Vertical dividers on horizontal UL menu - html

I'm trying to create a horizontal navigation bar (no dropdown, just a horizontal list), but I'm having trouble finding the best way to add vertical dividers between the menu items.
The actual HTML is as follows:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
The current CSS is as follows:
.menu li {
display: inline;
margin-left: 25px;
padding-left: 25px;
}
Between each menu item I want a small image as a vertical divider, except that I don't want a divider shown before the first item and I don't want a divider shown after the second item.
The end result should look something like this:
Item 1 | Item 2 | Item 3 | Item 4 | Item 5
Just replacing the pipe with an actual image.
I've tried different ways - I've tried setting the list-style-image property, but the image didn't show up. I've also tried setting the divider as a background which actually more or less worked except that it made the first item have a divider in front of it.

Quite and simple without any "having to specify the first element". CSS is more powerful than most think (e.g. the first-child:before is great!). But this is by far the cleanest and most proper way to do this, at least in my opinion it is.
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li:not(:first-child):before {
content: " | ";
}
Now just use a simple unordered list in HTML and it'll populate it for you. HTML should look like this:
<div id="navigation">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Support</li>
</ul>
</div><!-- navigation -->
The result will be just like this:
HOME | ABOUT US | SUPPORT
Now you can indefinitely expand and never have to worry about order, changing links, or your first entry. It's all automated and works great!

try this one, seeker:
li+li { border-left: 1px solid #000000 }
this will affect only adjecent li elements
found here

This can also be done via CSS:pseudo-classes. Support isn't quite as wide and the answer above gives you the same result, but it's pure CSS-y =)
.ULHMenu li { border-left: solid 2px black; }
.ULHMenu li:first-child { border: 0px; }
OR:
.ULHMenu li { border-right: solid 2px black; }
.ULHMenu li:last-child { border: 0px; }
See: http://www.quirksmode.org/css/firstchild.html
Or: http://www.w3schools.com/cssref/sel_firstchild.asp

I think your best shot is a border-left property that is assigned to each one of the lis except the first one (You would have to give the first one a class named first and explicitly remove the border for that).
Even if you are generating the <li> programmatically, assigning a first class should be easy.

A simpler solution would be to just add #navigation ul li~li { border-left: 1px solid #857D7A; }

.last { border-right: none
.last { border-right: none !important; }

This works fine for me:
NB I'm using BEM/OCSS SCSS Syntax
#navigation{
li{
&:after{
content: '|'; // use content for box-sizing
text-indent: -999999px; // Hide the content
display: block;
float: right; // Position
width: 1px;
height: 100%; // The 100% of parent (li)
background: black; // The color
margin: {
left: 5px;
right: 5px;
}
}
&:last-child{
&:after{
content: none;
}
}
}
}

I do it as Pekka says. Put an inline style on each <li>:
style="border-right: solid 1px #555; border-left: solid 1px #111;"
Take off first and last as appropriate.

Related

Creating a vertical line next to a list item

