numerous inquiries regarding my CSS header navigation bars

As someone who is new to CSS, I find myself struggling to grasp the correct approach. Online examples vary and leave me confused. Specifically, I have questions about my markup but overall, am I doing things correctly?

I feel like my CSS code is bloated. Why is my overflow property causing a scrollbar to appear? How can I eliminate the large padding on the left of my top-menu, possibly related to li + li? Is my layout of divs the most efficient way to achieve what I want? Using margin-top 70 to push down the second menu doesn't seem optimal. Is there a better method like float bottom or valign bottom that I should be using?

Any advice on getting started off on the right foot would be greatly appreciated.


<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="styles.css">

</head>
<body>

<div class="wrapper">

    <div class="logo">
    logo

    </div>
    <div class="top-menu">
        <ul>
            <li>Lorum</li>
            <li>Blog</li>
            <li>Contact us</li>
        </ul>

    </div>

    <div class="main-menu">
        <ul>
            <li>About Us</li>
            <li>Countries
            <li>Vacancies</li>
            <li>About Us</li>
            <li>Countries
            <li>Vacancies</li>
        </ul>
    </div>

</div>

</body>
</html>


    .wrapper {
    background-color: aqua;
    width: 600px;
    overflow: auto;
    padding: 5px;
}

.logo {
    background-color: black;
    height: 100px;
    width: 100px;
    float: left;
}

.top-menu {
    background-color: blue;
    float: right;
    line-height: 5px;
}

.top-menu > ul {
    list-style: none;
}

.top-menu > ul > li {
    display: inline-block;
}

.top-menu li + li:before{
    content: " | ";
    padding: 0 10px;
}

.main-menu > ul {
    list-style: none;
}

.main-menu > ul > li {
    display: inline-block;
    padding-right: 10px;
}

.wrapper {
    background-color: aqua;
    width:100%;
    overflow: auto;
    padding: 5px;
}

.top-menu {
    background-color: blue;
    float: right;
    line-height: 5px;
}

.main-menu {
    font-family: arial;
    font-size: 14px;
    background-color: crimson;
    clear: right;
    margin-top: 70px;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

Answer №1

The .wrapper class has been duplicated with different widths, along with several other classes.

Please make sure to clean up the code :)

One issue is that the margin of the ul in the main-menu extends beyond the div, causing a scrollbar to appear. You can identify this problem by using the inspect element feature in a browser like Chrome: https://developer.chrome.com/devtools/docs/dom-and-styles

.logo {
                background-color: black;
                height: 100px;
                width: 100px;
                float: left;
            }

            .wrapper {
                background-color: aqua;
                width: 100%;
                overflow: auto;
                padding: 5px;
            }

            .top-menu {
                background-color: blue;
                float: right;
                line-height: 5px;
            }

            .top-menu::after {
                clear: both;
            }

            .main-menu {
                font-family: arial;
                font-size: 14px;
                background-color: crimson;
                clear: right;
                margin-top: 70px;
                height: 30px;
                line-height: 30px;
                text-align: center;
            }

            .top-menu > ul > li {
                display: inline-block;
            }

            .top-menu li + li:before{
                content: " | ";
                padding: 0 10px;
            }

            .main-menu > ul {
                margin: 0;
            }

            .main-menu > ul > li {
                display: inline-block;
                padding-right: 10px;
            }
<div class="wrapper">

                <div class="logo">
                    logo
                </div>


                <div class="top-menu">
                    <ul>
                        <li>Lorum</li>
                        <li>Blog</li>
                        <li>Contact us</li>
                    </ul>
                </div>

                <div class="main-menu">
                    <ul>
                        <li>About Us</li>
                        <li>Countries</li>
                        <li>Vacancies</li>
                        <li>About Us</li>
                        <li>Countries</li>
                        <li>Vacancies</li>
                    </ul>
                </div>


            </div>

http://jsfiddle.net/n3wurcpx/

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 best way to prevent blank space when splitting a div into two parts?

Currently in the process of working on a school project that involves creating a website with an integrated database. The foundation for this project is an existing website from a previous assignment, created using PHP/HTML. The layout of my prior website ...

Slanted lines HTML CSS

I am encountering an issue with my HTML and CSS coding. The design requires a zig-zag "border" at the top and bottom of the page, creating a white paper space in between. The paper needs to be positioned underneath the zig-zag borders. Currently, this is ...

Execute a function when the selected option changes

Now I have implemented a code that dynamically changes the foreign key based on user input and retrieves data accordingly. Here is how it all comes together: Starting with the HTML page: <div class="large-6 columns"> {% csrf_token %} <in ...

