【发布时间】:2015-09-22 20:31:11
【问题描述】:
我有一个宽度为 100% 的<ul>,其作用类似于表格,内部有两个 <li> 元素,其中包含一个背景图像,它们都充当表格单元格,每个 <li> 的宽度为50%。我想将<li> 更改为在媒体查询断点处显示为块元素,并改为以 100% 的宽度显示。这行不通。
这是HTML:
<section id="features">
<h1>The Functionality</h1>
<ul class="main-links">
<li style="background-image: url(img/test2.jpg);"><div>Some text</div></li>
<li style="background-image: url(img/test1.jpg);"><div>more text and even more text</div></li>
</ul>
</section>
这是css(我使用的是SASS):
#main #features {
background-color: #fff;
overflow: hidden;
}
#main #features ul {
display: table;
width: 100%;
}
#main #features ul li {
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
background-position: center top;
height: 350px;
list-style: none;
display: table-cell;
width: 50%;
}
最后是媒体查询:
@media screen and (min-width: 760px) and (max-width: 980px) {
#features .main-links {
width: 100%;
border: solid 2px red;
}
#features li {
border: solid 2px lime;
width: 100%;
display: block;
}
.contact-info {
display: none;
}
}
唯一被覆盖的是边框......我错过了什么?感谢帮助
【问题讨论】:
-
您还需要将
ul从display:table重置回block。并且还要注意特异性。在您的媒体查询中使用相同的选择器。 -
@Abhitalks 这可能应该是一个答案,而不是评论。
-
尝试将其显示更改为阻止并在必要时使用 !important。希望有所帮助
-
添加 !important 确实使其成为块元素,但它不会将宽度更改为 100%。这是我无法解决的最大问题。
-
好的,我添加了 !important 到宽度,这解决了我的问题。但是使用 !important 感觉不对。
标签: html css media-queries