I'm wondering what some good practices are for styling li elements like buttons. Any examples would be appreciated. I'm guessing a box shadow and a background color would go a long way, but that alone does not seem to be enough.
Edited the question to make it more useful.
Okay I think what your after is to make the whole link clickable rather than just the text. All you need to do is make your anchor a block element, then it will take the full width of the li:
.nav a {
display:block;
}
<ul class="nav">
<li>Home</li>
<li>About us</li>
</ul>
I assume you try to make menu and want bigger buttons than just link text.
You should set links inside list elements as you shown and then make links as buttons.
Very simple css example for horizontal menu would be something like this:
.nav li {
list-style-type: none;
padding 0px;
margin 0px;
float: left;
}
.nav li a {
text-decoration: none;
display: block;
padding: 0px 15px;
line-height: 25px;
}
For horizontal menu you should make width with padding and height with line-height. Unless you want every button to be same sized, then you just could use width.
More in-depth example would be this one http://medialoot.com/blog/how-to-create-a-responsive-navigation-menu-using-only-css/
I think your issue may be that you have styled the <li> to look like the menu button, but the text is the only part that is clickable, is this correct?
What you need to do, is not style the <li> as the menu button but instead the <a> within it.
Here is a demo: https://jsfiddle.net/arrx7dL7/
As you can see the styles are applied to the links, rather than the li
HTML:
<ul class="menu">
<li><a class="menu-item" href="#">Item 1</a></li>
<li><a class="menu-item" href="#">Item 2</a></li>
<li><a class="menu-item" href="#">Item 3</a></li>
<li><a class="menu-item" href="#">Item 4</a></li>
</ul>
CSS:
.menu {
list-style:none;
}
.menu-item {
color:black;
text-decoration: none;
background: #eee;
border: 1px solid #ccc;
padding:20px 30px;
display:block;
}
I think this is what you mean, if so I hope it is helpful.
Related
I have the following code: https://jsfiddle.net/u8db2j75/1/ and it works fine, I have the effect I wanted - a picture and some text next to it. But now I want to add another component, a navigation bar - and I want to add it on top of the page. So what I followed the example given here http://css-snippets.com/simple-horizontal-navigation/ and I created the code like this:
<div class="nav">
<ul>
<li class="home">Home</li>
<li class="tutorials"><a class="active" href="#">Tutorials</a></li>
<li class="about">About</li>
<li class="news">Newsletter</li>
<li class="contact">Contact</li>
</ul>
</div>
https://jsfiddle.net/u8db2j75/2/ however, after modifying css as well -as you can see - the effect is far from what I expected... What did go wrong here?
Give your .nav ul and .nav a min-width of 100%.
Example:
.nav {
min-width:100% !important;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
position: absolute;
top: 0;
padding: 0;
margin: 0;
min-width: 100%;
}
https://jsfiddle.net/u8db2j75/4/
I don't have 50 reputation to comment the answer above, but:
List item needs to be displayed inline, or floated to the left so the result will be a horizontal navigation as per the examble shown in the issue.
Here's my code:
jsfiddle.net/q49hb
<ul id="navigation">
<li><a class="" href="#">Home</a></li>
<li><a class="" href="#">Blog</a></li>
<li><a class="" href="#">Services</a></li>
<li><a class="" href="#">About</a></li>
</ul>
There's a little caret cursor in between each list item when hovering over. I noticed floating to the left will get rid of it, but then I can't center the navigation, which I am also trying to do. Any help?
So to re-cap, I'm looking to:
Space out the list items, leaving no excess space.
Not show a carrot cursor when hovering in between the items.
Centering the unordered list nav on the page.
None of the answers above are correct or even close. You need users to know what is clickable and what isn't. The caret is in fact misleading and distracting between list items. This is bad UX. You cannot blitz the ul with cursor: pointer; then everything will seem clickable, even bewteen li's.
reset the entire ul's clickable area (even between list items)
ul{
cursor:default;
}
Now define what is clickable.
ul li{
cursor:pointer;
}
You can do one of two things.
You can set the parent element (#navigation) so cursor: pointer; which will stop the caret from showing in between links:
http://jsfiddle.net/q49hb/1/
#navigation {
cursor: pointer;
}
Or you can remove the whitespace between the <li>s, which is what's causing the default caret cursor type to show.
http://jsfiddle.net/q49hb/2/
<li><a class="" href="#">Home</a></li><li><a class="" href="#">Blog</a></li><li><a class="" href="#">Services</a></li><li><a class="" href="#">About</a></li>
EDIT: Option 2 is better, (but the code isn't very neat,) because Option 1 gives users the illusion that the space is clickable when it isn't (thanks #JoshC)
you can set a minus margin-left to force the LI to be together and a set a width for the anchors:
demo
#navigation li {
display: inline;
margin-left: -4px;
}
#navigation a{
width: 60px;
display: inline-block;
}
I have a menu which can be seen in the link below:
http://fiddle.jshell.net/V88c6/8/show/
Here is the full jsfiddle
http://jsfiddle.net/V88c6/8/
Here is the HTML
<div id="head_1">
<div class="inner">
<div class="column_0">
LOGO
</div>
<div class="column_1">
LINK 1
LINK 2
LINK 3
LINK 4
</div>
<div class="column_2">
<span>USER NAME</span> LOGOUT
</div>
<div class="clearfix"></div>
</div>
</div>
For some reason the LOGOUT link's top border on hover seems to be a pixel higher then the rest of the links. This happened when I added some css reset script.
Here is a link of the same page without the css reset where the LOGOUT link works fine:
http://fiddle.jshell.net/V88c6/9/show/
I like to use the css reset script to help the page look similar on most popular browsers.
Anyone know why the css reset script would be interfering with the LOGOUT link only?
Tested on IE7, IE8, Latest Google Chrome, latest Firefox, Latest Opera.
You are trying to style it the bad way. Try styling it like this - whit li ul:
<div class="column_1">
<ul class="menu_link">
<li><a href="#" >LINK 1</a></li>
<li><a href="#" >LINK 2</a></li>
<li><a href="#" >LINK 3</a></li>
<li><a href="#" >LINK 4</a></li>
<ul>
</div>
<div class="column_2">
<ul class="menu_link">
<li>username</li>
<li><a href="#" >LINK 4</a></li>
<ul>
</div>
and these are the selectors:
.menu_link li{}
.menu_link li a{}
you can try this one also
#head_1 .inner .column_2 {
display: block;
float: right;
padding: 0 15px;
}
#head_1 .inner .column_2 .menu_link {
border-top: 17px solid transparent;
padding: 17px 15px 10px 15px;
display: inline-block;}
The problem has to do with the computed value for the display property.
Your middle column with "LINK 1" and so on shows .menu-link with float: left, which causes the <a> elements to be block instead of inline.
You "LOGOUT" link shows .menu-link with no float, so the <a> element is inline.
The inline element affects the height of its inline box differently from a block element.
There was some style property in your browser's default style sheet that was masking this effect, and when you used a reset CSS style sheet, it appears.
The fix would be to layout out the two elements on the right (User Name and Logout) as floated element or to tweak the margin or line height by 1-2 px (involves trial and error, groaning).
The Fix
I was able to get a consistent layout by doing the following by adjusting your CSS as follows:
#head_1 .inner .column_2 {
display:block;
float:right;
/* padding:34px 0px 10px 15px; Remove this... */
}
#head_1 .inner .column_2 .menu_link{
border-top:17px solid transparent;
padding:17px 15px 10px 15px;
float: left; /* add this.. */
}
/* Float your span like you floated the link... */
#head_1 .inner .column_2 span {
border-top:17px solid transparent;
padding:17px 15px 10px 15px;
float: left;
}
Fiddle: http://jsfiddle.net/audetwebdesign/Myhcy/
The key is to keep a consistent coding style in laying out your two menus.
I've stumbled upon a problem here. I created a menubar which consists several clickable parallelogram menu-items with list and link tags.
Unfortunately, the menubar is showing a problem now. Whenever I try to hover the overlapping part of menu-item, it will automatically choose the next-right menu-item. For example, when I tried to click the pointy part of HOME (which is overlapping with menu-item ABOUT), the menu-item ABOUT would be chosen instead.
I want all of area of each menu-item clickable respectively without any interference from neighboring menu-items. Any helps and suggestions please?
http://i.stack.imgur.com/NDKNF.png
http://i.stack.imgur.com/gnhzt.png
Here's the HTML code:
<ul class="header" id="navlist">
<li id="home"></li>
<li id="about"></li>
<li id="benchmark"></li>
<li id="service"></li>
<li id="work"></li>
<li id="client"></li>
<li id="contact"></li>
</ul>
Here's the CSS:
#navlist {
position:relative;
}
#navlist li {
margin:0;padding:0;list-style:none;position:absolute;top:0;
}
#navlist li,
#navlist a {
height:31px;display:block;
}
#home {
left:0px;
width:112px;
background:URL('../headbar/navmap.png') 0px 0px;
}
#home a:hover {
background:URL('../headbar/navmap.png') 0px -31px;
}
and for another menu-item such as about, client, and others follow the same rule as home.
i'm trying to create a horizontal navigation which is aligned to the right side of the parent element. You can see the navigation at http://kaffeeprinzen.jag-aelskar.de/ where it says "Espresso".
My HTML is:
<ul id="menu-standard">
<li id="menu-item"><a>Item 4</a></li>
<li id="menu-item"><a>Item 3</a></li>
<li id="menu-item"><a>Item 2</a></li>
<li id="menu-item"><a>Item 1</a></li>
</ul>
My CSS is:
.menu li {
float: right;
margin-left: 20px;
}
It works like this, the only problem is that the order in the list is wrong. The first item is the last one in the html code.
Any tips for me? Thanks a lot!
Yannis
Try floating the ul right rather than each li. Each li can float left.
#menu-standard {
float: right;
}
#menu-standard li {
float: left;
}
Example: http://jsfiddle.net/hunter/HsUTQ/
float: right will float the items, in order, to the right. Meaning the 1st element will be the right-most, then 2nd element the next-right-most, etc.