Menu full width of the page [duplicate] - html

This question already has answers here:
Set div width equal to window size
(6 answers)
Closed 8 years ago.
I have a menu I want to be the entire width of the site even when I zoom out but can't manage to make it work, this is my code.
HTML:
<div id="menu">
<ul>
<li>home</li>
<li>contact</li>
<li>about</li>
<ul>
</div>
CSS I Have tried:
#menu {
width: max;
background-color: #f4f4f4;
height: 75px;
}
And
#menu {
width: 1920px;
background-color: #f4f4f4;
height: 75px;
}

Make the width 100% -- change it in your CSS to width: 100%;
HTML :
<div id="menu">
<ul>
<li>home</li>
<li>contact</li>
<li>about</li>
</ul>
</div>
CSS:
#menu {
width: 100%;
background-color: #f4f4f4;
height: 75px;
}

Related

How do I get my 'logo' image to show in the header?

I'm very, very new to HTML and CSS, so sorry for my ignorance! I'm trying to add an image to my header, to go to the left and above the navigation. Any help anyone can give would be amazing!!
I have tried two ways of adding the image, the first using , but it did not show (I could see the image 'content' highlighted in blue on the page when i was in the console, but i couldn't see the image. The second way I used a , then the css below:
body {
background-color:#4A4849;
margin: 0 auto;
font-family:Arial, helvetica, sans-serif;
}
.Logo {
display: inline;
float:left;
width: 100%;
height: 100%;
background-image: url('../Images/Logo.png');
}
header {
text-align: center;
width: 100%;
height: 15%;
background-color: white;
margin: 0;
}
My full CSS includes the below...i feel like the problem is to do with the , as in the console the dimensions show as 1304x0 (but I am able to see the navigation) I therefore tried adjusting the header, which is why it duplicates with the .topnav.(see below) :)
.topnav {
font-weight: bold;
background-color: white;
overflow: hidden;
position: fixed;
top: 0;
left 0;
width:100%;
height:15%;
}
.topnav ul {
list-style-type:none;
overflow: hidden;
margin:0;
padding: 0;
}
.topnav li {
display:inline;
padding: 0px;
margin: 0px;
}
.topnav a {
float: right;
color: #4A4849;
text-align: center;
padding: 20px 10px;
text-decoration:none;
width:10%;
}
It would be great if anyone could help, as I've tried different things based on resources i've found online!
*HTML, in case you need it:
<body>
<header>
<div class="Logo"></div>
<nav>
<div class="topnav">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>GRAPHIC DESIGN</li>
<li>MARKET</li>
<li>HOME</li>
</ul>
</div>
</nav>
</header>
There are a few things that can be changed with how you are setting things up:
I would recommend not making your logo the background-image on a div, when an <img> tag will work better in your case (<img src="path/to/your/logo.png">).
If you do use it as a background-image on a div, you have to remember that background images do not affect the height of an element.
Setting a % height on the .Logo div will also not work, since a percentage height needs to be relative to a containing element and you also set it to an inline element (height will not apply). Since, its parent (header) has as height of 15%, but that element also has no reference to 15% - e.g. 15% of what? The body tag would need to have a height set to 100%.
Only for your logo, I would simply do this:
<header>
<img src="your logo link">
<nav>
<div class="topnav">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>GRAPHIC DESIGN</li>
<li>MARKET</li>
<li>HOME</li>
</ul>
</div>
</nav>
</header>
If you absolutely want to make it a background-image:
.Logo {
height: whatever your logo height is;
display: block;
background-image: url( ../Images/logo.png );
background-repeat: no-repeat;
}
<header>
<div class="Logo"></div>
<nav>
<div class="topnav">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>GRAPHIC DESIGN</li>
<li>MARKET</li>
<li>HOME</li>
</ul>
</div>
</nav>
</header>

Excess space next to header [duplicate]

This question already has answers here:
Does UL have default margin or padding [duplicate]
(2 answers)
Closed 3 years ago.
I'm having issues with excess space to the left of my header.
I had the same problem with my footer as well using <nav> and <ul>, but edited this to only using <a> elements instead, and this seemed to do the trick. I would, however, like to keep the <nav> in the header, and preferably without using negative margin-left.
https://jsfiddle.net/thereseel/d75jurzy/6/
<header>
<nav>
<ul class="mainnav">
<li>Home</li>
<li>Menu</li>
<li>Logo</li>
<li>Contact</li>
<li>Location</li>
</ul>
</nav>
</header>
you are facing excess space to the left of your header because of ul
browsers have default CSS values for many elements and ul is one of them.
from your current code just remove the padding
example:
.mainnav {
/* add this to override default padding left of ul*/
padding-left: 0;
}
Here is Reference of default CSS values used by browser : w3schools link
Try with this code.
HTML code:
<header>
<nav>
<ul class="mainnav">
<li>Home</li>
<li>Menu</li>
<li>Logo</li>
<li>Contact</li>
<li>Location</li>
</ul>
</nav>
</header>
<div class="main-body">
</div>
<footer >
<section class="footnav">
Home
About
Order
Jobs
Contact
</section>
</footer>
CSS code:
.main-body{
min-height:500px;
}
.mainnav {
max-width: 800px;
margin-left: 0;
margin-bottom: 5px;
text-align: center;
display: flex;
justify-content: space-evenly;
padding-left:0px;
}
.mainnav li {
display: inline-block;
}
.footnav {
width: 100%;
text-align: center;
display: flex;
justify-content: space-evenly;
}
footer{
position: fixed;
left:0;
right:0;
bottom:0;
}
.footnav a {
display: inline-block;
padding: 10px;
}
Hope it working.

