【发布时间】:2015-08-19 17:54:23
【问题描述】:
我有以下布局:
<!doctype html>
<html lang="en">
<head>
<style>
html{
font-family: "Trebuchet MS", Helvetica, sans-serif;
color: white;
}
.outer{
/*Maybe something here?*/
}
.inner_1{
background-color: aquamarine;
display: inline-block;
width: 400px; /*(For testing)*/
}
.inner_2{
background-color: mediumaquamarine;
display: inline-block;
width: 400px; /*For testing*/
}
/*or Something like this?*/
/*inner_1:below{
background-color:red;
}*/
</style>
</head>
<body>
<div class="outer">
<div class="inner_1">
<p>This is inner_1. Some Content goes here</p>
</div>
<div class="inner_2">
<p>This should be red if it is <b>below</b> inner_1</p>
</div>
</div>
</body>
</html>
只有当第二个div 低于第一个div 时,是否有纯CSS 方法来选择它? (当视口大小下降到 800 像素以下时就是这种情况)
我只想将颜色(或任何 CSS 属性)应用于第二个 div,前提是它低于第一个 div。
我知道我可以使用媒体查询将一个 div 放在另一个 div 的下方并对其应用样式,但我不知道 div 中会有多少内容,所以这不是一种选择。
有什么想法吗?请告诉我。
编辑我说的是视觉表现。
【问题讨论】:
-
视觉结构或 DOM 中的“下方”是什么意思?
-
不,你不能。这正是媒体查询的用途。
-
如何查询换行符?我不知道换行的宽度是多少。