猿问

css如何控制父div层隐藏 子div层显示?

例:
<style type="text/css">
#div1{display:none;width:500px;height:300px;background:white;border:2px solid black;}
#div2{display:block;width:150px;height:200px;background:red;margin-left:30px;margin-top:30px;}
</style>
</head>
<body>
<div id="div1" ><div id="div2"></div>
</div>
现在想要先只div2

慕工程0101907
浏览 2115回答 1
1回答

精慕HU

只需将父div设置为display:none;即可,子div不设置display属性!1<div&nbsp;display:none><div></div></div>;这样父div就会被隐藏!display 属性规定元素应该生成的框的类型。个属性用于定义建立布局时元素生成的显示框类型。对于 HTML 等文档类型,如果使用 display 不谨慎会很危险,因为可能违反 HTML 中已经定义的显示层次结构。display可能的取值为:none &nbsp; &nbsp;此元素不会被显示。 &nbsp; &nbsp;block &nbsp; &nbsp;此元素将显示为块级元素,此元素前后会带有换行符。 &nbsp; &nbsp;inline &nbsp; &nbsp;默认。此元素会被显示为内联元素,元素前后没有换行符。 &nbsp; &nbsp;inline-block&nbsp;&nbsp; &nbsp;行内块元素。(CSS2.1 新增的值)&nbsp; &nbsp;&nbsp;
随时随地看视频慕课网APP

相关分类

CSS3
我要回答