Exploring CSS3 for Creating Stylish Navigation Bars

Currently, I am attempting to design a Navigation bar that resembles the style shown in this image, complete with a drop-down menu feature. Here is how I have structured my menu:

<nav>
            <ul>
                <li> <a href="/index.php">Home</a></li>
                <li><a href="/kbi/articles/articles.php">Articles</a>
                    <ul>
                        <li><a href="/kbi/articles/new/new.php">News & Updates</a></li>
                        <li><a href="/kbi/articles/reviews/reviews.php">Reviews</a></li>
                        <li><a href="/kbi/articles/toppicks/toppicks.php">Top Picks</a></li>
                        <li><a href="/kbi/articles/vault/thevault.php">Vault</a></li>
                        <li><a href="/kbi/articles/myrig.php">My Rig</a></li>
                    </ul>
                </li>
                <li><a href="kbi/devices/devices.php">Devices</a>
                    <ul>
                        <li><a href="/kbi/devices/android/android.php">Android</a></li>
                        <li><a href="/kbi/devices/ios/ios.php">IOS</a></li>
                        <li><a href="/kbi/devices/windows/windows.php">Windows</a></li>
                        <li><a href="/kbi/devices/osx/osx.php">OSX</a></li>
                        <li><a href="/kbi/devices/linux/linux.php">Linux</a></li>
                    </ul>
                </li>
                <li><a href="/kbi/about/about.php">About</a>
                    <ul>
                        <li><a href="/kbi/about/contact/contact.php">Contact</a></li>
                        <ul>
                            <a href="/kbi/articles/myrig.php">My Rig</a>
                        </ul>
                    </ul>
                </li>
            </ul>
        </nav>

In addition, here is the corresponding CSS styling for the navigation bar:

nav ul ul {
display: none;
}

nav ul li:hover > ul {
    display: block;
}
nav ul {
background: #efefef; 
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);  
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%); 
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%); 
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 10px;  
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
    content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
    background: #4b545f;
    background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
    background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
    background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
    nav ul li:hover a {
        color: #fff;
    }

nav ul li a {
    display: block; padding: 25px 40px;
    color: #757575; text-decoration: none;
}
nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
    float: none; 
    border-top: 1px solid #6b727c;
    border-bottom: 1px solid #575f6a;
    position: relative;
}
    nav ul ul li a {
        padding: 15px 40px;
        color: #fff;
    }   
        nav ul ul li a:hover {
            background: #4b545f;
        }
nav ul ul ul {
position: absolute; left: 100%; top:0;
}

However, the navigation bar does not extend the full width of the page. How can I modify it to achieve this?

Answer №1

Based on your current styles, the nav ul element has a display: inline-table property, causing it to take up only as much horizontal space as necessary. To make it span the entire width, you should change it to a block level element:

nav ul {
    background: #efefef;
    background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -webkit-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
    padding: 0 20px;
    border-radius: 10px;
    list-style: none;
    position: relative;
    display: block; /* change to block */
}

Check out the demo here: http://jsfiddle.net/e0ar7urh/1/

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

Only conceal the breadcrumb trail on the 404 error page

I have recently created a custom node for my site's 404 page with the path /node/83 in the site information. However, I am facing an issue where I cannot hide the .breadcrumb element using display:none. I attempted to achieve this through CSS injector ...

Using jQuery to remove the 'active class' when the mouse is not hovering

I recently came across this amazing jQuery plugin for creating slide-out and drawer effects: However, I encountered a problem. I want to automatically close the active 'drawer' when the mouse is not hovering over any element. The jQuery plugin c ...

The "initialized" event in angular2-tree-component fires prior to the data being loaded

Utilizing the angular2-tree-component, my goal is to display an already expanded tree. According to Angular docs, the initialized event should be used for expanding the tree after the data has been received: This event triggers after the tree model has ...

A guide on creating and accessing a variable within a Jinja for loop

Whenever a link is clicked by the user, I would like Jinja to establish a variable known as {{ contact_clicked }} that holds the same value as {{ contact }}. I thought about using <a href="/?{% contact_clicked = contact %}">.....</a> ...

What is the process for incorporating a button to the left of the search field?

