简体   繁体   English

CSS属性不适用于嵌套div

[英]CSS properties not applying in nested div

I'm trying to create a <div> within a <div> that sits like this 我试图创建一个<div>内的<div>坐在这样的 在此处输入图片说明

Both containers should have a nice amount of height to them, for some reason when I put the <div> within the <div> it breaks the height and some of the other CSS properties so everything ends up looking squashed. 这两个容器应该有一个很好的量height到他们,因为某种原因,当我把<div><div>它打破了height和其他一些CSS属性,所以一切最终看起来被挤压。

Is #masthead_topbar inheriting something from the parent <div> or do I need to change something else? #masthead_topbar是从父<div>继承某些内容还是我需要更改其他内容?

The Code: 编码:

 #container { width: 951.8px ; height: 600 px ; background-color: #c2c2c2 ; border: solid 1px ; border-color: b8b8b8 ; margin: 0 auto ; display: flex ; align-items: center ; } #masthead_topbar { width: 929px ; min-height: 47.00 px ; max-height: 47.00 px ; background-color: #c2c2c2 ; border: solid 1px ; border-color: b8b8b8 ; margin-left: 10px ; margin-right: 10px; margin-top: 10px ; } 
 <div id="container"> <!-- Start Masthead TopBar --> <div id="masthead_topbar"> <font>Test</font> <!-- End Masthead_TopBar --> </div> <!-- End Container DIV --> </div> 

you have a couple of mistakes, such as: 您有几个错误,例如:

  • a space in lengths such as 600 px 长度为600 px的空格
  • not using # in border-color (you can use border shorthand) 不要在border-color使用# (可以使用border速记)

Note this: 请注意:

  • don't use decimal values in px length. 不要使用px长度的十进制值。
  • don't use font , it is deprecated. 不要使用font ,它已被弃用。

here is a working example: 这是一个工作示例:

 .container { max-width: 950px; /* changed for demo */ height: 150px; /* changed for demo */ border: solid 1px #b8b8b8; margin: 0 auto; display: flex; align-items: center; } .masthead_topbar { width: 100%; border: solid 1px #b8b8b8; margin: 10px 10px 0; padding: 10px; } 
 <div class="container"> <!-- Start Masthead TopBar --> <div class="masthead_topbar"> Test <!-- End Masthead_TopBar --> </div> <!-- End Container DIV --> </div> 

well , you just have to remove the space between 600 px ; 好吧,您只需要删除600 px ;之间的空间600 px ; to be 600px; 600px; :) maybe some other things need to be fixed also (the codes between stars ** ** edited ) : :)也许还需要修复其他一些问题(编辑星星** **之间的代码):

#container {
  width: 951.8px ;
  **height: 600px ;**
  background-color: #c2c2c2 ;
  **border: 1px solid #b8b8b8 ;**
  **border-color: #b8b8b8 ;**
  margin: 0 auto ;
  display: flex ;
  align-items: center ;
}
#masthead_topbar {
  width: 929px ;
  **min-height: 47.00px ;
  max-height: 47.00px ;**  
  background-color: #c2c2c2 ;
  **border: 1px solid #b8b8b8 ;
  border-color: #b8b8b8 ;**
  margin-left: 10px ; 
  margin-right: 10px;   
  margin-top: 10px ;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM