本文介绍了为什么我的李元素之间有空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水平显示的项目列表。

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;
}

简而言之,列表项之间有空格。我想让他们彼此相邻,现在我只能通过设置margin-left = -3px在li项目。

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!

推荐答案

据我所知, c> li 为 display:inline ,这意味着它将像段落中的文本一样处理。因此,元素之间的白色空格变成你可以看到的空间。

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.

意思:

请注意,以下解决问题:

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>

这是 li之间没有空白 s和 li s和 a 之间修改代码。

It's the absence of whitespace between the lis and betwen the lis and as that fixes the code as-is.

现在,如果你 float:left ,这个元素将变成一个 display: / code>元素将流向左边的显示。空格将被忽略。

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.

因此:

.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;
}

这篇关于为什么我的李元素之间有空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:09