Designing a navigation bar with CSS

I created a CSS menu using ul li elements with the goal of making them cover the entire width of the div when placed next to each other. Currently, it appears like this: https://i.sstatic.net/uKbzs.png My aim is to have the green area touch the borders.

Below is the CSS code I used:

#menu {
    width: 100%;
    height: 1%;
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    font-weight: bold;
    text-align: center;    
}
#menu ul {
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
}
#menu li { 
    display: inline;
    margin: 0;
    padding: 0; 
}
#menu a {
    text-decoration: none;
    height: 100%;
    width: 100%;
    margin: 1px;
    padding-top: 1%;
    padding-bottom: 1%;
    padding-right: 6%;
    padding-left: 6%;
    background-color:#04B45F;
    color: #F0F0F0;
}
#menu a:hover {
    color: #04B45F;
    background-color: #FFF;
}

Answer №1

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body{background-color:#04B45F; text-align: center;}
div{width: auto; height: auto;}
#body{border-style: ridge; border-color: grey; border-width: 2px; background-color: white; padding: 0; margin: 1%;}
#logo{margin: 2px;}
#menu {
 width: 100%;
    height: 1%;
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    font-weight: bold;
    text-align: center;    
}
#menu ul {
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
    text-align: center;
}
#menu li { 
display: inline-block;
margin: 0 1%;
padding: 0; 
    width: 18%;
    
}
#menu a {
text-decoration: none;
height: 100%;
    width: 100%;
    display: block;
    padding: 10px 5%;
    
    background-color:#04B45F;
    color: #F0F0F0;
}
#menu a:hover {
    color: #04B45F;
    background-color: #FFF;
}
#contents{text-align: left; margin: 2px; padding: 5px;}
#login{float:right; border: solid 1px; border-right: 0; margin: 0; padding: 5%;}
#info{overflow: hidden;}
hr{margin: 0px;}
<body>
<div id="body">
<div id="logo"><img id="logo_im" width="100%" height="250px" src="http://upload.wikimedia.org/wikipedia/commons/3/32/Easyjet.ezyi.b737.750pix.jpg"/></div>
<br />
<div id="menu">
<ul>
<li>
<a href="index.jsp" id="menus">Main Page</a>
</li><li>
<a href="#" id="menus">Learn More</a>
</li><li>
<a href="#" id="menus">Discuss</a>
</li><li>
<a href="#" id="menus">Gallery</a>
</li><li>
<a href="#" id="menus">Contact Us</a>
</li>
</ul>
</div>
<div style="float:right;">
<br /><br /><br /><br />
<div id="login">
Log into our website!
<form method="post">
Username: <br />
<input type="text" name="username" />
<br />
Password: <br />
<input type="password" name="pass" />
<br />
<input type="submit" value="Login">
<br />
<i>You didn't sign up yet?<br /><a href="register.jsp">No problemo!</a></i>
</form>
</div>
</div>
<div id="contents">
<br />
Welcome to "On The Air" a website that's dedicated for you! <br />
Did you ever wondered or had any questions about aviation, commercial jets and more?<br />
We're hoping that you'll find your answers here, and if not you can ask questions in our chat.<br />
<br /><br />
Did you signed up yet? <a href="register.jsp">Join</a> our community now! Currently registered: <%=application.getAttribute("X") %><br />
<br />
<img src="https://c1.staticflickr.com/9/8432/7811765360_e51f479602_z.jpg" width="200px" height="200px" />

</div>
</div>
</body>

Answer №2

Give this a shot

To make it work, simply insert display: block; in the appropriate tag (#menu a)

Take a look at this demo here: http://jsfiddle.net/dykgsc0L/

Answer №3

Gratitude to all for the assistance, it is truly appreciated. Seems like I failed to articulate my question clearly.

body{background-color:#04B45F; text-align: center;}
div{width: auto; height: auto;}
#body{border-style: ridge; border-color: grey; border-width: 2px; background-color: white; padding: 0; margin: 1%;}
#logo{margin: 2px;}
#menu {
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    font-weight: bold;
    text-align: center; 
    background-color:#04B45F;
    overflow: hidden;
}
#menu ul {
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
}
#menu li { 
    display: inline;
    margin: 0;
    padding: 0; 
}
#menu a {
    text-decoration: none;
    height: 100%;
    width: 100%;
    padding-top: 1%;
    padding-bottom: 1%;
    padding-right: 6%;
    padding-left: 6%;
    background-color:#04B45F;
    color: #F0F0F0;
}
#menu a:hover {
    color: #04B45F;
    background-color: #FFF;
}
#contents{text-align: left; margin: 2px; padding: 5px;}
#login{float:right; border: solid 1px; border-right: 0; margin: 0; padding: 5%;}
#info{overflow: hidden;}
hr{margin: 0px;}

http://jsfiddle.net/4h0Lvhsd/3/

Realized that setting the whole div's background in the same color as the bottom and using overflow: hidden created a neatly aligned look.

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

Solving the enigma of CSS positioning: mastering floats, margin-left/right, and auto

Hey there, I'm having trouble posting an image but here is the link: I believe this explanation will be clearer, D2, D3 & D4 need to be aligned next to each other and centered on the screen at all times. (960px)      & ...

