如果在页面上存在另一个div,我将如何隐藏div并仅显示它?我猜
jquery或js将是要走的路……
<style type="text/css">
.always-here {
display:none;
}
</style>
<div class="im-here">This div exists on this particular page!</div>
<div class="always-here">This div is always here but has the style
display: none unless a div with the class "im-here" exists.</div>
解决方法
对于您当前的当前HTML,您可以这样做
.always-here {
display:none;
}
.im-here ~ .always-here{
display:block;
}
只有.always-这里和.im-这里是兄弟姐妹和.im-这里才会有用.
http://jsfiddle.net/BKYSV/ – .im-现在
http://jsfiddle.net/BKYSV/1/ – .im-这里缺席