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

Can you explain the distinction between using a period in a class selector and not using one?

Could someone please clarify the meaning of the code snippet below? <div class="cls1 cls2">abcd <div class="cls2"> adfffff </div> </div> .cls1 { background-color: yellow; } /*sample1 .cls1.cls2 { color: red; } */ /* ...

Using JavaScript to print radio type buttons

Currently working on a web page and I've encountered a problem that's got me stumped. There are two sets of radio buttons - the first set for package dimensions and the second set for weight. The values from these buttons are assigned to variable ...

Restoring styles back to the default CSS settings

I am currently working on creating visualizations using D3, and one challenge that I have encountered is the need to define a lot of styles within my code instead of in my CSS where I would prefer them to be. This necessity arises mainly to support transi ...

What do I do when I encounter the error message "Provider not found for RadioControlRegistry" in Angular 2? Which provider should

Which provider should be included in the provider component? <div class="radio"> <input let match id="male" type="radio" name="gender" value="true" [(ngModel)]="isMatching" (click)="isMatching(match.value)" > Take a look at my console output ...

Make the div stretch to the bottom of the webpage

This question may be a common one, but despite my efforts, I have not been able to find a solution to what seems like a simple issue. Here is the code snippet in question: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

What is the best way to adjust the fontSize of text within a table using Material UI?

In my Material UI table, I am attempting to adjust the fontSize of the contents. However, when I try to modify it using the style={{}} component, the changes are not being applied. <Grid><Typography variant="body1">Fiscal Year </Typography&g ...

IE11 React application cannot recognize the <main> tag

When using my React application, I encountered the following error message in the dev console while using IE11: Warning: The tag <main> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase let ...

Tips for modifying only one property after receiving an object from an HTTP GET request

Within my Angular application, I have defined an object structure like this: export class Article { id: number; author: number; title: string; content: string; date: Moment; readingTime: number; draft: boolean; constructor(obj: Partial< ...

Problem encountered in AngularJS CheckBox binding where the checkbox remains unchecked despite the model having a checked value

I am working with AngularJS and have implemented the following code: <div > <input type="checkbox" ng-model="vehicleDetails.selfOwned"> Owned </div> <div> {{vehicleDetails.selfOwned}} </div> The mo ...

Determine the total character count in every paragraph

Looking for a way to tally up the number of characters in each paragraph on a webpage. Came across this handy snippet that counts words in paragraphs and it works like a charm. Wondering if it can be tweaked to also calculate the character count. There are ...

Is there a way to iterate through identical sections of HTML using BeautifulSoup?

Looking to extract information from each of the "item watching" elements within the "items" class. Currently facing a challenge where using the find method only retrieves HTML for the first occurrence of "item watching". Aiming to avoid utilizing find_all ...

Unable to retrieve data from PHP using AJAX request

My project consists of 3 interconnected files: index.php, functions.js, and compute.php In index.php, there is a div that triggers a function in functions.js called compute(), which sends an AJAX request to perform a task in compute.php The code in index ...

Encountering an IndexError while iterating through a table in Selenium using Python due to a list index being out of range

Encountering IndexError: list index out of range while iterating through an HTML table but unsure about the cause. My function for iterating through the table involves clicking on web page frames and downloading files from another frame. The table consis ...

Switching back and forth between JQuery and CSS display changes

My challenge involves utilizing a JQuery file to present one question at a time in a quiz format. Upon clicking the submit button, the intention is to progress to the subsequent question. However, I have encountered an issue where the transition occurs mom ...

Searching for a JavaScript tool that offers syntax highlighting capabilities

I have come across some excellent RTE HTML text editors such as jsredaktor, TinyMCE, and FCK Editor, but I am in search of an HTML/JavaScript component that functions similarly to a TEXTAREA with built-in code syntax highlighting. ...

Avoid allowing text to spill out of the designated container

Hey there, I've run into this issue twice now and I can't seem to find a solution for the second occurrence. The first time it happened with an image, I used max-height and width to prevent it from overflowing the div when zoomed in. But now, for ...

Utilizing CSS position sticky in Bootstrap 4 to maintain visibility of a sidebar

I currently have a layout with two columns structured like this: <div class="row"> <div class="col-xs-8 content"> </div> <div class="col-xs-4"> </div> </div> By applying the position:sticky to the si ...

Customize Color of Bootstrap Tooltips

Is there a way to customize the appearance of BootStrap tooltips by changing the color and aligning the text to the left? I've tried various CSS modifications from different posts, but none seem to work. Any idea on how to alter the CSS of the tooltip ...

Bootstrap carousel powered by AngularJS

Struggling to incorporate bootstrap, angular, and a carousel to showcase images from local folders on my drive. Unsure how to customize the angular file properly. The example provided in the link below fetches images from the Internet, but I need to modify ...

Creating a Distinct Interior Array Separate from the Exterior

I'm currently working on a project that involves creating a 2D array. I want the interior elements of this array to be black while the exterior elements should be white. However, my 2D array doesn't seem to be forming correctly - it looks more li ...