A guide to implementing toggle functionality on child elements

After clicking the button, the entire sidebar toggles, but I only want the side menus to toggle. Here is the relevant HTML code: <nav id="sidebar"> <div class="sidebar-header"> <img src="/fintantra/image ...

Pause the counter based on the data attribute containing multiple values

I have a collection of div elements, each with a unique data-attribute value. My goal is to display these values in the divs using JavaScript by incrementing a counter. const numbers = document.querySelectorAll(".number"); console.log(numbers); let c ...

Scrolling through menus horizontally

I am faced with a challenge where I have Menu items from Menu1 to Menu10, but the limited space on the web page prevents me from displaying all the menu items at once. Currently, I can only show 4 menu items - Menu4 to Menu7. To access the remaining menu i ...

What is the best method for adjusting the size of a button on a video as needed?

@import url("https://fonts.googleapis.com/css2?family=Luxurious+Script&display=swap"); * { margin: 0px; padding: 0px; box-sizing: border-box; font-family: "Luxurious Script", cursive; } body { background-color: #e97272; } .navbar { backgr ...

Issues arise with tabbed content as default content fails to display and classes are not added upon clicking

I'm currently working on a tabbed module that consists of three tabs. Here's how it operates: When the user clicks on a carousel_element, it reveals carousel_hidden-text within that div and displays it in another div called carousel_quote. I&ap ...

Transmit information to a different JavaScript framework using Vue

Utilizing Vue, I create a JSON file using classic ASP from SQL Server and import the data. My objective is to showcase the received data on the page and in ApexCharts. The structure of the HTML page, getData.js, and the JSON from dataSql.asp is outlined b ...

What could be causing the p tag to be displacing the parent div downwards?

Can someone help with an issue I'm having? I have two divs that are supposed to take up half of the screen each. However, when I add a p tag inside the second div, it gets pulled down. I am working on creating an HTML email, so I can only use inline s ...

Having trouble getting a resizable DIV inside a 100% height DIV with margin to work properly. Any tips or assistance would be greatly

I've encountered a common issue that is slightly different from others I've come across. Despite my best efforts, I have been unable to find a solution on my own. If anyone could offer me some guidance on this, I would greatly appreciate it. The ...

Struggling to understand why the PHP/HTML form with a file upload field is not successfully uploading

I've been staring at this code for the past two hours and I can't seem to spot the issue. It's probably something simple, as I keep getting an undefined index error, but it's eluding me. Could you please take a look with fresh eyes? He ...

What could be causing angular-datatable to not properly fill columns in Bootstrap 4?

I have been attempting to create a responsive table using angular-datatables (for angular 7) and bootstrap 4, but I am encountering issues with the current appearance of the table: Current HTML code: <div class="row"> <d ...

Utilizing Java's IE/Chrome HTML-Renderer or managing file storage with JavaScript

I am currently in the process of developing a small application that operates offline only. I want to keep it simple and was considering using HTML, CSS, and JavaScript as they should suffice for my needs. However, I require access to the filesystem to sto ...

What is the best way to insert a Bootstrap Glyphicon into an asp:Button in ASP.Net?

In my current project, I am utilizing Bootstrap 3 and aiming to incorporate Bootstrap Glyphicons into ASP.net buttons. However, I encountered an issue when using the following code (I discovered a solution that utilizes Twitter Bootstrap <span> tags ...

Using Javascript to prevent css from changing the display

I want to make some CSS adjustments to a single element using a single script, but I want all the changes to be displayed at once. For example: $("#someelement").css({width:"100%"}); //this change should not be displayed $("#someelement").width($("#someel ...

Python form submission error code 405 encountered

I recently developed a simple WSGI Server using Google app engine. Here's an example of the code: import webapp2 class MainHandler(webapp2.RequestHandler): def get(self): self.response.write(''' ...

Using the combination of Chrome browser, Lucida Grande font, and word-wrap

Recently, I encountered a unique situation in Chrome where an odd combination of styles led to an issue. To help illustrate the problem, I created a fiddle which can be viewed here: http://jsfiddle.net/C3CbF/1/ This particular issue is only visible if you ...

employing the display flex property triggers the emergence of a lavender border

This is an example of a basic HTML structure: <section id="teasers"> <div class="wrapper"> <a href=""> <div class="redbox"> <h2 class="two-lines uppercaseme lowercaseme"> ...

Tips for preventing menu flickering caused by overflow during CSS animations

I recently created a vertical menu with an interesting underline effect that appears when hovering over the menu items. Even though the snippet initially failed to execute, I discovered this cool hover effect (taken from here) which I wanted to implement: ...

Linking HTML files across different directories

Here is the current structure of my folders: de/ index.html en/ index.html hu/ index.html img/ image.png style/ stylesheet.css I am wondering how I can link to the css file in the style folder and the image in the img folder directly ...

AngularJS's support for html5mode on GitHub pages is now available

Is it feasible for GitHub pages to accommodate AngularJS in html5mode? I came across a source online suggesting that it can be done with a fallback page for 404 errors. However, this solution seems flawed as it may result in multiple 404 errors, which wou ...