Add a pipe separator after items in an unordered list unless that item is the last on a line
This is possible with flex-box
The keys to this technique:
- A container element set to
overflow: hidden
. - Set
justify-content: space-between
on theul
(which is a flex-box) to force its flex-items to stretch to the left and right edges. - Set
margin-left: -1px
on theul
to cause its left edge to overflow the container. - Set
border-left: 1px
on theli
flex-items.
The container acts as a mask hiding the borders of any flex-items touching its left edge.
.flex-list {
position: relative;
margin: 1em;
overflow: hidden;
}
.flex-list ul {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
margin-left: -1px;
}
.flex-list li {
flex-grow: 1;
flex-basis: auto;
margin: .25em 0;
padding: 0 1em;
text-align: center;
border-left: 1px solid #ccc;
background-color: #fff;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css" rel="stylesheet"/>
<div class="flex-list">
<ul>
<li>Dogs</li>
<li>Cats</li>
<li>Lions</li>
<li>Tigers</li>
<li>Zebras</li>
<li>Giraffes</li>
<li>Bears</li>
<li>Hippopotamuses</li>
<li>Antelopes</li>
<li>Unicorns</li>
<li>Seagulls</li>
</ul>
</div>
What is the proper way to put divider lines between navigation links?
Pipe characters work, but you could do the same thing with some CSS.
If your markup is like this:
<nav>
<a href="/about.html">About</a>
<a href="/portfolio.html">Portfolio</a>
<a href="/contact.html">Contact</a>
</nav>
You can add some CSS to style the "right side" of each link element to have a border, except for the last element because you don't want a floating divider line on the end of the links.
nav > a {
border-right: solid 1px #eff0f1;
}
nav > a:last-of-type {
border-right: none;
}
This will add a border to the right side of all your nav links, but then overrides the final nav link to not have a right border.
Separators for Navigation
Simply use the separator image as a background image on the li
.
To get it to only appear in between list items, position the image to the left of the li
, but not on the first one.
For example:
#nav li + li {
background:url('seperator.gif') no-repeat top left;
padding-left: 10px
}
This CSS adds the image to every list item that follows another list item - in other words all of them but the first.
NB. Be aware the adjacent selector (li + li) doesn't work in IE6, so you will have to just add the background image to the conventional li (with a conditional stylesheet) and perhaps apply a negative margin to one of the edges.
Responsive Separator for Horizontal List
You can exploit fact that trailing and line trailing white space automatically collapses:
document.write(
'word<b style="background: red; outline: 1px solid blue;"> </b>'
.repeat(42)
);
How to hide last | with CSS?
You are doing it wrong. Here is the correct answer:
#menu-footer-menu li:last-child .f_sep{ display:none }
How to style the vertical bar i.e. | ?
Put it in an element, and style the element:
<span class="bar">|</span>
In your style sheet, for example:
.bar { font-size: 20px; }
Related Topics
How to Apply an Opacity Without Affecting a Child Element with HTML/Css
Fill Remaining Vertical Space - Only CSS
With a Browser, How to Know Which Decimal Separator Does the Operating System Use
CSS Only Animate Draw Circle with Border-Radius and Transparent Background
Restrict Future Dates in HTML5 Date Input
Declare Variable in a Play2 Scala Template
Options with Display:None Not Hidden in Ie
How to Get a Web Page Header/Footer Printed on Every Page
How to Choose Between Get and Post Methods in HTML Forms
Does a Name Attribute Have to Be Unique in a HTML Document
How Do Browsers Calculate Width When Child Depends on Parent, and Parent's Depends on Child'S
How to Flatten Nested Divs to Display Them in a CSS Grid
Why Use Schema.Org Microdata to Mark Up Web Page Elements
Why Are Some of My CSS Rules Not Working
How to Make a Textarea 100% Width Without Overflowing When Padding Is Present in CSS
How to Remove/Ignore :Hover CSS Style on Touch Devices
How to Prevent the Padding Property from Changing Width or Height in CSS