I want to put a little vertical line next to the right of each list item (except the last) but I'm wondering if there is a way to do it other than adding in a new div or something to accommodate the line. I tried just adding a border line for the list but it added one more than I needed.
html
<ul class="list">
<li><span id = "home">Home</span></li>
<li><span id = "about">About</span></li>
<li><span id = "portfolio">Portfolio</span></li>
<li><span id = "contact">Contact</span></li>
</ul>
CSS
.list li {
display: inline;
margin: 0px 25px 0px 0px;
white-space: nowrap;
font-family: Oswald;
color: white;
}
.list {
text-align: right;
padding-right: 2%;
}
#home {
height: 50px;
background-color: black;
}
Just add a right border to all the li elements and then remove it from the last one using the :last-child pseudo class. This will work for dynamic content.
Example Here
.list li {
display:inline-block;
border-right:2px solid;
padding:10px;
}
.list li:last-child {
border-right:none;
}
Alternatively, you could also just use the :not() pseudo class, and avoid applying the border to the last element to begin with.
Example Here
.list li:not(:last-child) {
border-right:2px solid;
}
Support for both of these methods can be found here - http://caniuse.com/#feat=css-sel3
If support is a concern, you could also alternatively just add a left border and remove it from the first child element. (:first-child has more browser support than :last-child/:not). I doubt you need to support older versions of IE though.
Example Here
.list li {
display:inline-block;
border-left:2px solid;
padding:10px;
}
.list li:first-child {
border-left:none;
}
You can achieve that by adding a border on every <li> item and just removing the border for the last element using the css last child selector: li:last-child selecting the last li element of its parent.
You can even combine that with the :not selector to achieve it with one css block.
JSFiddle Demo
I would probably set a border-right on the whole list and use jQuery to remove it on the last item.
This is a little trickier if you don't know the ID of the last item ahead of time, but if it's always going to be "Contact," you can say
$("#contact").attr('style','border-right:none');
You can add this:
li:before {
content: " | ";
}
li:first-child:before {
content: none;
}
Or:
li:not(:first-child):before {
content: " | ";
}
Here's a more universal and simpler solution that will work in older browsers without a hitch: http://jsfiddle.net/pw3vpvLv/.
HTML:
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
CSS:
ul > li {
display:inline-block;
padding: 5px 10px;
}
ul > li + li {
border-left: 1px solid;
}

Is it possible to choose a different shape instead of a circle for a HTML list without using an image?

Preferably looking for a triangle to replace the circle. I'd rather not use an image but I would if there was no other way.
JSFiddle of triangle bullets
Hopefully this is what you mean?
CSS:
.ul1 {
margin: 0.75em 0;
padding: 0 1em;
list-style: none;
}
.li1:before {
content: "";
border-color: transparent #111;
border-style: solid;
border-width: 0.35em 0 0.35em 0.45em;
display: block;
height: 0;
width: 0;
left: -1em;
top: 0.9em;
position: relative;
}
Yup. It's a bit of work though, if you want to use something other than circles or squares :)
See: http://alistapart.com/article/taminglists
The article I link to describes doing this by first stripping off the original markup:
ul.custom-list {
list-style: none;
margin-left: 0;
padding-left: 1em;
text-indent: -1em;
}
Then they add a custom bullet using the "before" pseudo-selector, and injecting content into that:
ul.custom-list li:before {
content: "\0BB \020";
}
In this case, they're using it to include the "double chevron" symbol. You can look up the symbol code for whatever you want to inject.
Yes you can use
list-style
style property for that.
If you want a simple (and painless) solution for a triangle in your unordered list, then you could use this method. I simply wrote a fiddle where the CSS gives you a UL list with each item marked with a right-pointing triangle instead of a round bullet.
Is this what you were after?
http://jsfiddle.net/CU5Ry/
HTML:
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
CSS:
ul {
list-style: none;
}
ul li:before {
content: "\25BA \0020";
}
Unfortunately there is no triangle available as a standard marker.
A full list of values for list-style-type can be found here.
Yes. Check this out. You can use CSS propriety as discribed here
http://www.w3schools.com/cssref/playit.asp?filename=playcss_ol_list-style-type&preval=cjk-ideographic

List-style goes away with inline-block - but I want my list decorators to stay

