[英]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: 您有几个错误,例如:
600 px
600 px
的空格 #
in border-color
(you can use border
shorthand) border-color
使用#
(可以使用border
速记) Note this: 请注意:
px
length. px
长度的十进制值。 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.