Move the components over to the right

How can I vertically align the user and the search bar on the right side of the page?

#search {
    float: right;
    margin-top: 9px;
    width: 250px;
}

.search {
    width: 230px;
    height: 30px;
    position: relative;
    line-height: 22px;
  
}

...

</div>
</div>
</p>
    </div></questionbody>
<exquestionbody>
<div class="question">
                
<p>How do I align user and the search bar on the right and vertically aligned?</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>#search {
    float: right;
    margin-top: 9px;
    width: 250px;
}

.search {
    width: 230px;
    height: 30px;
    position: relative;
    line-height: 22px;
    display: flex;
}

.search button {
    margin: 0;
    background-color: transparent;
    border: 0;
}

.search button span {
    font-size: 1.2rem;
    color: #fff;
}

.search input {
    box-sizing: border-box;
    width: 0;
    -webkit-transition: all 0.7s ease-in-out;
    -moz-transition: all 0.7s ease-in-out;
    -o-transition: all 0.7s ease-in-out;
    transition: all 0.7s ease-in-out;
    line-height: 18px;
    padding: 0;
    border: 0;
    margin-left: 180px;
    visibility: hidden;
}

.search:hover input,
.search input:focus {
    width: 180px;
    margin-left: 0px;
    padding: 0 2px 0 2px;
    border: 2px inset;
    border-radius: 3px !important;
    visibility: visible;
}
.search button span:hover, .search button:hover {
    background-color: transparent;
}
.topbar-user img{
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-left: 15px;
}
.user-menu {
    color: #fff;
    cursor: pointer;
    margin-left: 15px;
    margin-right: 15px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<nav id="top-menu" class="navbar bg-primary-gradient col-lg-12 col-12 p-0 fixed-top navbar-inverse d-flex flex-row">
 
    <div class="navbar-menu-wrapper d-flex align-items-center">
        <button id="menuToggler" class="navbar-toggler navbar-toggler hidden-md-down align-self-center mr-3"
                type="button" data-toggle="minimize">
            <span id="navbar-icon" class="fa fa-arrow-left"></span>
        </button>
        <ul class="navbar-nav ml-lg-auto d-flex align-items-center flex-row">
        </ul>
        <div class="text-right">
            <div class="search">
                <input type="text" class="form-control input-sm float-left" maxlength="64" placeholder="Search"/>
                <button type="submit" class="btn btn-primary btn-sm"><span class="fa fa-search">Search</span></button>
            </div>
            <div class="dropdown user-menu">
                <a class="dropdown-toggle topbar-user" id="navbar-user" data-toggle="dropdown">
                   <span>USER</span>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbar-user">
                    <a class="dropdown-item" href="#"><span class="fa fa-user"></span> Profile</a>
                    <a class="dropdown-item" href="settings"><span class="fa fa-cog"></span> Settings</a>
                    <a class="dropdown-item" href="#"><span class="fa fa-question"></span> Help</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" onclick="logout()"><span class="fa fa-sign-out"></span> Sign out</a>
                </div>
            </div>
        </div>
    </div>
</nav>

Answer №1

Utilize a class to float an element either left or right along with the !important declaration to prevent specificity conflicts. Additionally, classes can serve as mixins.

<div class="pull-left">...</div>
<div class="pull-right">...</div>

Avoid using this method in navbars. For aligning components within navbars using utility classes, use .navbar-left or .navbar-right instead. Refer to the navbar documentation for more information here

#search {
    float: right;
    margin-top: 9px;
    width: 250px;
}

.search {
    width: 230px;
    height: 30px;
    position: relative;
    line-height: 22px;
    display: flex;
}

.search button {
    margin: 0;
    background-color: transparent;
    border: 0;
}

.search button span {
    font-size: 1.2rem;
    color: #fff;
}

.search input {
    box-sizing: border-box;
    width: 0;
    -webkit-transition: all 0.7s ease-in-out;
    -moz-transition: all 0.7s ease-in-out;
    -o-transition: all 0.7s ease-in-out;
    transition: all 0.7s ease-in-out;
    line-height: 18px;
    padding: 0;
    border: 0;
    margin-left: 180px;
    visibility: hidden;
}

