Can't get padding, margin, or line-spacing to work on any UL/LI/ or A tags in CSS.
Keep in mind, I have a CSS reset stylesheet setup before loading all other style sheets.
Here is my HTML:
<div class="h_logo"><img src="http://dummyimage.com/800x125/000/fff"></div>
<div class="h_navbar">
<nav>
<ul>
<li>Home</li>
<li>Web Design</li>
<li>Advertising</li>
<li>Publishing</li>
</ul>
</nav>
</div>
CSS:
.h_logo{
width:800px;
height:125px;
margin:auto;
display:block;
clear:both;
}
.h_nabar{
width:1000px;
height:125px;
padding:10px;
}
.h_navbar li{
list-style-type:none;
display:table-cell;
vertical-align:middle;
width:100px;
height:50px;
text-align:center;
}
.h_navbar ul{
display:table;
margin:auto;
}
.h_navbar a{
text-decoration:none;
display:table-cell;
border:2px double black;
font-size:18px;
}
JSFiddle
CSS
.h_logo{
width:800px;
height:125px;
margin:auto;
display:block;
clear:both;
}
.h_nabar{
width:1000px;
height:125px;
padding:10px;
}
.h_navbar li{
list-style-type:none;
display:inline-block;
vertical-align:middle;
width:120px;
height:50px;
text-align:center;
border:1px solid #111;
}
.h_navbar ul{
display:block;
margin:auto;
}
.h_navbar a{
text-decoration:none;
display:table-cell;
font-size:18px;
vertical-align:middle;
margin:15px;/*Adjust your margin here*/
width:120px;
height:50px;
}
HTML
Home
Web Design
Advertising
Publishing
Related
I am trying to create a fixed horizontal navigation that stretches to the browser's width.The problem I am having is that the links in the navigation bar move when i resize the browser window. How can I make it so that when you resize the web browser, the links(Home, Services...) stay fixed to the right and vertically in-line with the #content.?
Here is my html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
</head>
<body>
<!--Navigation-->
<div id="fixed_bar">
<div id="navigation">
<ul>
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
<!--Content-->
<div id="content">
<!--Content-->
</div>
</body>
</html>
And my CSS:
body {
background-color:yellow;
color:black;
width:100%;
padding:0;
margin-left:auto;
margin-right:auto;
font-size:16px;
font-family:"Sans-Serif", Helvetica, Arial;
}
/*Navigation*/
#navigation {
background-color:green;
color:black;
width:100%;
height:60px;
margin:0;
padding:0;
position:fixed;
top:0;
z-index:99;
}
#navigation ul {
list-style:none;
display:inline-block;
margin:0;
padding:0;
float:right;
overflow:hidden;
}
#navigation ul li{
padding:10px;
float:left;
clear:right;
}
#navigation ul li a{
background-color:inherit;
color:black;
vertical-align:middle;
text-decoration:none;
text-transform:uppercase;
font-size:15px;
font-family:"Lato", sans-serif;
letter-spacing:1px;
line-height:40px;
clear:both;
}
/*Content*/
#content {
padding-top:50px;
margin:auto;
width:900px;
color:black;
background-color:white;
}
I have been trying to solve this for hours, help would be much appreciated
You can apply your actual #navigation CSS rules to your #fixed_bar div and give #navigation the same width of the content (900px), let the browser calculate the margins with automatic margins and align the text to the right, so the ul will be at the right of #navigation while you keep the background, etc in #fixed_bar.
See it here: http://jsbin.com/bibulewa/1
And this is the CSS I've modified:
#fixed_bar {
background-color:green;
color:black;
width:100%;
height:60px;
margin:0;
padding:0;
position:fixed;
top:0;
z-index:99;
}
#navigation {
width: 900px;
text-align: right;
margin: auto;
}
Not sure if this is what you're looking for
I gave the ul an absolute position and align to the right:2%.
A top margin of 5px.
Remove the float and display the list as inline-block
Here's a jsfiddle - http://jsfiddle.net/rezasan/kE7LK/
/*Navigation*/
#navigation {
background-color:green;
color:black;
width:100%;
height:60px;
margin:0;
padding:0;
position:fixed;
top:0;
z-index:99;
}
#navigation ul {
list-style:none;
position:absolute;
right:2%;
display:inline-block;
margin:5px;
padding:0;
overflow:hidden;
width:60%;
text-align:right;
}
#navigation ul li{
padding:5px;
display:inline-block;
}
#navigation ul li a{
background-color:inherit;
color:black;
vertical-align:middle;
text-decoration:none;
text-transform:uppercase;
font-size:15px;
font-family:"Lato", sans-serif;
letter-spacing:1px;
line-height:3px;
clear:both;
}
set navigation styling:
left:0;
right:0;
html
<footer>
<div class="Footer_Container">
<div class="Footer_Rows">
<div class="span3" id="sspan1">
<h5>CONTACT</h5>
<ul>
<li>chris#pagemotion.com</li>
<li>(03) 013 3134114</li>
</ul>
</div><!--end of span-->
<div class="span3" id="sspan2">
<h5>FOLLOW</h5>
<ul>
<li>Facebook</li>
<li>Twitter</li>
</ul>
</div><!--end of span-->
<div class="span3" id="sspan3">
<h5>VISIT</h5>
<ul>
<li>6700 N New York Ave Suite 233 Portland, OR 97203</li>
</ul>
</div><!--end of span-->
<div class="span3" id="sspan4">
<img src="Image/mylogo.png" class="mylogo">
<!-- <img src="Image/rdio-icon.png" class="sg"> -->
</div><!--end of span-->
</div><!--end of FooterRows-->
</div><!--end of FooterContainer-->
css
footer{
width:100%;
height:100%;
min-height:150px;
padding:30px 0 80px;
color:#fff;
font-size:14px;
line-height:1.6;
background:#222;
position:relative;
}
.Footer_Container{
max-width:1080px;
width:86%;
min-height:150px;
padding-right:10px;
padding-left:10px;
margin:0px auto;
/*box-sizing:border-box;*/
display:block;
background-color:red;
}
.Footer_Rows{
margin-right:-10px;
margin-left:-10px;
padding:25px;
overflow:auto;
/*margin:0px auto;*/
}
.span3{
width:16%;
position:relative;
padding-right:30px;
padding-left:30px;
min-height:1px;
float:left;
font-size:14px;
color:#fff;
font-family:"colfax-web";
background-color:blue;
}
.span3 h5{
margin:0 0 10px;
font-size:16px;
font-style:normal;
}
.span3 ul{
margin:0;
padding:0;
list-style:none;
}
.span3 ul li{
display:list-item;
/*text-align:-webkit-match-parent;*/
box-sizing:border-box;
}
.span3 ul li a{
font-size:14px;
font-family:"colfax-web";
color:#fff;
text-decoration:none;
-webkit-trasition:all .2s ease-in-out;
transition:all .s2 ease-in-out;
}
#sspan1{
margin-left:10px;
}
#sspan4{
margin-left:10px;
}
.mylogo{
width:150px;
height:100px;
}
please copy and paste i cant put link here , i want to make this responsive , which will be 2 box on top , 2 box on bottom . but i have no idea how to make it can any one show me how ?
so is like this:
A B
C D
thank ~
Are you looking for something like this?
http://jsfiddle.net/62uzV/
.span3{
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
footer {
width:100%;
height:100%;
min-height:150px;
padding:30px 0 80px;
color:#fff;
font-size:14px;
line-height:1.6;
background:#222;
position:relative;
}
.Footer_Container {
max-width:1080px;
width:86%;
min-height:150px;
padding-right:10px;
padding-left:10px;
margin:0px auto;
/*box-sizing:border-box;*/
display:block;
background-color:red;
}
.Footer_Rows {
margin-right:-10px;
margin-left:-10px;
padding:25px;
overflow:auto;
/*margin:0px auto;*/
}
.span3 {
width:50%;
padding-right:30px;
padding-left:30px;
min-height:1px;
float:left;
font-size:14px;
color:#fff;
font-family:"colfax-web";
background-color:blue;
}
.span3 h5 {
margin:0 0 10px;
font-size:16px;
font-style:normal;
}
.span3 ul {
margin:0;
padding:0;
list-style:none;
}
.span3 ul li {
display:list-item;
/*text-align:-webkit-match-parent;*/
box-sizing:border-box;
}
.span3 ul li a {
font-size:14px;
font-family:"colfax-web";
color:#fff;
text-decoration:none;
-webkit-trasition:all .2s ease-in-out;
transition:all .s2 ease-in-out;
}
.mylogo {
width:150px;
height:100px;
}
I am building a navigation bar. This is what the HTML looks like
<div class="navhead">TEXT</div>
<div class="navcontainer">
<div class="button">TEXT</div>
<div class="button">TEXT</div>
<div class="button">TEXT</div>
<div class="button">TEXT</div>
<div class="button">TEXT</div>
</div>
And this is what the CSS looks like.
body {
margin:0px;
padding:0px;
font-family:"futura";
margin-top:75px;
height:100%;
width:100%;
}
.navcontainer {
width:100%;
position:fixed;
background-color:#FFF;
height:60px;
top:24px;
border:solid;
color:#000;
border-top:none;
border-bottom:solid;
border-left:none;
border-right:none;
margin:0px;
padding:0px;
}
.button {
width:20%;
height:60px;
float:left;
background-color:#FFF;
color:#000;
text-align:center;
vertical-align:central;
line-height:60px;
transition:background-color 1.5s ease;
margin:0px;
padding:0px;
}
.button:hover {
width:20%;
height:60px;
float:left;
background-color:#000;
color:#FFF;
text-align:center;
vertical-align:central;
line-height:60px;
margin:0px;
padding:0px;
}
.navhead {
width:100%;
color:#FFF;
background-color:#000;
position:fixed;
top:0px;
height:24px;
text-align:center;
font-size:9px;
line-height:24px;
}
The problem I am having is that the last button to the right isn't flush with the browser window. I don't really know what I'm doing wrong. I added everything I thought I needed to the "body" class, but still there's space... I mean, there's no space on top of it, just to the right of the last button.
jsfiddle here
This is a better way to structure your HTML and a more reliable way to create that menu: http://codepen.io/pageaffairs/pen/xaGuq
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body {
margin:0px;
padding:0px;
font-family:"futura";
margin-top:75px;
height:100%;
width:100%;
}
.navcontainer {
width:100%;
position:fixed;
background-color:#FFF;
top:24px;
border:solid;
color:#000;
border-top:none;
border-bottom:solid;
border-left:none;
border-right:none;
margin:0px;
padding:0px;
list-style: none;
display: table;
table-layout: fixed;
}
.navcontainer li {display: table-cell;}
.navcontainer li a {line-height: 60px;
background-color:#FFF;
color:#000;
text-align:center;
transition:background-color 1.5s ease;
display: block;
text-decoration: none;
}
.navcontainer li a:hover {
background-color:#000;
color:#FFF;
}
.navhead {
width:100%;
color:#FFF;
background-color:#000;
position:fixed;
top:0px;
height:24px;
text-align:center;
font-size:9px;
line-height:24px;
}
</style>
</head>
<body>
<div class="navhead">TEXT</div>
<ul class="navcontainer">
<li>
TEXT
</li>
<li>
TEXT
</li>
<li>
TEXT
</li>
<li>
TEXT
</li>
<li>
TEXT
</li>
</ul>
</body>
</html>
I am trying to vertically align the <a>'s inside my navigation divs, and it is for some reason not working. I've already checked that there are no other styles overriding my code, and several combinations of positioning.
<div id="logodiv">
<figure>
<img id="logo" src="/images/Capture2.jpg" alt="logo" />
</figure>
<nav id="flexbox">
<div class="menudiv"><a class="menua" href="gallery.html">Gallery</a></div>
<div class="menudiv"><a class="menua" href="events.html">Events</a></div>
<div class="menudiv"><a class="menua" href="default.html">Home</a></div>
<div class="menudiv"><a class="menua" href="membership.html">Info</a></div>
<div class="menudiv"><a class="menua" href="contactus.html">Contact</a></div>
</nav>
</div>
CSS
#logodiv {
width:100%;
height:100px;
position:relative;
display:block;
}
#flexbox{
background-color:#f5b00e;
float:right;
width:65%;
min-width:400px;
height:30px;
padding:0;
margin:0;
white-space:nowrap;
margin-bottom:0px;
position:absolute;
right:0px;
bottom:0px;
display:inline;
}
.menudiv{
width:20%;
height:100%;
line-height:100%;
display:inline;
float:left;
margin:0 auto;
padding:0;
vertical-align:middle;
position:relative;
}
.menua{
line-height:100%;
height:100%;
font-family: font, Arial, sans-serif;
font-size:15pt;
text-decoration:none;
text-shadow:none;
margin-top:10px;
vertical-align:bottom;
}
any help would be appreciated.
Check it http://jsfiddle.net/mKbLW/1/
Changed around some of your values. Had some unneeded css rules.
#logodiv {
width:100%;
height:100px;
position:relative;
display:block;
}
#flexbox{
background-color:#f5b00e;
float:right;
width:65%;
min-width:400px;
height:30px;
padding:0;
margin:0;
white-space:nowrap;
margin-bottom:0px;
position:absolute;
right:0px;
bottom:0px;
display:inline;
}
.menudiv{
width:20%;
height:100%;
float:left;
padding:0;
position:relative;
}
.menua {
height:100%;
line-height:30px;
display:inline;
font-family: font, Arial, sans-serif;
font-size:15pt;
text-decoration:none;
text-shadow:none;
margin-top:10px;
}
here is the code
http://jsfiddle.net/77NBM/12/
two grey squeares ("float 1" and "float 2") have to be positioned beside each other in absolute positioned division "submenu_container" related to < li > "menu 3".
Can plz somebody help me to get it? :(
Thx!
If you'll always have two elements ("float1 and float2") of 100px each, you can set the width of .submenu_container to 220px and they will float beside each other. like this http://jsfiddle.net/77NBM/13/
If the width of the elements ("float1 and float2") is dynamic, I suggest you set the width of .submenu_container dynamicly width javascript or jQuery. for example:
$('#main_menu li').each(function(index) {
var menuWidth=0;
$(this).children().children().each(function(index) {
menuWidth+=$(this).outerWidth();
}
$(this).children('.submenu_item').width(menuWidth)
});
The width of your submenu is being constrained by the width of your li element, just add some width to your submenu and they should float:left naturally
CSS
#top{
width:500px;
height:300px;
position:relative;
margin:0px auto;
background:#ccc;
}
#navigation{
position:absolute;
width:100%;
height:50px;
top:250px;
left:0px;
background:#f00
}
#main_menu{
width:auto;
height:50px;
margin-left: 0;
padding-left: 0;
list-style-type: none;
}
#main_menu li{
width:100px;
height:50px;
margin-right:10px;
float:left;
background:#ff0;
position:relative;
}
#main_menu li a{
display:block;
width:inherit;
height:inherit;
}
.submenu_container{
position:absolute;
background:#00f;
padding:5px;
left:-5px;
width:275px;
}
.submenu_item{
width:100px;
height:100px;
float:left;
background:#eee;
margin:5px;
}
http://jsfiddle.net/77NBM/17/
By the way, your html markup is full of errors, you need to take a look at that.
HTML
<div id="top" class="center">
<div id="navigation">
<ul id="main_menu">
<li>
Menu 1
</li>
<li>
Menu 2
</li>
<li>
Menu 3
<div class="submenu_container">
<div class="submenu_item">
Float 1
</div>
<div class="submenu_item">
Float 2
</div>
</div>
</li>
<li>
Menu 4
</li>
</ul>
</div>
</div>
#top{
width:500px;
height:300px;
position:relative;
margin:0px auto;
background:#ccc;
}
#navigation{
position:absolute;
width:100%;
height:50px;
top:250px;
left:0px;
background:#f00
}
#main_menu{
width:auto;
height:50px;
margin-left: 0;
padding-left: 0;
list-style-type: none;
}
#main_menu li{
width:100px;
height:50px;
margin-right:10px;
float:left;
background:#ff0;
}
#main_menu li a{
display:block;
width:inherit;
height:inherit;
}
.submenu_container{
width:auto;
position:absolute;
background:#00f;
padding:5px;
left:-5px;
}
.submenu_item{
width:100px;
height:100px;
float:left;
background:#eee;
margin:5px;
}