Is it possible to enhance the search field by adding a button to make it more user-friendly? Below is the code I have been using: <div id="search"> <div class="container"> <h1>Search U.K. house price data</h1> <form c ...

Enter the website address into the designated text field, then simply click on the GO button to be redirected to the destination website within

I'm looking for a basic HTML code that allows users to input a website URL in a text field on my website, hit "GO," and be redirected to the entered site. It seems like this feature is hard to come by as I haven't found any websites with similar ...

How can I create spacing between squares in an HTML div element?

Currently, I am working on my project using Laravel 5. I retrieve some integer values from a database and use them to create square divs in HTML. Below is the current output of my work. https://i.stack.imgur.com/sy2ru.png You may notice that there is spa ...

scrollable header within the confines of the container

I have been trying to find a solution for my scrolling issue, but I just can't seem to get it right. I want the content within a div to scroll inside its container without affecting the header. Here's the updated JSFiddle link with the jQuery cod ...

The presence of concealed cells within an HTML table is leading to an increase in the

I am currently working on an HTML Table that serves as a summary table for displaying a list of items. The table has 4 visible columns out of approximately 20, with the remaining columns set to display: none;. However, the hidden cells are causing the rows ...

The JSON output displayed my HTML `<br />` as unicode `u003cbr /u003e`, resulting in the `<br />` being shown as text instead of creating a line break

Utilizing ASP.net MVC3, I have retrieved a model in Json format using Jquery.AJAX and am passing it into a Jquery template for rendering. For instance, the Json returned by the server is {"Key":2,"Content":"I'm Jason\u003cbr /\u003ehow are ...

Display the percentage text behind a filling Bootstrap progress bar

I'm working on a bootstrap progress bar that displays a percentage along with the numerical value. Currently, the text fits next to the progress bar up until around 85%, after which it blocks the bar from growing further. You can see the issue in the ...

Is there a way to utilize JavaScript in order to trigger a CSS animation to occur at a designated time during a video

I have a cool animated image element that I want to play at a specific point in time during a video using JavaScript. I'm not sure how to make it happen, but I know the .currentTime property could be the key. My goal is for the animation to only play ...

Creating customizable divider lines with text next to them using HTML in emails

How can I create an adjustable line with a word next to it, ensuring that long words do not wrap onto a second line? I want the line to stay on one line and the left side to shrink accordingly. Also, I need the text input area to be flexible so I can input ...

Issue with Vue2: DIV does not adjust height when using v-for loop

I have a div set up like: <div class="pt-4"> <h5>Genres:</h5> <div class="inline-block float-left" v-for="(genre, index) in moreData.genres" :key="index"> <span v-if="index < ...

Link the parameters of two polymer elements within a repeat template

In this scenario, my goal is to securely bind attr and attr1. These two variables should be independent from the variable data, unlike other attributes in use. I want each iteration to have its own set of bound components, rather than sharing one data obje ...

Ensure portrait orientation images have a restricted width to maintain their aspect ratio

On a responsive site, I have set up flexslider to showcase both landscape and portrait orientation images. The smoothHeight: true option is enabled to adjust the height according to the images. However, at the largest media query where the flexslider cont ...

Discover the hexadecimal color code generated from an rgba color

Do you know of a service that can determine the final hexadecimal value of an rgba color? For instance, if my body background-color is set to #FF0000 and my header is positioned over it with a background-color of rgba(0,0,0,.7), how can I find out what the ...

Update the content retrieved through ajax periodically

Looking to set up a periodic update for this ajax fetch function, say every 10 seconds. I've tried a few approaches but none seem to work as expected. That's why I'm reaching out here for help. So, any idea how I can refresh the content ev ...

Assign a value to the input field based on changes made in another input field

I am brand new to the world of JavaScript and currently grappling with setting a value in an input field based on the onchange event of another input field. Here is my code sample for input field 1: <input type='text' onchange='methodTh ...

Adjust the margin of FormHelperText within a FormControl specifically for a Select component in Material-UI

I'm currently facing a challenge where I need to add marginLeft of 8px to FormHelperText. However, I have not been successful in doing so within the MuiInput formControl rule or in MuiSelect. Here is the React code snippet: <FormControl error clas ...