Mr.Smithyyy
Mr.Smithyyy

Reputation: 1329

How can I add horizontal lines between horizontal list items?

ul {
    float: left;
    width: 100%;
    padding: 0;
    margin: 0;
    list-style-type: none;
}

a {
    float: left;
    width: 6em;
    text-decoration: none;
    color: white;
    background-color: purple;
    padding: 0.2em 0.6em;
    margin: 0em 2em;

    border-right: 1px solid white;
}

a:hover {
    background-color: fuchsia;
}

li {
    display: inline;
}
<ul>
<li><a href="#">Link one</a></li>
<li><a href="#">Link two</a></li>
<li><a href="#">Link three</a></li>
<li><a href="#">Link four</a></li>
</ul>

I am wondering if there is a way to accomplish what I have in that picture, with code. Not the borders or text but the lines in between the menu items. I have tried a few ways including making a div but I can't seem to get the styling right. If anybody has a solution they've used before I would love to hear it. Thank you in advance for any help.

enter image description here

Upvotes: 1

Views: 8771

Answers (3)

Leandroc
Leandroc

Reputation: 75

In case of table, you have to do it in a different way. Here's the how. (as you did not specify what you were looking for)

http://jsfiddle.net/3ndwnohn/1/

table tr td {
    padding: 10px;
    border: 1px solid #444;
}
td.space {
    padding:10px;
    border: 0;
}
td.space::before {
    position: absolute;
    margin-left: -12px;
    height: 1px;
    width: 25px;
    background-color: #444;
    content: ' ';
}
<table>
    <tr>
        <td>numberOne</td>
        <td class="space"></td>
        <td>numberTwo</td>
        <td class="space"></td>
        <td>numberThree</td>
    </tr>
</table>

Upvotes: 0

Weafs.py
Weafs.py

Reputation: 23002

You could use :after :pseudo-element to add the line. To filter out the last div you could use #container .box:not(:last-child) selector, which will select all .boxes but the last one.

.box {
  position: relative;
  width: 50px;
  text-align: center;
  display: inline-block;
  border: 2px solid black;
  padding: 2px 5px 2px 5px;
}
#container .box:not(:last-child) {
  margin-right: 25px;
}
#container .box:not(:last-child):after {
  position: absolute;
  content: '';
  right: -50%;
  top: 0%;
  width: 50%;
  height: 50%;
  border-bottom: 2px solid black;
}
<div id="container">
  <div class="box">Link 1</div>
  <div class="box">Link 2</div>
  <div class="box">Link 3</div>
</div>

Upvotes: 4

Johan Karlsson
Johan Karlsson

Reputation: 6476

You could do something like this:

HTML:

<div class="menu-item">LINK 1</div>
<div class="menu-line"></div>
<div class="menu-item">LINK 2</div>
<div class="menu-line"></div>
<div class="menu-item">LINK 3</div>

CSS:

.menu-item, .menu-line {
    width: 80px;
    height: 20px;
    border: 1px solid black;
    float: left;
    text-align: center;
}
.menu-line {
    width: 25px;
    height: 0px;
    margin-top: 9px;
}

DEMO: http://jsfiddle.net/vqm7oawq/

Upvotes: 0

Related Questions