0

Why is there a space before all these <li>'s Please Help.

HTML

<div class="links">
    <ul>
        <li><a href="page1.html">Page 1</a></li>
        <li><a href="page2.html">Page 2</a></li>
        <li><a href="page3.html">Page 3</a></li>
    </ul>
 </div>

CSS

.links ul{
    display: inline;
}
.links{
    display: block;
}
.links li{
    display: inline;
}
.links a{
    display: inline-block;
    width: 290px;
    text-align: center;
    padding-top: 10px;
    padding-bottom: 10px;
    border: 1px solid #000;
}

JS Fiddle: http://jsfiddle.net/jy4ojyyt/

Mackan
  • 6,031
  • 2
  • 23
  • 44
abaft
  • 152
  • 1
  • 12

2 Answers2

1

Inline-block elements render spaces between them. You can either put the li's on the same line or do some of your styling.

http://jsfiddle.net/jy4ojyyt/1/

<div class="links">
    <ul>
        <li><a href="page1.html">Page 1</a></li><li><a href="page2.html">Page 2</a></li><li><a href="page3.html">Page 3</a></li>
    </ul>
</div>
RyanS
  • 3,455
  • 1
  • 21
  • 36
-1

use Comments <!---->

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.links ul{
    display: inline;
}
.links{
    display: block;
}
.links li{
    display: inline;
}
.links a{
    display: inline-block;
    width: 290px;
    text-align: center;
    padding-top: 10px;
    padding-bottom: 10px;
    border: 1px solid #000;
}
<div class="links">
<ul>
    <li><a href="page1.html">Page 1</a></li><!--
--><li><a href="page2.html">Page 2</a></li><!--
--><li><a href="page3.html">Page 3</a></li>
</ul>
</div>

parent- font-size: 0; child - font-size - XXpx

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.links ul {
    display: inline;
}
.links {
    display: block;
    
}
.links li {
    display: inline;
    font-size: 0;
}
.links a {
    display: inline-block;
    width: 290px;
    text-align: center;
    padding-top: 10px;
    font-size: 16px;
    padding-bottom: 10px;
    border: 1px solid #000;
}
<div class="links">
    <ul>
        <li><a href="page1.html">Page 1</a>
        </li>
        <li><a href="page2.html">Page 2</a>
        </li>
        <li><a href="page3.html">Page 3</a>
        </li>
    </ul>
</div>
Dmitriy
  • 4,259
  • 3
  • 24
  • 32
  • The advantage of `` is that you can still have multiple lines. If you only use a single line, you can just remove the comments. – Oriol May 25 '15 at 19:34