Colored stripe on a horizontal menu

I am attempting to design a page header with a menu that resembles the image provided below.

As I construct the navigation, each link area (highlighted in blue) is represented by an <li>. However, I am encountering an issue where the items are stacking vertically instead of horizontally.

You can view the code on jsFiddle.

<header>
<div id="area-logo">
    <div class="header-ribbon"></div>
    <div class="container bg-white"></div>
</div>
<nav id="main-menu">
    <ul>
        <li id="link-a-link">
            <div class="header-ribbon"></div>
            <div class="container bg-white"> <a href="#">link a</a>

            </div>
        </li>
        <li id="link-b-link">
            <div class="header-ribbon"></div>
            <div class="container bg-white"> <a href="#">link b</a>

            </div>
        </li>
        <li id="link-c-link">
            <div class="header-ribbon"></div>
            <div class="container bg-white"> <a href="#">link c</a>

            </div>
        </li>
        <li id="link-d-link">
            <div class="header-ribbon"></div>
            <div class="container bg-white"> <a href="#">link d</a>

            </div>
        </li>
        <li id="link-e-link">
            <div class="header-ribbon"></div>
            <div class="container bg-white"> <a href="#">link e</a>

            </div>
        </li>
        <li id="link-f-link">
            <div class="header-ribbon"></div>
            <div class="container bg-white"> <a href="#">link f</a>

            </div>
        </li>
    </ul>
</nav>

    header {
    background-color: #787aad;
    height: 126px;
}

header .header-ribbon {
    height: 6px;
}

header .bg-white {
    background-color: #ffffff;
}

#area-logo {
    float: left;
}

#main-menu ul {
    margin-left: auto;
    margin-right: 0px;
    padding: 0;
    list-style-type: none;
    text-align: center;
    width: auto;
}

#main-menu ul li {
    display: inline;
}

I am looking to ensure that the colored bar above each link and over the logo area have consistent sizes so that if text expands, the width will also increase accordingly.

How should I go about achieving this?

UPDATE

The updated code on jsFiddle has resolved my initial problem. However, it has revealed a rendering bug with the new Microsoft Edge browser, which adds an extra 1px to the border-top of the <li>.

Answer №1

To achieve the desired layout, change the display: inline; to display: inline-block; for the li elements in your CSS. Additionally, add a border-top: 6px solid #787aad; to each li to get the colored bar effect over each link.

In the provided CSS snippet, you can find styles for the logo area, main menu, and list items. Adjusting these styles will help you customize the appearance of your navigation bar according to your design preferences.

EDIT #1: For expanding the logo element, consider adding width: 50%; and display: block; to the #area-logo and #main-menu elements in your CSS.

Answer №2

If you want things to align properly, here is the recommended CSS to use. Instead of display: inline-block, it is advised to utilize a float in this scenario.

Check out this JSFiddle for reference: http://jsfiddle.net/vrc4qhbn/2/

header {
    position: relative;
    }
    header *,
    header *:before,
    header *:after {
        -webkit-box-sizing: border-box;
        -moz-box-sizing:    border-box;
        box-sizing:         border-box;
        }

    #area-logo {
        position: absolute;
        top: 0;
        left: 0;
        width: 150px; /* Adjust as needed */
        }
    #main-menu {
        width: 100%;
        padding-left: 165px; /* Logo width plus spacing */
        }
        #main-menu > ul {
            float: right; /* Navigation aligned to the right */
            }
            #main-menu > ul > li {
                display: block; /* Display as block element */
                float: left; /* Align navigation items from the left */
                }

Answer №3

Make sure to incorporate this CSS snippet into your stylesheet:

#main-menu ul li {
    display: inline;
    float: left;
}

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

Tips for preventing control click events from interfering with modal dialog interactions

From what I understand, when I open a modal dialog in jQuery, all input controls will be disabled. However, I am still able to click on buttons, divs, and other controls. Is there a way in jQuery to disable all interactions once the modal dialog is opene ...

Best practices for displaying code blocks within an AngularJS application

