CSS ‘word-spacing’属性不正常工作。

huangapple go评论54阅读模式
英文:

CSS 'word-spacing' property not working properly

问题

我有一个无序列表,其中包含我想要均匀分布的列表项,但元素之间的间距不均匀。

<footer>
    <ul class="footer">
        <li><a href="about">Name&copy;2023</a></li>
        <li><a href="legal">Privacy&Legal</a></li>
        <li><a href="vin-recall-search">Vehicle Recalls</a></li>
        <li><a href="contact">Contact</a></li>
        <li><a href="blog">News</a></li>
        <li><a href="updates">Get Updates</a></li>
        <li><a href="findus/list">Locations</a></li>
    </ul>
</footer>

在CSS文件中:

footer li{
    word-spacing:20px;
    display:inline-block;
}

项目之间的单词间距不均匀。
它看起来像这样:
CSS ‘word-spacing’属性不正常工作。

英文:

I have an unordered list with list items that I want to spread evenly from each other but the elements don't spread evenly.

&lt;footer&gt;
    &lt;ul class=&quot;footer&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;about&quot;&gt;Name&#169;2023&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;legal&quot;&gt;Privacy&amp;Legal&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;vin-recall-search&quot;&gt;Vehicle Recalls&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;contact&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;blog&quot;&gt;News&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;updates&quot;&gt;Get Updates&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;findus/list&quot;&gt;Locations&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/footer&gt;

In the CSS file:

footer li{
    word-spacing:20px;
    display:inline-block;
}

The word spacing between the items isn't identical.
it looks like this
CSS ‘word-spacing’属性不正常工作。

答案1

得分: 0

这是因为您在li元素上使用了间距,而不是在ul元素上。

您需要像下面这样更改您的CSS。

footer li{
    display:inline-block;
    word-spacing: normal;
}

footer ul{
    word-spacing:20px;
}
英文:

That's because you use the spacing on the li elements instead of the ul element.

You need to change your CSS like below.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

footer li{
    display:inline-block;
    word-spacing: normal;
}

footer ul{
    word-spacing:20px;
}

<!-- language: lang-html -->

&lt;footer&gt;
    &lt;ul class=&quot;footer&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;about&quot;&gt;Name&#169;2023&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;legal&quot;&gt;Privacy&amp;Legal&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;vin-recall-search&quot;&gt;Vehicle Recalls&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;contact&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;blog&quot;&gt;News&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;updates&quot;&gt;Get Updates&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;findus/list&quot;&gt;Locations&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/footer&gt;

<!-- end snippet -->

答案2

得分: 0

你可以使用新的Flexbox规范,如下所示:

footer ul {
    display: flex;
    align-items: stretch; /* 默认值 */
    justify-content: space-between;
    width: 100%;
}
footer li {
    display: block;
    flex: 0 1 auto; /* 默认值 */
}
<footer>
    <ul class="footer">
        <li><a href="about">Name&copy;2023</a></li>
        <li><a href="legal">隐私与法律</a></li>
        <li><a href="vin-recall-search">汽车召回</a></li>
        <li><a href="contact">联系我们</a></li>
        <li><a href="blog">新闻</a></li>
        <li><a href="updates">获取更新</a></li>
        <li><a href="findus/list">位置</a></li>
    </ul>
</footer>

参考链接:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

英文:

You can use the new Flexbox specification as well

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

footer ul {
    display: flex;
    align-items: stretch; /* Default */
    justify-content: space-between;
    width: 100%;
}
footer li {
    display: block;
    flex: 0 1 auto; /* Default */
}

<!-- language: lang-html -->

&lt;footer&gt;
    &lt;ul class=&quot;footer&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;about&quot;&gt;Name&#169;2023&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;legal&quot;&gt;Privacy&amp;Legal&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;vin-recall-search&quot;&gt;Vehicle Recalls&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;contact&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;blog&quot;&gt;News&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;updates&quot;&gt;Get Updates&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;findus/list&quot;&gt;Locations&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/footer&gt;

<!-- end snippet -->

For Ref: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

huangapple
  • 本文由 发表于 2023年6月8日 17:18:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定