如果在页面上存在另一个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>
Run Code Online (Sandbox Code Playgroud)
对于您当前的当前HTML,您可以这样做
.always-here {
display:none;
}
.im-here ~ .always-here{
display:block;
}
Run Code Online (Sandbox Code Playgroud)
这只会工作,如果.always-here和.im-here是兄弟姐妹和.im-here到来之前.
http://jsfiddle.net/BKYSV/ - .im-here目前
http://jsfiddle.net/BKYSV/1/ - .im-here缺席