Arrange items in the navigation bar

Currently, I am in the process of setting up a small navigation bar that includes a search bar and a login feature. However, I have hit a roadblock as my usual method of using display:flex is not working for this particular case. Instead, I attempted to apply the property display:inline to my <li> elements, but unfortunately, it did not yield the desired results.

CSS:

* {
    margin:0;
    box-sizing:border-box;
}
html {
    display:block;
}
body {

  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
  line-height: 1.42857143;

}

a {
  color: #00B7FF;
}
.navbar-default {
    position:relative;
    min-height: 50px;
    background-color: #f8f8f8;
    border-color: #e7e7e7;
}

.container-fluid {
    padding-right:30px;
    padding-left:30px;
    margin-left:auto;
    margin-right:auto;
}

.navbar-default ul {
    list-style: none;
    display:inline;
}

.navbar-default li {
    display:inline;
}

HTML:

<nav class="navbar-default">
    <div class="container-fluid">
        <ul class="navbar-default nav">
            <li>
                <div id="search" class="search-navbar">
                    <input type="search"> 
                    <input type="button" value="Search">
                </div>
            </li>
            <li>
                <div id="login" class="login-navbar">
                    <input type="text">
                    <input type="password">
                    <input type="button" value="Sign in">
                </div>
            </li>
        </ul>
    </div>
</nav>

I have created a demonstration on JSFiddle: https://jsfiddle.net/rvfd5h5e/

My goal is to position the search bar slightly left of center and the login feature towards the right side. If anyone can provide assistance with achieving this layout, it would be greatly appreciated.

Answer №1

Experiment with the combination of display:inline-block and float:right

CSS Tips

.navbar-default ul {
    list-style: none;
    display:block;
    clear: both;
    line-height: 3em;
}
.navbar-default li, .navbar-default li div {
    display:inline-block;
}
.navbar-default li:last-child {
    float: right;
}

Check out the DEMO HERE

Answer №3

Include the property display:inline in the styles for both of the <div> elements.

Answer №4

Feel free to use the following CSS:

width: 50%;
float: left;
display: inline;

To style the div inside the first list item. and

display: inline;
float: right;

The above CSS is for the div in the second list item.

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

Reset input fields upon jQuery removal

Currently, I am working on a form that includes a remove function. The function is functioning correctly, but I am facing an issue where I want the field values to be cleared when the remove function is triggered. This is necessary as I am sending input va ...

Having trouble with imagecopyresampled function, unsure of the reason behind its malfunction

I am currently trying to use imagecopyresampled to crop a specific section of an image, in order to prevent users from uploading photos larger than the intended size on my website. However, I am facing an issue where imagecopyresampled seems to be resizing ...

Troubleshooting a unique CSS problem on an Android PhoneGap

We are currently working on an Android application using PhoneGap, HTML, CSS, and jQuery Mobile. After compiling the application in Eclipse, everything seems to work correctly. However, I am facing an issue where my CSS styles are not updating when recompi ...

Alignment of columns within an HTML grid

I can't seem to figure out why my grid column headers are not aligning properly with the data in the grid. It's puzzling that they have the same CSS class but different sizes. Can someone please help me with this: .outer { width: 60%; heig ...

Optimizing the use of .less files in an expansive angularjs application

Currently, I am in the process of developing a large-scale application using AngularJS as a Single Page App. All the html files have been organized under the Views folder as shown here. Views Sample sample.html sampleheader.html ...

Searching for a JavaScript tool that offers syntax highlighting capabilities

I have come across some excellent RTE HTML text editors such as jsredaktor, TinyMCE, and FCK Editor, but I am in search of an HTML/JavaScript component that functions similarly to a TEXTAREA with built-in code syntax highlighting. ...

Build an upvote feature using PHP and WordPress that allows users to vote without causing a page reload

Just starting out as a developer and currently working on a website using WordPress. I want to implement an upvote button that allows users to upvote a post without the page needing to refresh. I understand that I'll need to use JavaScript to highligh ...

Is your WordPress one-page scroll JQuery script failing to function properly?

Currently attempting to develop a single page scroll feature. Within WordPress, my navigation contains anchor tags structured as follows: <a href="#contact">Contact</a> <a href="#about">About</a> The corresponding divs for the li ...

Is it possible for me to overlay a blank white page onto a background image?

Looking to add a blank white page on top of my background image using html5 or css3. Need the page to be customizable in terms of dimensions. ...

Unable to retrieve input values from the text fields using JavaScript

In my project, I have created two PHP pages - "doc.php" and "chkval.php". The issue I am facing is that the textfield values are not being captured in the "chkval.php" page using $POST method. An error that I encountered is: Use of undefined constant re ...

Equal height tabbed content design allows for a visually appealing and organized

I'm looking to create a tabbed menu that displays content in blocks, but I want each block to be the same height. I tried using padding and flexbox, but couldn't get it to work properly. Any suggestions on how to achieve this? .tab-pane { fl ...

Issues with displaying images in IE 11 when using Flex

After testing this code, I found that it works perfectly in both Firefox and Chrome, displaying a row as expected. https://i.sstatic.net/29wgb.png However, when viewing the same row in IE 11, the image is not visible, and the width seems to be missing in ...

Unable to create transparent div

I am currently working on a test page located at this link. As you scroll down the page, you will notice that the logo remains fixed in the background while an area I have painted purple scrolls over it. I chose to make this area purple temporarily for vi ...

How do I use jQuery to animate a height increase where the added height is applied to the top of the element?

I am facing a simple issue that I need help resolving. The problem involves hidden content that, once expanded, needs to have a height of 99px. When collapsed, the container holding this content section#newsletter is set to be 65px in height. If you want ...

showing information retrieved using the fetch function

Currently, I am attempting to retrieve the user's input value from a search box and then proceed to use this variable in my endpoint to retrieve data. <input type="text" class="search" placeholder="planet"> <script> const media = &apo ...

Move the cursor to the bottom of a div that can be edited

I have been struggling to position the cursor at the end of the next or previous editable content tag if the current one is empty. However, when I try to set focus, it always ends up at the beginning of the text instead of the end. I've tried various ...

The button labeled as "hamburger" on my navigation bar seems to be malfunctioning (using bootstrap)

Recently, I've been facing an issue with the "hamburger" button in my navbar. Whenever I click on it, nothing seems to happen. This was not a problem before, and now I can't seem to figure out what went wrong or where the error lies. If anyone c ...

Pressing a button will reset the input spinner in Bootstrap

Is there a way to reset the bootstrap input spinner by clicking a button? I attempted using document.getelementbyId().value = "0" and also tried using reset(), but neither method worked. Any suggestions on how to successfully reset it? function resetScor ...

Creating a Navigation Bar with a Dropdown Menu in HTML

Apologies if this question has been asked before, but I've searched everywhere and can't find an answer. All my searches just bring up dropdown menus with <nav></nav> Consider this table (serving as a navigation bar): <table cl ...

Social Engine is incapable of analyzing the HTML code

Currently working on a website using Social Engine 4.8.9 version that is still in development mode. Upon inspecting the html code with the chrome inspector, I find it incredibly complex to decipher. For instance, when I click on the login page link http:// ...