Utilizing flexbox to align a horizontal menu

I have been working on creating a fixed menu using flexbox. Within my navigation bar, I have set up 2 divs. The first one is supposed to contain the logo, and the second one is for the menu (utilizing the display:flex property). However, I am facing an issue when trying to position the list elements (li) in my menu. I aim to have a horizontal menu, but when I apply justify-content:space-between, the first element should align with the left edge of the menu's div, yet it has a slight margin that I cannot seem to resolve.

https://jsfiddle.net/4Lmu08yc/

header {
    height:100vh;
    background-color:yellow;
    width:100vw;
    max-width:100%;

}

.navbar {
    width:100vw;
    background-color:grey;
    height:7vh;
    max-width:100%;
    position:fixed;
    border-bottom:5px solid white; 
    z-index:2;

}

.flex_row {
    display:flex;
    flex-direction:row;
}

.container{
    height:100%;
    width:100vw;
    max-width:100%;
    background-color:green;
    display:flex;
}


#logo {
    height:100%;
    background-color:white;
    flex-grow:1;
}

#menu {
    height:100%;
    background-color:yellow;
    flex-grow:1;
}

#menu ul {
    list-style-type:none;
    justify-content:flex-start;
    align-content:flex-end;

}

#menu ul li {

    border:1px solid black;
    line-height:40px;
}
<header>
<div class="container">
<div class="navbar flex_row">
    <div id  ="logo"></div>
    <div id ="menu">
        <ul class="flex_row">
            <li><a href="#">text1</a></li>
            <li><a href="#">text2</a></li>
            <li><a href="#">text3</a></li>
            <li><a href="#">text4</a></li>
        </ul>
    </div>
</div>
</div>
</header>

Answer №1

Ensure to include margin:0; in the CSS for '#menu ul'.

By default, HTML applies a margin to unordered lists.

#menu ul {
      margin:0;
}

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

What is the correct way to apply a concatenated element id when using the .click() function in

Having an issue with assigning buttons to input boxes in a loop. When using concatenated element IDs with the .click() method, the buttons won't click for some reason. The following code works: document.getElementById("streamInput1") .addEventLi ...

Is there a way to position the tooltip above the sorter icon in Ant Design (antd) component?

I'm currently working on creating a table with sorter columns using the antd framework. Can anyone guide me on how to position the tooltip above the sorter icon? Below is a snippet of my UI. https://i.sstatic.net/fGoqA.png Specifically, I included t ...

Getting the local path of a file from an input file in Angular 7

Is there a way to retrieve the local file path from an input field in HTML? After running the code below, I obtained 'C:\fakepath\fileTest.txt' I am looking for a method to get the local path so that I can pass it on to my control ...

Using Selenium in Java to extract text from an h1 tag

Although I am familiar with the method .getAttribute("innerHTML") for retrieving the value of a h1 tag, my HTML structure is a bit different: https://i.sstatic.net/RVaMM.png While I am able to locate the h1 tag, I am facing difficulty in accessing its inn ...

What is the correct way to format the headings for sub-level pages, like chapters within a novel or sections within a lengthy article?

At times, the text and image content becomes too expansive to fit on a single page. However, preserving the context of the content is crucial, making it necessary to display it explicitly from a user experience perspective. This could include chapters of a ...

Separate sentence to one word per line

Can CSS be used to display each word of a sentence on a separate line? Input: <div>Hello world foo bar</div> Rendered output: Hello world foo bar It is not ideal to set the width to 1px, as specified. ...

Difficulty establishing a connection between data in app.js and index.html using Ionic framework

Struggling with connecting index.html to get data for my Ionic mobile app. Any tips or guidance would be highly appreciated as I'm new to this! The goal is to display a list of restaurants in the app, utilizing Cards Images to showcase an image, logo ...

What steps should be followed to display an HTML page within an HTML div?

The question I have is a bit misleading, as I'm not looking for guidance on how to open an HTML document in a div. Rather, I am currently facing an issue where I am unable to replace the HTML file that I have already placed in a div. Initially, I pla ...

Is it possible to conceal a form field until a previous field has been completed?

Looking for a way to hide a form field until another field is properly completed? I have a divided registration form and want the second field to appear only when the first one is valid. Preferably using CSS3, with HTML5 and maybe some JavaScript if necess ...

When utilizing the `express.static(__dirname)` function in Node.js with Express, the visitor may be directed to an incorrect HTML page

My website consists of a login page named login.html and an index page named index.html. I want to implement authentication so that only logged in users can access the index page. I have not set up the post method on the login HTML page. Therefore, I have ...

Developing a hovercard/tooltip feature

I'm currently working on developing a hovercard feature for a social media platform I'm building. The concept involves displaying additional information about a user when their name is hovered over. The hovercard will appear with the user's ...

Guide on incorporating pinching gestures for zooming in and out using JavaScript

I have been working on implementing pinch zoom in and out functionality in JavaScript. I have made progress by figuring out how to detect these gestures using touch events. var dist1=0; function start(ev) { if (ev.targetTouches.length == 2) {//checkin ...

When it comes to designing responsive websites, the use of `@

Being new to CSS, I am open to criticism and feedback. @media (max-width: 735px) {... } @media (min-width: 735px) {... } @media (width: 320px) {... } @media (width: 360px) {... } @media (width: 375px) {... } @media (width: 414px) {... } I have tried us ...

Exploring the process of passing parameters in Material-UI React styled components

Recently, I developed a new component const CategoryDialog = (props) => { const classes = useStyles(); console.log(props); return ( <div> <Dialog fullScreen open={props.dilaogOpenProp} TransitionCompone ...

Tips for avoiding overflow while utilizing animations

In my current project, I am facing an issue with a container div that has the CSS property overflow: auto which cannot be removed. Inside this container, there is another div that toggles between showing and hiding using an animation triggered by a button ...

Button to scroll down

I have successfully implemented a #scrolldownbutton that scrolls to the first component. However, I am now attempting to modify it so that when the button is clicked, the page smoothly scrolls within the viewport and stops at the partially visible componen ...

The functionality for determining whether the value isset as 'Yes' or 'No' is not functioning properly in my PHP form

I'm currently working on creating a combined 'Order Calculator / Order Form' using one php form. The calculator part of the form is functioning perfectly and accurately calculates the total for all 5 order options both on the live page and i ...

Updating Template in Python Flask upon Button ClickLet's enhance our Python Flask application by

I need assistance with switching templates upon clicking a button. My Python code is as follows: @app.route("/", methods = ['POST', 'GET']) def my_forum_post(): if request.method == 'POST': if reque ...

Issue with :visited pseudo-class not functioning as intended

My code includes all four basic pseudo-classes, and they all seem to be working fine except for the :visited pseudo-class. The color property doesn't function properly, and the background property appears to be inactive. I'm not sure what the iss ...

Displaying a loading animation within a specific div element

Is it possible to use jQuery to insert a div into another div? My goal is to replace the contents of one div with a loading div while waiting for an ajax call to return. <div id="content1">foo</div> <div id="content2">bar</div> < ...