The presentation of an HTML table varies between Gmail and web browsers

<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <table width="100%" height="131" border="0" cellspacing="0" cellpadding="0"> <tr> <td wid ...

Discovering visible ID numbers on the screen

My content includes the following: <div id="sContainer"> <div class="message0" id="l0">Initial Content 111</div> <div class="message1" id="l1">Initial Content 222</div> <div class="message2" id="l2">Initial ...

Fetching JSON data cross-domain with the help of JavaScript or JQuery

I am currently attempting to retrieve JSON data from this specific url. However, I am encountering difficulties in making it function as intended. The goal is to seamlessly integrate the school's lunch menu utilizing NutriSlice. We are leveraging Ris ...

Is Angular File API Support Compatible with HTML5?

When checking for HTML5 File API browser support in my code: private hasHtml5FileApiSupport; constructor(@Optional() @Inject(DOCUMENT) document: Document) { const w = document.defaultView; this.hasHtml5FileApiSupport = w.File && w.FileReader & ...

What is the determined method for calculating the pixel size of an SVG image?

Did you know that the Stackoverflow logo is actually an <a> element with a SVG image as its background? #hlogo a { text-indent: -999em; display: block; width: 200px; height: 50px; background-image: url("img/sprites.png?v=c4222387 ...

MaterialUI Box reigns supreme in the realm of background images

In my React component, I have a form that is structured like this: <Box display="flex" justifyContent="center" alignItems="center" style={{ minHeight: "100vh", backgroundColor: "gray", opacity: "0.8" }} > ... </Box> ...

Bootstrap-tour is incompatible with a row within a table structure

Is there a way to highlight a table row effectively? I've been struggling with it and tried using the fix mentioned in this bootstrap-tour issue here Check out this demonstration on jsFiddle: jsFiddle JAVASCRIPT $("#dialog").dialog(); var t = new ...

Optimizing the speed and load performance of SQLite in Phonegap

As someone who is new to Android programming, I am seeking advice on how to optimize the performance of my phonegap SQLite application. Currently, it takes 30 seconds to load 150 words when I hit the refresh button. Can anyone provide tips on how to enhanc ...

What is the best way to bring a closing </div> tag closer to its opening <div> tag in React, Angular, or Vue

Introduction Experienced JavaScript developers may cringe at the sight of a lengthy 200-line function. Their goal is to break it down into smaller, more manageable functions, each around 20 lines long. The idea is for a function to fit on one screen witho ...

I recently edited my htaccess file to redirect my webpage, but now I'm facing issues with my CSS, images, and

Here is the htaccess code I am using: RewriteRule ^example1/([A-Za-z-]+)/?$ example2.php?name=$1 [NC] The page is loading, but the CSS and JS are not rendering correctly. Can anyone assist me in resolving this issue? ...

Is it possible in HTML to detect *any* changes made to an input, not just those made by the keyboard?

Let's consider a scenario where we have an input element like this: <input id="myInput" type="text" /> The question now arises, how can we detect when the value of this input is changed programmatically (such as through $("#myInput").val("new ...

Tips for keeping the header section anchored to the top of the page

I am having trouble getting the menu bar and logo to stick at the top of my header section in the template. I have been trying different solutions, including using the sticky.js plugin for almost 4 days now but it's not working. I also have parallax e ...

Extract the price value from the span element, then multiply it by a certain number before adding it to a div element

On the checkout page of my website, I have the following HTML: <tr class="order-total"> <th>Total</th> <td><strong><span class="woocommerce-Price-amount amount"> <span class="w ...

What is the best way to combine two pieces of information from a constantly changing table?

Could really use some help with jQuery! I'm trying to calculate the cumulative value from columns A and B, then add those values together. Check out this image for the expected output. <script src="http://code.jquery.com/jquery-1.11.2.min.js"> ...

Adjust image width in column

After searching through various tutorials and Stack Overflow posts, I am still unable to properly resize my image in the right column. I have a layout with a left and right column - the left contains a menu and the right holds some content along with a ba ...

Tips for obtaining the dynamically loaded HTML content of a webpage

I am currently attempting to extract content from a website. Despite successfully obtaining the HTML of the main page using nodejs, I have encountered a challenge due to dynamic generation of the page. It seems that resources are being requested from exter ...

How can we assign various class names depending on the value of an object?

I have a set of objects stored in my component. I need to dynamically apply different classes based on the value of the ErrorLevel property within each object. If an object has ErrorLevel equal to 1, I want to assign the following classes to various elemen ...