html - 使列表项样式彼此独立

标签 html css html-lists

我有一个 ul,里面有几个列表项,由 h3s 和 lis 组成,类 ID 为“close”。

我有一个悬停样式,可以扩展 h3s 上的字母间距,问题是,具有 close 类的元素也会扩展。在添加类之前我尝试了一些不同的东西,比如第 n 个 child 等(所有这些都在代码中可见)。当 h3 扩展时,我希望紧密分类的 lis 保持相同的大小。

感谢任何帮助。

jsfiddle 在这里: https://jsfiddle.net/snowwhyte/7eLmarnp/7/#&togetherjs=Uq5j49dUG0

CSS:

a {text-decoration:none;
}
li {list-style:none;
}
}
#openClose {
    position:absolute;
    top:200px;
    margin-top:55px;
}

#openClose li{
    list-style-type:none;
    display:block;
    padding-right:-50px;
}

#openClose li:nth-child(2n+2){
    margin:30px 0 100px 0;
    background-color:#000;
    border:2px #fff solid;
    text-align:center;
    letter-spacing:1rem;
    padding:10px 0 10px 0;
}
#openClose li:nth-child(2n+2):hover{
letter-spacing:-0.1rem; 
transition:.3s;
}

#openClose li a h3{
font-family:Helvetica, Gotham, Helvetica, Arial, sans-serif;
color:#73a6c2;
}

.close{
}

#openClose li a h3:hover{color:#fff;
text-shadow:2px 1px 2px #000;
transition:.2s;
letter-spacing:1rem;
}

a:visited { text-decoration: none; color:#B8CEDB; }
a:hover { text-decoration: none; color:#D7D8D8; }
a:focus { text-decoration: none; color:#fff; 

HTML:

<section id="openClose">
<ul>
<li><a href="#wrapper"><h3>Tool Descriptions</h3></a></li>
<li class="close"><a href="#">Close</a></li>
<li><a href="#wrapper2"><h3>Key tools</h3></a></li>
<li class="close"><a href="#">Close</a></li>
<li><a href="#wrapper3"><h3>Adjustment Layers & <br>
Blending modes</h3></a></li>
<li class="close"><a href="#">Close</a></li>
</ul></section>

最佳答案

问题是您没有任何具有定义宽度的元素,因此每个元素都具有最大元素的宽度。

要实现您想要实现的目标,您可以根据自己的需要选择多种解决方案。

您可以在其中一个父项上定义固定宽度,例如 ul 并将 white-space: nowrap 属性添加到 h3(参见 the fiddle):

ul {
    width: 200px;
}
#openClose li a h3{
    white-space: nowrap;
}

您还可以使用关闭按钮在 li 上设置固定宽度(请参阅 the fiddle ):

#openClose li:nth-child(2n+2){
   width: 200px;
}

关于html - 使列表项样式彼此独立,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35964555/

相关文章:

javascript - 逐步上传页面内容(不必等到所有内容都加载完毕)

python - 无法覆盖 django 中 NumberInput 字段的步骤属性

html - 在 OPTGROUP 元素上应用 CSS 类

html - 您可以为无序列表中的每个列表元素使用不同的图标图像吗?

html - 如何在列表项周围创建价格标签(如边框)

javascript - 为什么我在 <span> 元素后换行

html - 自动选择 HTML 输入中的文本

css - 在CSS中,如何用破折号填充段落中每一行的空白区域?

javascript - 滑动显示错误的一面

css - 图像相互重叠的导航