Chrome and opera leaves empty space on top because of li padding - html

I'm working on a homepage with fullpage slider.
At firefox everything went right!
At Chrome and Opera, I have an empty space on the top of the page.
I noticed that all the space is from the menu padding (li), when I turn it to 0 the space is getting shorter but is not leaving.
Here is my html
<ul id="connect">
<li>
logo
</li>
</ul>
<ul id="menu">
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
And my css is
#connect {
z-index: 10;
position: fixed;
width: 100%;
list-style: none;
margin: 0;
margin-left: 90px;
padding: 20px;
}
#menu {
z-index: 10;
float: right;
margin: 0;
font-size:12px;
list-style: none;
position:relative;
top:30px;
right:20px;
font-family: 'Open Sans', sans-serif;
}
li {
display:block;
float: left;
padding: 10px;
}
Could someone help?

I'd re-write your code like this so it's more simple and semantic: http://jsfiddle.net/kc4umn1c/
Whenever you use "position: fixed" you should also specify your X/Y coordinates ("left/right" in this case). I've added the styles below.
Also, look into using a reset.css file to make all of your styles fit nicely between browsers. (google html5 boiler plate, they have a good one.)
Good luck!
HTML
<header class="header">
<h1 class="logo">logo</h1>
<nav class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
</nav>
</header>
CSS
* { margin: 0; padding: 0; box-sizing: border-box; }
.header {
position: fixed;
left: 0;
top: 0;
right: 0;
background: black;
z-index: 1;
padding: 20px;
color: white;
}
.logo {
float: left;
display: inline-block;
}
.menu {
float: right;
display: inline-block;
color: white;
}
.menu ul {
list-style: none;
}
.menu ul li {
float: left;
padding: 10px;
}

Related

div not covering its content height

I'm trying to do a sort of nav bar without using any pre existing library.
The problem is that I want the nav links to have a padding but the header is not covering their height.
Here's what I've done so far
* {
margin: 0;
}
.header {
color: #fefbed;
box-sizing: border-box;
width: 100%;
position: sticky;
top: 0;
padding-right: 4.7%;
text-align: right;
background-color: #115695;
z-index: 1;
}
ul {
box-sizing: content-box;
}
li {
font-family: Montserratextrabold;
font-size: 16px;
display: inline;
margin-left: 2%;
}
li a {
padding: 5%;
border: 2px solid yellow;
color: #fefbed;
text-decoration: none;
}
<div class="header">
<ul>
<li>HOME</li>
<li>IL FILM</li>
<li>GALLERY</li>
<li><a class="selected" href="about.html">ABOUT</a></li>
</ul>
</div>
The result is this one. Why?
This is because a tags are inline elements. Inline elements treat margin and padding differently than block elements. You can add left and right properties, but not top or bottom.
You can change the display to inline-block which will respect the top and bottom padding you set.
* {
margin: 0;
}
.header {
color: #fefbed;
box-sizing: border-box;
width: 100%;
position: sticky;
top: 0;
padding-right: 4.7%;
text-align: right;
background-color: #115695;
z-index: 1;
}
ul {
box-sizing: content-box;
}
li {
font-family: Montserratextrabold;
font-size: 16px;
display: inline;
margin-left: 2%;
}
li a {
padding: 5%;
border: 2px solid yellow;
color: #fefbed;
text-decoration: none;
display: inline-block;
}
<div class="header">
<ul>
<li>HOME</li>
<li>IL FILM</li>
<li>GALLERY</li>
<li><a class="selected" href="about.html">ABOUT</a></li>
</ul>
</div>
EDIT
I did mark this as a duplicate, but wanted to give an answer, because OP asked why the header wasn't expanding - and the duplicated doesn't answer the question explicitly.

Extend element beyond container, but keep children within container

