I am styling a ul so that I can make a menu that sits on the left side. They will basically be square boxes with icons (using ionicons). The only problem I run into is, I can't get a perfect square and cannot center the icons. Here is what I have now.
.menu_simple ul {
margin: 0;
padding: 100px 0 0 0;
width:185px;
list-style-type: none;
position: fixed;
font-size: 60px;
}
.menu_simple ul li a {
text-decoration: none;
color: white;
padding: 10.5px 60px;
background-color: #F0541E;
display:block; width: 120px; height: 120px;
vertical-align: middle;
}
.menu_simple ul li a:visited {
color: white;
}
.menu_simple ul li a:hover, .menu_simple ul li .current {
color: white;
background-color: #d84b1b
;
}
Also, the html I am currently using looks is this:
<div class="menu_simple">
<ul>
<li><i class="ion-ios-person-outline" style="color:#FFFFFF;" href="#"></i></li>
<li><a class="ion-ios-baseball-outline" style="color:#FFFFFF;" href="#"></a></li>
<li><a class="ion-ios-calendar-outline" style="color:#FFFFFF;" href="#"></a></li>
<li><a class="ion-ios-plus" style="color:#FFFFFF;" href="#"></a></li>
<li><a class="ion-log-out" style="color:#FFFFFF;" href="#">a</a></li>
</ul>
</div>
It currently looks like this:
Thanks everyone. After a little research, this ended up working for me:
.menu_simple ul {
margin: 0;
padding: 100px 0 0 0;
width:185px;
list-style-type: none;
position: fixed;
font-size: 60px;
}
.menu_simple ul li a {
color: #FFF;
padding: 0px;
margin: 0px;
background-color: #F0541E;
display: block;
width: 120px;
height: 120px;
vertical-align: middle;
display: table-cell;
text-align: center;
}
Unless you have removed it with a normalize.css reset or something similar you will need to set padding and margin to zero for your li's in your css. By default li elements in an unordered or ordered list get some left margin to set them apart from their parent ul.
Related
Been trying to get this to work for a while now. I'm trying to create the menu for my new site, Ive set up the nav, ul, and li tags. Naturally, I have the actual buttons slightly larger than the text displaying, and I wish to have the A fill out the LI tag.
nav {
width: 100%;
min-width: 800px;
background-color: #EDEDED;
}
nav a {
color: #000;
text-decoration: none;
display: block;
height: 100%;
width: 100%;
}
nav ul {
list-style: none;
margin: auto auto auto 10vw;
height: 2em;
display: block;
}
nav ul li {
display: inline-block;
background-color: #DEDEDE;
vertical-align: middle;
padding: 0 50px 0 50px;
height: 2em;
line-height: 2em;
}
nav ul li:hover {
background-color: #FF0000;
}
<nav>
<ul>
<li><a href='index.php'>Home</a>
</li>
<li><a href='index.php'>Home</a>
</li>
<li><a href='index.php'>Home</a>
</li>
</ul>
</nav>
I feel like ive tried everything in:
How do I make an <a> tag the size of it's parent <li> tag for larger clickable region?
Stretching <a> tag to fill entire <li>
Expand an <a> tag to fill the space
and I really feel like my code should give the same result. Can someone please point out what mistake I've made?
You had the right idea by adding display:block on the anchors, however the padding on your list item was affecting the result. Move that padding onto the anchors and you're all set.
nav {
width: 100%;
min-width: 800px;
background-color: #EDEDED;
}
nav a {
color: #000;
text-decoration: none;
height: 100%;
width: 100%;
display: block;
padding: 0 50px 0 50px;
box-sizing:border-box;
}
nav ul {
list-style: none;
margin: auto auto auto 10vw;
height: 2em;
display: block;
}
nav ul li {
display: inline-block;
background-color: #DEDEDE;
vertical-align: middle;
height: 2em;
line-height: 2em;
}
nav ul li:hover {
background-color: #FF0000;
}
<nav>
<ul>
<li><a href='index.php'>Home</a>
</li>
<li><a href='index.php'>Home</a>
</li>
<li><a href='index.php'>Home</a>
</li>
</ul>
</nav>
Remove the padding from the ul li:
nav ul li {padding:0px;}
If necessary add it to the nav ul li a:
nav ul li a {padding:0px 50px;}
i am trying to make a responsive navigation bar with these 4 elements. however, if i drag the browserwindow to a certrain point it starts placing one of the 4 below the rest. but i dont know what i'm doing wrong.
The HTML:
<div id="nav">
<ul>
<li class="blue">Home</li>
<li class="blue">Trailer</li>
<li class="red">Gallery</li>
<li clas="red">Contact Us</li>
</ul>
</div>
The CSS:
#nav {
width: 100%;
background-color:transparant;
}
#nav ul {
width: 85%;
max-width: 1200px;
padding: 0;
margin: 0 auto;
list-style: none;
text-align: center;
}
#nav ul li {
display: inline-table;
width: 24%;
padding: 4px;
background-color:#242424;
border-radius: 5px;
}
#nav ul li a {
color:white;
text-decoration: none;
width: 100%;
padding-top: 10px;
padding-bottom: 10px;
display: inline-block;
border-radius: 5px;
}
You are maybe having problems with your padding.
For that, add the box-sizing property in your lis and the padding will be included in the width of the element, like:
#nav ul li {
display: inline-table;
width: 24%;
padding: 4px;
background-color:#242424;
border-radius: 5px;
box-sizing: border-box;
}
Fiddle: http://jsfiddle.net/begyu5v3/
Info: http://www.w3schools.com/cssref/css3_pr_box-sizing.asp
And there's those undesirable white spaces between your lis. In this link, there are some ways to avoid this problem, like font-size:
#nav ul {
font-size: 0;
}
#nav ul li {
font-size: 16px;
}
Give it a try and let me know if it helps!
Here's the HTML :
<nav>
<ul class="menu">
<li class="li_pc">PC</li>
<li class="li_one">ONE</li>
<li class="li_ps3">PS4</li>
<li class="li_360">360</li>
<li class="li_ps3">PS3</li>
<li class="li_wiiu">WiiU</li>
</ul>
</nav>
and here's the CSS :
nav {
padding: 0;
margin: 0;
widht: 1200px;
height: 100px;
}
ul li {
display: inline;
font-family: Verdana, Geneva, sans-serif;
float: left; /* IE */
list-style-type: none;
}
ul li a {
display: block;
float: left;
width: 190px;
height: 60px;
padding: 0;
background-color: transparent;
color: white;
text-decoration: none;
text-align: center;
}
.li_pc a:hover {
background-color: #cc9a34;
}
.li_one a:hover {
background-color: #149a14;
}
.li_ps4 a:hover {
background-color: #040264;
}
.li_360 a:hover {
background-color: #9cce04;
}
.li_ps3 a:hover {
background-color: #0406b4;
}
.li_wiiu a:hover {
background-color: #5c12ac;
}
My goal is to vertically center the text in the cells. I'm using text-align:center; to center it horizontally, but when I use vertical-align:middle; it doesn't even move a pixel. I tried a lot of different ways but it always destroys the thing and makes the design look like my face on sunday morning.
How can I center these vertically please ?
Thanks in advance :)
If you anchor links are 60px tall
line-height:60px
should do it.
JSFiddle
Take a look at this website I am working on: new.AudioManiacProductions.com
A screenshot from Dreamweaver showing the divs can be found here: new.AudioManiacProductions.com/images/stack.png
Notice how to navigation bar is not centered and the "home" has an intent on the left side.
I want the nav bar to stretch the whole span of it's parent container and be centered both vertically and horizontally.
Here's my CSS for the navigation section of the page, the nav list item, and the links.
#nav {
width: 100%;
height: 40px;
margin: 0 auto;
padding: 0px;
text-align: center;
color: #FFF;
list-style: none;
line-height: auto;
verticle-align: middle;
}
#nav li {
padding: 0px;
display: block;
width: 20%;
list-style-type: none;
float: left;
text-align: center;
overflow: hidden;
line-height: auto;
verticle-align: middle;
}
#nav li a {
font-size: 18px;
font-weight: 600px;
text-decoration: none;
font-weight:800;
color:#FFF;
}
#nav li a:hover, a:visited {
color: #00F;
}
And here is my HTML:
<div id="nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Packages</li>
<li>Quote</li>
<li>Contact Us</li>
</ul>
</div>
Any help is greatly appreciated!
Browsers set padding-left by default on UL tags. Remove the padding and that should help out.
#nav ul {
padding-left: 0;
}
or just clear all padding:
#nav ul {
padding: 0;
}
I've got a list here for my page's footer, that I want displayed horizontally.
But because I've turned it into an inline list to go horizontally, the background images get cut off vertically. The biggest one is 27px high.
So I'm stuck.. I know why the following is doing what it's doing. But how do I get around it?
Here's the html:
<div id="footer">
<ul>
<li id="footer-tmdb">Film data courtesy of TMDB</li>
<li id="footer-email">Contact Us</li>
<li id="footer-twitter">Follow Us</li>
</ul>
</div>
and the CSS:
#footer ul {
height: 27px;
}
#footer ul li {
display: inline;
list-style: none;
margin-right: 20px;
}
#footer-tmdb {
background: url('../images/logo-tmdb.png') no-repeat 0 0;
padding-left: 140px;
}
#footer-email {
background: url('../images/icon-email.png') no-repeat 0 3px;
padding-left: 40px;
}
#footer-twitter {
background: url('../images/icon-twitter.png') no-repeat 0 0;
padding-left: 49px;
}
Here's what it looks like:
As you can see, half of the images are cut off.
The simpler the solution, the better, please.
#footer ul li {
display: block;
float: left;
height: 27px;
list-style: none;
margin-right: 20px;
}
Use inline-block
#footer li {
height: 27px;
display: inline-block;
}
Try this:
#footer ul {
overflow: auto
}
#footer ul li {
display: block;
list-style: none;
margin-right: 20px;
float: left;
}
Try this:
#footer li,
#footer ul {
height: 27px;
}