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

How to exclude elements nested inside another element using CSS or XPath techniques

Presented here is a snippet of XML code: <xml> <section> <element>good</element> <section class="ignored"> <element>bad</element> </section> </section> </xml> Identifying a ...

I'm looking for a skilled CSS spinner creator. Can anyone recommend one?

Can anyone recommend a good online application for creating CSS spinners? I've been searching and only found one on David Walsh's blog, but it only has one available. Any suggestions? ...

What is the best way to insert a YouTube video into a WordPress template page?

I decided to create a new template page for one of the pages on my WordPress site because I only wanted to have some text and a YouTube video displayed. It turns out that embedding a YouTube video directly into the code is not supported by WordPress, so I ...

JavaScript function failing to validate password

While engaging in an online game where the objective is to uncover a password by inspecting the page source or element, I encountered a puzzling line: if(el.value == ""+CodeCode+""). My assumption is that el.value represents my guess, and it indicates that ...

Is it conceivable that Rails may be rendering HTML at a slower rate compared to static

When using a Rails layout, you can include HTML tags to render images like this: <%= image_tag("logo.png", :alt => "Sample App", :class => "round") %> This will generate the following HTML code: <img alt="Sample App" class="round" src="/i ...

Using an ellipsis in a hyperlink within a list item conceals the bullet points of the list

When I apply an ellipsis to the text within a list element that has disc bullet points, it hides the bullet point itself. I discovered that applying overflow: hidden to the list will also hide the bullet point. Moving this rule to the anchor within the li ...

Having trouble accessing an element using jQuery(idOfElement) with a variable as the name parameter

Possible Duplicate: Issue with JavaScript accessing JSF component using ID Whenever I attempt to retrieve an element by passing a variable in jQuery(idOfElement), it doesn't work. But if I use something like jQuery('#e'), it works perfe ...

In React, the Textarea component that displays the character count only updates its value after a page reload

Contained within this element is the following component: import React, { useEffect, useState } from 'react'; import { TextareaTestIds } from '../utils/test-ids'; export interface TexareaProps extends React.TextareaHTMLAttributes<H ...

CSS: Set the left position to 250px with the added feature of hiding any overflow

I am currently working on a sidebar that can be shown or hidden using JavaScript with CSS animations. To achieve this effect, I need to position the content div (#main) using left: 250px;. #main { left: 250px; position: relative; overflow: hidden; } ...

Is your Ajax jQuery live search not functioning properly with JSON data?

My programming code is not functioning properly. Here is the file I am working on. When it does work, it does not display the list and gives an error in the Json file. I am unsure of the reason behind this issue. You will be able to view the error in the C ...

Implement a callback function to dynamically generate variables and display them within an HTML element

Apologies in advance for any errors I may make as I am a beginner when it comes to javascript, jquery, and json. I have a script that retrieves data from a json file and displays it on a webpage using javascript, jquery, ajax (I believe), and json. When ...

Is the Packery image grid only functional when the background image is specified in CSS and not in JavaScript? Perhaps we need to look into using Await/Sem

I've successfully implemented a packery image grid that is responsive and functional when the background image in the .item-content section is defined in the CSS file: http://codepen.io/anon/pen/eJdapq .item-content { width: 100%; height: 100%; ...

Error: Compilation was unsuccessful due to module not found. Unable to resolve in ReactJS

As I was wrapping up this task, an unexpected error popped up: Module not found: Can't resolve './components/Post' in ./src/pages/index.js I've tried everything to troubleshoot it but no luck. Here's a rundown of my code snippets ...

Deactivate the connection button for accessing the database

I'm currently developing a PHP script to establish a connection with a MySQL database. My goal is to deactivate a button and display a spinner image when I click on a submit button to initiate the database connection. Below is the code snippet I have ...

Scrolling animations do not support the Translate3d feature

I'm struggling to implement a smooth scroll effect on the header of my website. My approach involves using transform:translate3d for animation, with the goal of keeping the header fixed at the top and moving it out of view as the user scrolls down. I ...

What is the best way to make an HTML table with a static header and a scrollable body?

Is there a way to keep the table header fixed while allowing the table body to scroll in an HTML table? Any advice on how to achieve this would be greatly appreciated. Thanks in advance! ...

Retrieve data from an API and store it in a JSON array

My website is having an issue where it's fetching data from an API and displaying it in a table, but all the cells are returning undefined values. The data in the API is structured as an array with multiple datasets inside curly braces that I am unsu ...

Microsoft Edge and Google Fonts display strong and distinctive lettering

When using Microsoft Edge on Windows 10, all text appears with bold UTF-8 characters: I'm unsure of what the issue is. Is there a solution available? ...

Detecting collisions using CSS animation

I'm currently working on a unique "game" project. Check out the code snippet here: jsfiddle function update() { coyote.applyForce(gravity); coyote.edges(); coyote.update(); cactus.update(); if (coyote.intersects(cactus)){ alert("colisio ...

Expanding Lists in Bootstrap 3: A Step-by-Step Guide

I have been experimenting with Bootstrap's Example accordion code, which can be accessed via this link: http://jsfiddle.net/qba2xgh6/18/ <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> <div class="panel ...