How do I get them to stay?
I have the following list - the moment I add to my list li display: inline-block; the custom list decorators I designated disappear.
Is there a CSS way of keeping my list decorators when the list is horizontal, or are list decorators only ever supposed to appear with vertical lists? Of course I could just have an image next to every list entry, but for simplicity's sake I'd rather deal with this in the CSS.
.first-page-menu-list {
list-style-image: url('../graphics/list-style-image.png');
list-style-position: inside;
text-transform: uppercase;
}
An alternate method consists of floating the li elements.
<ul>
<li>the item</li>
<li>the item</li>
<li>the item</li>
</ul>
ul {
overflow: auto; /* similar to clearing the floats... */
border: 1px solid gray;
}
ul li {
float: left;
border: 1px solid blue;
padding: 10px;
margin: 0 20px;
}
Demo fiddle: http://jsfiddle.net/audetwebdesign/kBNVz/
It seems that you're right but there's an easy fix for this, just use the background as long as you're not using it otherwise try this:
CSS:
.first-page-menu-list li {
background: url('../graphics/list-style-image.png') no-repeat 0px 4px;
display: inline;
text-transform: uppercase;
padding-left: 15px;
margin-left: 10px;
}
HTML:
<ul class="first-page-menu-list">
<li>asd</li>
<li>asdf </li>
<li> asdf</li>
</ul>
Play with the px values and you'll easy see what does which magic
Flexbox works well for this without the need to clear your floats.
ul.inline-list-style {
list-style: upper-roman;
display: flex;
}
ul.inline-list-style li {
flex: 1;
}

Move text baseline in <li> 2 px up

I have implemented my webpage menu by inline li-s of ul. li has a colored border and contains a. Now onmousehover I need to change color of the text inside a and move it 2px up by not moving the li border. How can I do that?
The trick is to remove the top padding a bit and increase the bottom padding a bit to maintain the markup integrity.
I have set up a simple example of what you want. Check it on the fiddle here
The HTML:
<ul>
<li>Home</li>
</ul>
The CSS:
ul { width: 200px; margin: 20px; }
li { border-top: 2px #000 solid; padding: 5px; }
li a { padding: 5px; display: inline-block; }
li:hover a { padding: 3px 5px 7px 5px ; }
Add this to your CSS:
a:hover.jump {
color: [Insert whatever];
position: relative;
bottom: 2px;
}
And then add a class to your link
<ul>
<li>My Link Text</li>
</ul>
You can add background colors or whatever else you need on the hovering text. The cliche-named but pretty useful website CSS Ninja has a bunch of examples

How can I do this menu using list and css?

I have a sort of menu like this one, but how you can see the code is not so "well".
I'd like that margin between word and border is always 5px for example, for every word.
I know I should use List for this kind of stuff, but I don't know how to apply css style with cross-browser compatibility.
Can you give to me an example of that menu with List?
This is how I'd do it:
See: http://jsfiddle.net/thirtydot/554BT/3/
<ul class="menu">
<li>Home</li>
<li>Incredible</li>
<li>One</li>
</ul>
.menu {
width:545px;
float:left;
margin: 0;
padding: 0;
list-style: none
}
.menu li {
float: left;
text-align: center;
padding: 0 15px;
border-left: 2px solid red
}
.menu li:first-child {
border: 0
}
This is the way I would do it, keeping it as easy (simple) as possible. It probably doesn't get any less complex than this:
HTML
<ul id="menu">
<li>Home</li>
<li>Incredible</li>
<li>One</li>
</ul>
CSS
#menu {
list-style-type: none;
}
#menu li {
display: inline-block;
padding: 0 10px;
border-left: 2px solid red;
}
#menu li:first-child {
border-left: none;
}
DEMO: jsfiddle
Check out Listmatic for examples of all the basic list layouts.
Looks like you want something like this one.
Try this...
fiddle:http://jsfiddle.net/anish/Laqqn/
<style type="text/css">
.menu
{
width:500px;
}
.menu li
{
width:100px;
text-align:center;
float:left;
border-right:1px solid red;
}
</style>
<ul class="menu">
<li>Home</li>
<li>Incredible</li>
<li>One</li>
</ul>
A CSS3 example, not really cross browser as it uses CSS3 pseudo-selectors
CSS3 List menu
This other example uses a pipe character to separate the links and is cross browser safe:
CSS2 List menu
Space between the borders do this =
Put a border on the right side of the li and the second button put a border on the left side of the li.
Now add margin-left (or margin-right) and see it expand.
This worked in my case.
Good luck.