html - 无法删除 <ul> 列表 CSS 前后的空格

标签 html css html-lists

我有一些文字,然后是这个部分:

<hr/>
<div class="older-posts">
<ul>
    <li><a href="/index2/">Older posts</a></li>
    <li><a href="/archive/">Archive</a></li>
</ul> 
</div>

这是我的 CSS:

.older-posts ul {
    list-style-type: none;    
    display: inline;
    text-align: center;
}

.older-posts li {
    justify-content: center;   
    width: 150px;
    height: 45px; 
    margin: auto;
    margin-top: 15px;
    border-style: solid;
    border-width: 1px;
    border-color: grey;
}

.older-posts li a {
    color: black;
    text-decoration: none;
}

.older-posts li:hover {
    color: lightcyan;
    background-color: darkslategray;
    -webkit-transition: all .2s ease-in-out;
    -moz-transition: all .2s ease-in-out;
    -o-transition: all .2s ease-in-out;
    transition: all .2s ease-in-out;      
}

但是,在行和框之后,我得到了一个很大的空间(见下文),它不能用 marginpadding 删除行高。我已经没有想法了。这一定是微不足道的。有什么想法吗?

enter image description here

最佳答案

试试这个。 :)

.older-posts ul {
    list-style-type: none;    
    text-align: center;
}

.older-posts li {
    justify-content: center;   
    width: 150px;
    height: 45px; 
    margin: auto;
    margin-top: 15px;
    border-style: solid;
    border-width: 1px;
    border-color: grey;
}

.older-posts li a {
    color: black;
    text-decoration: none;
}

.older-posts li:hover {
    color: lightcyan;
    background-color: darkslategray;
    -webkit-transition: all .2s ease-in-out;
    -moz-transition: all .2s ease-in-out;
    -o-transition: all .2s ease-in-out;
    transition: all .2s ease-in-out;      
}
<hr/>
<div class="older-posts">
<ul>
    <li><a href="/index2/">Older posts</a></li>
    <li><a href="/archive/">Archive</a></li>
</ul> 
</div>

关于html - 无法删除 <ul> 列表 CSS 前后的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558998/

相关文章:

javascript - 只用一个动画类来回无缝过渡?

jquery 为旋转的 div 设置动画

html - knockout 在表中动态添加一行

javascript - 需要有关 Javascript 更新文本框输入文本和跨度文本的帮助和技巧

css - 如何减小DOM所有元素的字体大小?

css - Twitter Bootstrap - 如何让模态窗口在移动设备上负责?

jQuery 均匀高度 float LI

css - 有序列表的自定义列表样式

jquery - 根据 HREF 值切换父元素的类 jQuery

javascript - HTML 获取 URL、单选按钮组、javascript 解析、设置按钮值