I've recently had a problem, where I want to keep all my content within a parent container, but I want the navigation background to be 100% of the width of the page. The methods I've tried have worked in terms of getting the navigation to be 100% width of the page, but now the ul inside isn't affected by the container, which is what I originally wanted.
I got it to work by using another container div inside the navigation, but I feel like this is a very makeshift method.
Any suggestions on how to get the parent container to affect the ul inside the nav?
HTML:
<div class="container">
<nav class="menu">
<div class="container">
<ul>
<li>HOME</li>
<li>ABOUT ME</li>
<li>SERVICES</li>
<li>CURRENT PROJECT</li>
<li>PORTFOLIO</li>
<li>CONTACT ME</li>
</ul>
</div>
</nav>
</div>
CSS:
.container {
margin: 0 auto;
width: 1200px;
}
.menu {
left: 0;
right: 0;
height: 80px;
position: fixed;
background-color: rgb(33, 33, 33);
}
.menu ul {
padding: 0;
margin: 0;
color: #fff;
list-style: none;
font-weight: bold;
height: 80px;
float: right;
}
.menu ul li {
display: inline-block;
padding-right: 50px;
}
You can use :before or :after pseudo selector for creating background effect that looks like having width equal to the width of the page.
body {
overflow: hidden;
width: 100%;
margin: 0;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.menu {
height: 80px;
position: relative;
}
.menu:before {
background-color: rgb(33, 33, 33);
position: absolute;
right: -9999px;
left: -9999px;
content: '';
z-index: -1;
bottom: 0;
top: 0;
}
.menu ul {
padding: 0;
margin: 0;
color: #fff;
list-style: none;
font-weight: bold;
float: right;
}
.menu ul li {
display: inline-block;
padding-right: 50px;
}
.menu ul li a {
color: #fff;
}
<div class="container">
<nav class="menu">
<ul>
<li>HOME</li>
<li>ABOUT ME</li>
<li>SERVICES</li>
<li>CURRENT PROJECT</li>
<li>PORTFOLIO</li>
<li>CONTACT ME</li>
</ul>
</nav>
</div>

My navigation bar is vertical but won't go horizontal

I've been having trouble making my navigation bar for some reason. I've tried looking at if anything here answers it or going online but have had no luck. Am I missing something or is there a conflict?
html, body {
margin: 0;
padding: 0;
}
.container {
max-width: 940px;
margin: 0 auto;
padding: 0 10px;
}
.jumbotron {
background: url(../img/bg.jpg) no-repeat center center;
background-size: cover;
height: 800px;
}
.header {
background-color: #333;
}
.nav {
list-style-type: none;
margin: 0;
padding: 20px 0;
}
.nav li a {
color: #fff;
display: inline;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 12px;
margin-right: 25px;
text-transform: uppercase;
}
<div class="header">
<div class="container">
<ul class="nav" role="navigation">
<li>About</li>
<li>Photography</li>
<li>Programming</li>
<li>Writing</li>
<li>Reading</li>
<li>Contact</li>
</ul>
</div>
</div>
I made you a plunker as an example. You were very close. You just need to set the display property on the .nav li selector to inline-block.
.nav li {
display:inline-block;
}
The poster was actually looking for a Bootstrap solution but didn't have the question tagged as such. Here is a Bootstrap example. It just uses the pull-left class on each li tag.
<ul class="nav" role="navigation">
<li class="pull-left">About</li>
<li class="pull-left">Photography</li>
<li class="pull-left">Programming</li>
<li class="pull-left">Writing</li>
<li class="pull-left">Reading</li>
<li class="pull-left">Contact</li>
</ul>
In your CSS, try adding
.nav li {
display: inline;
}
Your li elements are naturally block displayed, so this should go ahead and remove the breaks from in between them.
See the fixed code snippet bellow. You need to add display: inline; to the li elements to make them go horizontal.
li {
display: inline;
}
html, body {
margin: 0;
padding: 0;
}
.container {
max-width: 940px;
margin: 0 auto;
padding: 0 10px;
}
.jumbotron {
background: url(../img/bg.jpg) no-repeat center center;
background-size: cover;
height: 800px;
}
.header {
background-color: #333;
}
.nav {
list-style-type: none;
margin: 0;
padding: 20px 0;
}
.nav li a {
color: #fff;
display: inline;
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 12px;
margin-right: 25px;
text-transform: uppercase;
}
<div class="header">
<div class="container">
<ul class="nav" role="navigation">
<li>About</li>
<li>Photography</li>
<li>Programming</li>
<li>Writing</li>
<li>Reading</li>
<li>Contact</li>
</ul>
</div>
</div>
Add the attribute .nav li with inline display.
.nav li{
display: inline;
}

css navbar hover drop down

I am looking to make a navbar menu that drops down when hovering over a specific navbar li.
My navbar looked and worked fine until I tried to get a hover drop down to work. Specifically this is what I am looking for:hover over "work" and get a drop down menu of "videos" and "photography". I don't think that I am nesting anything wrong, so I figure that it is the CSS that is wrong. I have tried a few different suggestions, but nothing has worked.
Side note: I recently gave the nav items the id of "menu". I had it so that the current page on the nav would be a certain darker color and when the current page nav was hovered it would stay that same color. This worked before I changed to id to "menu" (before it was "nav ul li"). Now when you hover, it changes the color. what made this change happen?
* {
padding: 0;
margin: 0;
}
ul, ol, dl {
padding: 0;
margin: 0;
}
ul#menu {
list-style: none;
text-align: center;
background-color: #bac9a9;
padding-top: 5px;
padding-bottom: 5px;
overflow: hidden;
}
ul#menu:after {
content:"";
background-image: url("../images/navbar-shadow-green.jpg");
height: 8px;
width: 100%;
display: block;
position: absolute;
left: 0;
margin-top: 4px;
}
ul#menu li {
display: inline;
}
ul#menu li a {
text-decoration: none;
color: #f3ffcf;
font-size: 22px;
padding: 10px 25px;
margin: 0 -2px;
}
ul#menu li a:hover {
background-color: #b2c1a2;
}
a.selected-page, a.selected-page:hover {
background-color: #a6b396;
}
li#sub ul {
display: none;
}
ul#menu li#sub:hover ul {
display: block;
}
<nav>
<ul id="menu">
<li>about
</li>
<li id="sub">work
</li>
<ul>
<li>videos
</li>
<li>photography
</li>
</ul>
<li>services
</li>
<li>contact
</li>
</ul>
</nav>
JSFiddle
I think you have got the nesting wrong. You want the list which is revealed when you roll over the work list item to be a child of that list item. Try updating your HTML / CSS as follows (see fiddle):
HTML:
<nav>
<ul id="menu">
<li>about
</li>
<li id="sub">
work
<ul>
<li>videos</li>
<li>photography</li>
</ul>
</li>
<li>services
</li>
<li>contact
</li>
</ul>
</nav>
CSS:
* {
padding: 0;
margin: 0;
}
ul, ol, dl {
padding: 0;
margin: 0;
}
ul#menu {
list-style: none;
text-align: center;
background-color: #bac9a9;
padding-top: 5px;
padding-bottom: 5px;
overflow: hidden;
}
ul#menu:after {
content:"";
background-image: url("../images/navbar-shadow-green.jpg");
height: 8px;
width: 100%;
display: block;
position: absolute;
left: 0;
margin-top: 4px;
}
ul#menu li {
display: inline;
}
ul#menu li a {
text-decoration: none;
color: #f3ffcf;
font-size: 22px;
padding: 10px 25px;
margin: 0 -2px;
}
ul#menu li a:hover {
background-color: #b2c1a2;
}
a.selected-page, a.selected-page:hover {
background-color: #a6b396;
}
li#sub ul {
display: none;
position: absolute;
top: 35px; left: 115px;
background-color: #b2c1a2;
}
li#sub ul li {
display: block;
}
ul#menu li#sub:hover ul {
display: block;
}

Why won't my unordered list centre properly?

It seemingly attempts to centre, but in actuality is a few pixels off. It's really annoying.
Picture: http://i.imgur.com/X4jhf.png
My code:
HTML:
<body>
<div class="menu-bar">
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Contact</li>
</ul>
</div>
<div class="greeting"></div>
</body>
CSS:
.menu-bar {
font-family: 'Lucida Grande';
}
.menu-bar ul {
text-align: center;
list-style-type: none;
}
.menu-bar li {
display: inline;
}
.greeting {
background: url('../media/pic.jpg');
border: 1px solid black;
margin-top: 75px;
margin-left: auto;
margin-right: auto;
width: 500px;
height: 375px;
}
Very frustrating. >_<
Margin and Padding both needs to be set to 0 unless you are using a css reset to avoid browser inconsistencies.
.menu-bar ul {
text-align: center;
list-style-type: none;
margin:0;
padding:0;
}
DEMO.
UL has a default left margin which you haven't dealt with. Just add margin: 0;