.search:hover input,
.search input:focus {
    width: 180px;
    margin-left: 0px;
    padding: 0 2px 0 2px;
    border: 2px inset;
    border-radius: 3px !important;
    visibility: visible;
}
.search button span:hover, .search button:hover {
    background-color: transparent;
}
.topbar-user img{
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-left: 15px;
}
.user-menu {
    color: #fff;
    cursor: pointer;
    margin-left: 15px;
    margin-right: 15px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<nav id="top-menu" class="navbar bg-primary-gradient col-lg-12 col-12 p-0 fixed-top navbar-inverse d-flex flex-row">
 
    <div class="navbar-menu-wrapper d-flex align-items-center">
        <button id="menuToggler" class="navbar-toggler navbar-toggler hidden-md-down align-self-center mr-3"
                type="button" data-toggle="minimize">
            <span id="navbar-icon" class="fa fa-arrow-left"></span>
        </button>
        <ul class="navbar-nav ml-lg-auto d-flex align-items-center flex-row">
        </ul>
        <div class="text-right pull-right">
            <div class="search">
                <input type="text" class="form-control input-sm float-left" maxlength="64" placeholder="Search"/>
                <button type="submit" class="btn btn-primary btn-sm"><span class="fa fa-search">Search</span></button>
            </div>
            <div class="dropdown user-menu">
                <a class="dropdown-toggle pull-right topbar-user" id="navbar-user" data-toggle="dropdown">
                   <span>USER</span>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbar-user">
                    <a class="dropdown-item" href="#"><span class="fa fa-user"></span> Profile</a>
                    <a class="dropdown-item" href="settings"><span class="fa fa-cog"></span> Settings</a>
                    <a class="dropdown-item" href="#"><span class="fa fa-question"></span> Help</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" onclick="logout()"><span class="fa fa-sign-out"></span> Sign out</a>
                </div>
            </div>
        </div>
    </div>
</nav>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Excessive form inputs extend beyond the modal when utilizing Bootstrap 3

Having an issue loading a modal with Angular and populating it with a template. The main problem I'm facing is that the inputs are extending beyond the boundaries of the modal - attached below is a screenshot illustrating the problem: Below is the c ...

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The server is unable to process the request sent by the browser or proxy. This error occurred in a Flask web application

Can someone guide me on troubleshooting this issue in Flask? I am still learning. Server running at (Press CTRL+C to exit) 127.0.0.1 - - [26/Jul/2020 11:19:45] "GET /predict HTTP/1.1" 500 - Traceback (most recent call last): raise exceptions. ...

The values are not being displayed in the local storage checkbox

I attempted to transfer checkbox values to another HTML page using local storage, however they were not appearing on the other page Here is my page1 HTML code snippet: <input class="checkbox" type="checkbox" id="option1" name="car1" value="BMW"> ...

Creating a "briefing" iframe at the top of a webpage

I'm looking for a way to allow users to embed my iframe at a specific size, like 100x100, and then have it resize dynamically to fit the page size when they click on it. I want this functionality to work regardless of how the HTML embedding the iframe ...

Z-index behaving abnormally

I've been working on developing a website and one of the key features I'm trying to implement is a slideout menu that slides horizontally when the mouse hovers over it. To make development easier, I initially set the menu to be fully extended by ...

Exploring issues with jQuery

I'm encountering an issue with my code. I have multiple divs with the same classes, and when I click on (toggle#1) with the .comments-toggle class, all divs below toggle-container expand. What I actually want is for only the div directly below .commen ...

What is the method to create a polygon in its entirety by utilizing a for loop within Javascript?

After successfully using the Canvas of HTML to draw a convex polygon, I encountered an issue. In the provided code snippet, t2 represents an array of points with getX() and getY() methods. The drawing function performs as expected until it reaches the seg ...

When attempting to use the ResponsiveSlides plugin, the functionality of 'Image links' seems to be disabled in the Chrome browser

While everything is functioning perfectly in Firefox and IE, I've encountered an issue with Chrome. It only works after right-clicking and inspecting the element; once I close the Inspector, it stops working - displaying just an arrow cursor as if the ...

What could be the reason for my difficulties in retrieving the necessary data from this website with Selenium?

Basically, I've been struggling to interact with the "enter your address" field on a particular website through xpath and selenium. I'm curious as to why this is happening. Detailed Explanation The website in question is this one. It features a ...

Adjust the CSS of a nested div within the currently selected div upon page load

I am facing an issue with a page that users access by clicking through an ebook. Upon clicking a link, they are directed to a specific product on the page, and the URLs look like example.com/#product1 example.com/#product6 example.com/#product15, etc... ...

Adjusting the thickness of the CSS cursor line upon entering an input field

Having an image as the background for an input field has been causing issues for me. Although I can adjust the line-height and font-size easily, the cursor line appears outside of the background image when clicking inside the input field. Is there a speci ...

Removing the active class from a Bootstrap menu can be achieved by targeting the specific

I have successfully implemented a Bootstrap Menu by placing it in a separate header.html file and using the php include function to call that file on every page of my website. However, I am now trying to figure out how to dynamically change the active cl ...

Using Angular to include a forward slash "/" in the text input for a date field

Hello everyone, I am a newcomer to AngularJS and I am looking to insert slashes in an input type text element. I prefer not to rely on external packages like angular-ui or input type Date. My goal is to have the format mm/dd/yyyy automatically applied as ...

Calling functions in AngularJS/HTML can help you execute specific

Just started with angularjs and facing some major issues haha... I have something that seems to be working fine, but I can't figure out what's wrong with this code... can someone please help me? Here it is: Basically, the scope.create function ...

When accessing the defaultValue property of a select element, it will result in

Here is a typical HTML dropdown menu: <select name="email" id="email"> <option value="2" selected="selected">Before redirecting to PayPal</option> <option value="1">After payment is successful</option> <opti ...

What is the fastest way to add an email subscription form to my website without needing to configure a database?

Would it be possible to integrate a sign-up text box on our site for users interested in receiving launch notifications? Any suggestions on the most effective method to implement this feature? EDIT: Our current use of Prefinery has limitations as we cann ...

Any tips on animating my SVG when I hover my mouse over it with CSS or JavaScript?

Having trouble getting the gray outline to fill when hovering over it. The method I'm currently using isn't working on any browser. Any suggestions? You can find the HTML with the inline SVG file below: CSS is in a separate file, containing cla ...

``Are you looking to create multiple canvases in a loop?

I've managed to get this command working exactly as I wanted: http://jsfiddle.net/m1erickson/64BHx/ However, I didn't anticipate how challenging it would be to turn the drawing into reality here: What I attempted to do is illustrated in this li ...

In a remarkable design with an array of buttons and an individual div assigned to each, a fascinating functionality unfolds. Whenever a

https://i.stack.imgur.com/emhsT.png When I click on the first "Respond" button, I want the adjacent text box to disappear. Currently, if I click on the first "Respond" button, both text boxes will disappear instead of just the first one. $('.comment ...

What is the technique for rearranging columns to be at the top in Foundation for mobile devices?

On my desktop, I have a layout like this: [Column1 large-8] [Column2 large-4] For mobile view, I'd like it to be like this: [Column2 large-4] [Column1 large-8] Below is the code snippet I am working with: <div id="search-content" class="row ma ...