I have a list of items displayed horizontally. I want to create a border around each li, and have them jut up right next to each other.
I created a small test to illustrate the problem, seen here:
<ul class="dashboard_inline_links">
<li><a href="#">October - 0</a></li>
<li><a href="#">November - 0</a></li>
<li><a href="#">December - 765</a></li>
<li><a href="#">January - 0</a></li>
<li><a href="#">February - 756</a></li>
<li><a href="#">March - 2</a></li>
</ul>
.dashboard_inline_links li {
border-style: solid;
border-width: 1px;
display: inline;
padding: 4px 8px;
}
.dashboard_inline_links a {
border-color: transparent #C6D3F0;
border-style: solid;
border-width: 1px;
color: #28478E;
display: inline-block;
margin: 0;
padding: 0;
}
In short - there is white-space between the list items. I want them to jut up next to each other, and now I can only accomplish this by setting margin-left = -3px on the li items.
Any idea what is happening? I feel like I am missing something obvious!
As far as I could tell, you're setting the li
to be display: inline
, which means it will be treated like text in a paragraph. Hence, the white-space
between the elements becomes a space that you visually see.
This should demonstrate what I mean: http://jsfiddle.net/8F2XY/1/
Note, the following "resolves" the issue:
<ul class="dashboard_inline_links">
<li><a href="#">October - 0</a></li><li><a href="#">November - 0</a></li><li><a href="#">December - 765</a></li><li><a href="#">January - 0</a></li><li><a href="#">February - 756</a></li><li><a href="#">March - 2</a></li>
</ul>
http://jsfiddle.net/8F2XY/2/
It's the absence of whitespace between the li
s and betwen the li
s and a
s that fixes the code as-is.
Now, if you float: left
, the element will become like a display: block
element which will flow left in the display. Whitespace will be ignored.
So:
.dashboard_inline_links {
border-bottom: 1px dotted #C6D3F0;
border-top: 1px dotted #C6D3F0;
display: inline-block; overflow: hidden;
padding: 6px 0;
width: 916px;
margin-top: -5px;
padding: 6px 0;
position: relative;
white-space: nowrap;
}
.dashboard_inline_links li {
list-style-type: none;
border-style: solid;
border-width: 1px;
float: left;
padding: 4px 8px;
}
.dashboard_inline_links a {
border-color: transparent #C6D3F0;
border-style: solid;
border-width: 1px;
color: #28478E;
display: block;
margin: 0;
padding: 0;
}
http://jsfiddle.net/8F2XY/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With