mismatch between margin-left and auto not aligning

  • Having trouble with margin-left: auto not working 1- Looking to create a header with an image and a navbar 2- Want two unordered lists in the navbar 3- Trying to position one list on the left side and the second on the right side

When I use margin-left: 800px, it works fine but not with auto.

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
header{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 10px 10px;
}
nav{
    font-family: "Montserrat", sans-serif;
    font-weight: 500;
    font-size: 16px;
    margin-left: 15px;
}
.nav__links_R, .nav__links_L, a {
    text-decoration: none;
    list-style: none;
    float: left;
    color:rgba(0, 0, 0, .50);

}
.nav__links_R {
    margin-left: auto;
}

.nav__links_L li {
    display: inline-block;
    padding: 0px 20px;
}

.nav__links_R li {
    display: inline-block;
    padding: 0px 20px;
}
  <header>
        <img src="../photo/logo_dark.png" alt="logo">
        <nav>
            <ul class=nav__links_L>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
            <ul class=nav__links_R>
                <li><a href="#">Register</a></li>
                <li><a href="#">Login</a></li>
            </ul>
        </nav>
    </header>

Everything looks as expected except for ".nav__links_R" not aligning to the right using "auto"

Answer №1

Include the following style rules inside the nav element:

width: 100%;
display: flex;

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
header{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 10px 10px;
}
nav{
    font-family: "Montserrat", sans-serif;
    font-weight: 500;
    font-size: 16px;
    margin-left: 15px;
    display: flex;
    width: 100%;
}
.nav__links_R, .nav__links_L, a {
    text-decoration: none;
    list-style: none;
    float: left;
    color:rgba(0, 0, 0, .50);

}
.nav__links_R {
    margin-left: auto;
}

.nav__links_L li {
    display: inline-block;
    padding: 0px 20px;
}

.nav__links_R li {
    display: inline-block;
    padding: 0px 20px;
}
 <header>
        <img src="http://placekitten.com/200/40" alt="logo">
        <nav>
            <ul class=nav__links_L>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
            <ul class=nav__links_R>
                <li><a href="">Register</a></li>
                <li><a href="">login</a></li>
            </ul>
        </nav>
    </header>

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

I'm experiencing an issue where the Devtool appears empty when inspecting it, making it impossible to locate

I'm currently working on automating the process of entering data into web forms using Selenium VBA. The forms are located on our organization's SharePoint site, and I have already logged into the account. However, every time I reach the final ste ...

Hiding a Hide/Show DIV when hovering over the Google+ Follow Button

I'm currently working on a project that involves a hover drop-down panel with Google+, Facebook, Youtube, and Twitter social widgets. These widgets are listed for visitors to easily click on each one without the panel closing. Initially, I created a ...

Detect IE 9 and IE 10 with jQuery

My jQuery code works well in Chrome and Mozilla but not in IE. if ($("html").hasClass("ie")) { $(function(){ $('.green-column, .red-column, .grey-column').click(function() { alert($(this).attr("data-type")); ...

What could be the reason for my select list not showing up?

Hello fellow developers, I am currently working on creating a dynamic tablerow that allows users to fill in input fields and select options from a list for each cell. While the input fields are functioning properly, I am facing an issue with displaying th ...

Activate the horizontal scrollbar within each flex item when it is stretched beyond its original width

My goal is to have both the child-1 (blue) and child-2 (black) retain their original width when the sidebar appears by enabling horizontal scrolling upon clicking anywhere in the demo below. document.body.onclick = () => document.querySelector(&apos ...

Instead of accessing the HTML page directly, you can view the source page by using the F12

I need to extract both data and IPs from VirusTotal.com using selenium and Beautiful Soup in Python. When I make a get request, I only receive the view-source HTML instead of the complete data-rich HTML shown in Inspect mode (F12). Does anyone have any su ...

Replicating a row in a table without disrupting a button within the row

As a novice in the world of coding, I am currently embarking on a project to revamp an existing website. The task at hand involves creating a table with a built-in save/edit feature, which I have successfully implemented. However, I am facing a roadblock w ...

Trigger a JavaScript event when attempting to input the maximum number of characters

I am currently facing a challenge with implementing a tooltip on a text area that has a maximum character limit of 500. The tooltip should only appear when the user reaches the maximum character count and attempts to input more characters. My previous appr ...

What is the best way to generate a table with continuously updating content?

If the user input : $sgl = 2; $dbl = 0; $twn = 1; $trp = 0; $quad = 0; $price_room = 250000; I want the result looks like the picture below : https://i.sstatic.net/iQYqr.jpg I have tried the following code : <?php $sgl = 2; $dbl = 0; ...

In order to properly adjust the HTML content when resizing the window, it

I'm facing an issue with a toggle setup for displaying content differently based on screen width. Specifically, when the screen size decreases below 600px, it switches to the correct content. However, upon increasing the screen width again, it fails t ...

What to do when Google Font fails to load and how to define an alternative font styling

Can anyone help me out with a solution? I am facing an issue with google fonts not working in Safari on my website. Is there a way to instruct the browser to switch to a different style when the font is not supported? Below is the CSS code I am currently u ...

Is the background color extending the entire width of the page?

Hey there, I'm currently trying to determine how to set the background-color on a paragraph or h1 so that it only appears behind the words and not across the entire page with blank space. I'm still a beginner when it comes to coding. I'm wor ...

Is there a way to connect an HTML page without using a hyperlink?

Is there a way to directly display linked HTML pages on my webpage instead of just creating a link? I'm looking for suggestions on how to arrange this. Thank you! ...

Switching the default image using jQuery upon click event

When I click on the image, I want to see a new image appear for just one second before returning to the default. I tried using setTimeout() function, but even after one second, I still see the same pressed.svg image. Here is my complete code: <html> ...

Rgd: Double-Sided Horizontal Slide Control

While browsing the internet, I came across several examples of horizontal sliders with adjustable values. For example, if I set the maximum value as 100 and move the slider 10 sectors to the left, each sector would decrease by 10. What I am trying to ach ...

Hide and show submenus with jQuery while ensuring that the initial submenu remains visible, along with the main menu

I am struggling to figure out how to make the first message active by default along with its corresponding menu selection in my navbar. I have implemented a show/hide functionality on the main menu click, but currently only the menu is being set as active ...

Develop a feature or method in your code that allows for the display of the specified table column based on user interaction

I'm a beginner with ASP.NET and I'd like to learn more about events and functions that will change the color of the corresponding day button when pressed: <td class="style2"> <asp:Button ID="Monday" runat="server" BackColor="#009933" He ...

Eliminating specific text and images from WordPress articles

I am working on a Wordpress website where the post's content is displayed using <?php the_content(); ?> The content includes images and text that are all outputted within < p > tags. My goal is to style the margins/padding of the image ...

Animating a div using a changing scope variable in AngularJS

As a newcomer to Angular, I am looking to add animation to a div element using ng-click within an ng-repeat loop. Here is what I have attempted: app.js var app = angular.module( 'app', [] ); app.controller('appController', function($ ...

Altering the vertical position of <li> within the nav bar without impacting the size of the nav bar is proving to be a

How can I adjust the vertical position of li elements without impacting the height of the navigation bar? Below is the code snippet in question: body { margin: 0px; } ul { margin: 0px; padding: 0px; list-style: none; padding-left: 5px; pad ...