Currently, I am in the process of building a website focusing on AngularJS within AngularJS ;-) To accomplish this, I have included ng-app within the body element. As a result, all my code snippets (enclosed in <pre><code> ... </code>&l ...

Achieve a full height for children without the need to specify a fixed height for the

I'm currently working on a container div that houses two child divs: the first one, positioned to align with its parent's left border, contains a series of buttons while the second one holds the main content. In essence, it operates like a tab na ...

What steps are involved in incorporating a machine learning algorithm from a Python file into a Django website?

I'm currently utilizing the random forest algorithm in Python to make predictions about college dropouts. The algorithm has been completed, and now I need to integrate the file into a website using Django. However, I am facing issues as the imported f ...

Attaching an SVG chart to a node causes it to malfunction, indicating a fundamental element is absent

I've been attempting to display a d3fc graph on an svg node within my react.js component and return the entire structure. However, it crashes when I try to apply .datum(my_data) to the d3 selection. I suspect that I'm overlooking something fundam ...

Understanding the integration of sass with webpack in an Angular 4 project

Is it possible to reference a sass file instead of a css file directly in the index.html? If so, how does webpack compile the sass into a css file? Additionally, what is the most effective way to bundle the sass file when building the application? The ve ...

Craft a stunning transparent border effect using CSS

I am trying to achieve a unique border effect for an element using CSS, where the transparency is maintained against the background: This is the desired outcome: https://i.stack.imgur.com/6Z1MU.png However, the border I am currently able to create looks ...

Adjust the menu scrollbar position to the right or limit scrolling to within the menu area

$(function() { "use strict"; $(".navbar-toggler").on("click", function() { $(".navbar-toggler").toggleClass("collapsed"); $(".offcanvas-collapse").toggleClass("open"); let menuposition = $("#toggler").offset().left + $("#toggler").width() + ...

Animations are failing to run within a Bootstrap card when using Vue rendering

I have utilized Bootstrap cards to display pricing information in my project. I implemented a collapse feature for half of the card when the screen size is equal to mobile width. While using vanilla Bootstrap, the animation worked seamlessly with the col ...

I seem to be having trouble with my JavaScript code when attempting to search for items within

I want to implement an onkeyup function for a text input that searches for patient names from column 2 in my table. However, it seems to be not working properly as I don't get any results in return. Below are the snippets of what I have done so far. ...

unable to view the contents of the template using the directive

I am facing an issue with the Directive, as it is not adding an element to the Template. This directive has been included in the .html file. There are no errors being displayed in the console. directive.js: app.directive('myDirective', function ...

Modifying Checkbox BorderWidth in Material UI v5

Seeking assistance with adjusting the checkbox border width in Material UI v5. I currently have a custom checkbox and would like to remove the border width. Despite trying numerous solutions, I have been unsuccessful so far. checkbox <Checkbox de ...

Why does the width of my image appear differently on an iPhone compared to other devices?

I recently encountered an issue with the responsiveness of an image on my website. While it displayed correctly on Android and desktop devices, the image appeared distorted on iPhones as if the CSS width attribute was not applied properly. This problem spe ...

What is the best way to retrieve the value of a submitted button in a jQuery form submission?

I am facing an issue with my HTML code. Here is the structure: <form method="post" id="IssueForm" action="wh_sir_insert.php"> <input name='id[]' type='checkbox' class="selectable" value='$col[8]' /> <inpu ...

Change the position of an array element when displayed on an HTML page

I'm trying to figure out a way to manipulate the position of an HTML element that is stored inside an array. The issue I am facing is that my code generates a new div every time a specific function is called, and this div has a class applied to it for ...

Middle-Click JavaScript Action

On the website I'm currently working on, there is a button that uses a sprite sheet animation and therefore needs to be set as a background image. I want the button to have a slight delay when clicked, so the animation can play before redirecting to a ...

Transfer data from a div to JavaScript

Within a php file, there is a div in which an id and some data are returned. Take a look at the code: <div id="dom-target" style="display: none;" data-stuff="2017, 8, 20, 0, 0"></div> So, I am trying to retrieve the value of data-stuff and pa ...

Footer alignment issue when using react-full-page is causing it to not lineup at the bottom of the page

Currently, I have integrated the react-full-page package into my project. However, after adding the Footer to the routes, I noticed that the footer is only visible in the second section of the page and does not appear at the bottom as expected. If you wan ...

Detecting whether a browser is capable of supporting dark mode

One method to determine if dark mode is active is by using prefers-color-scheme: dark: const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; Is there a way to detect if a browser supports dark mode as well? (By "supports ...

unable to receive the data transmitted by the socket.io client

I hit a roadblock while trying to follow the tutorial on socket.io. I'm currently stuck on emitting events. Previously, I successfully received the console logs for user connected and user disconnected. However, when it comes to emitting messages, I a ...