How to get an image behind a navigation bar

Kinda new to HTML, want to edit my navigation bar so that it has an image behind it and the nav bar sits at the bottom of the image. How do I do this?
After looking at a few forum posts, this is what I tried:
#cover {
background-image: url("Images\FB Cover.png");
}
<div id="cover">
<div>
<nav>
<li>Home</li>
<li>About DRC</li>
<li>Our Products</li>
<li>Contact</li>
</nav>
</div>
</div>
#cover {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(http://lorempixel.com/800/600) no-repeat 50% 50% / cover;
}
menu {
position: absolute;
left: 20px;
bottom: 20px;
}
a {
color: #fff;
}
<div id="cover">
<menu>
<li>Home</li>
<li>About DRC</li>
<li>Our Products</li>
<li>Contact</li>
</menu>
<div>
simple example
to place image as background of DOM element you can use, background-image css property.
For example
background-image: url('https://static.pexels.com/photos/87646/horsehead-nebula-dark-nebula-constellation-orion-87646.jpeg');
W3School has great documentation about css properties.
here is the link

HTML, I don't get why still need to put class="container" under class="nav"?

I don't get why still need to put class="container" under class="nav"? the class="nav" has already separate the whole element... why still need to put class="container"?
<div class="nav">
<div class="container">
<ul>
<li>Airbnb logo</li>
<li>Browse</li>
</ul>
<ul>
<li>Sign Up</li>
<li>Log In</li>
<li>Help</li>
</ul>
</div>
</div>
Why?
Because, in the absence of any other information, you might wish to restrict the width of the .container class but not that of the .nav class.
Perhaps you want the .nav to be 100% wide (which it would be by default) but the container to be 80% wide and centered.
That is just one reason...
Example Below:
* {
margin: 0;
padding: 0;
}
.nav {
background: lightblue
}
.container {
width: 80%;
margin: 0 auto;
background: green;
height: 150px;
}
<div class="nav">
<div class="container">
</div>
</div>

Vertical center menu in navigation bar

I'm struggling with this problem for over an hour and can't get it right, I know these are basics but none solution from google helped, I don't understand what's the problem. I got that navigation bar and I want to vertically center logo and list elements inside it:
<nav id="mainMenu">
<img class="logo" src="images/logo.png" alt="logo" />
<ul id="menu">
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
css:
http://klaunfizia.pl/damian/style.css
Here's the demo: http://klaunfizia.pl/damian/
#edit:
When I put margin-top:50% for #menu why it refers to entire body instead of nav element?
Notice - the class name are different. From your existing style, remove: #mainmenu, #menu, and #menu li. Here is an example the code -> DEMO
Here is your new html:
<ul class="nav"> <img class="logo" src="images/logo.png" alt="logo" />
<li>Home
</li>
<li>About me
</li>
<li>Portfolio
</li>
<li>Contact
</li>
Here is your new CSS:
.nav {
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
background-color:red;
}
.nav li {
display:inline;
}
.nav a {
display:inline-block;
padding:10px;
text-decoration: none;
color: #000000;
}
Since your "nav" element is fixed try wrapping your "ul" element in a div and setting the css of the margin to the distance you desire.
<div style="margin-top:20px">
<ul id="menu">
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
The vertical spacing of block elements can be a bit tricky as they were never intened to behave that way. So some tricks are always required.
You can center them to the middle by making the list and the logo's position relative, than giving them a 50% top and a negative margin with the half of their height. So just add these properties to the existing ones:
.logo {
position: relative;
top: 50%;
margin-top: -25px;
}
#menu {
position: relative;
top: 50%;
margin-top: -10px;
}
use this:
#mainMenu {
height: 80px;
width: 100%;
background-color: #F00;
position: fixed;
line-height: 80px; /* added */
}
#menu {
float: right;
margin-right: 16%;
display: inline-block; /* added */
}