[英]CSS padding not applying to parent div
I really don't understand CSS :( 我真的不懂CSS :(
Why is the following padding
not pushing out the size of the parent div? 为什么以下
padding
不超出父div的大小?
HTML 的HTML
<div class="lead-table">
<div class="row table-head-1">
<div class="col-md-9">
<span><strong>My Leads</strong></span>
</div>
</div>
</div>
CSS 的CSS
.lead-table .table-head-1 {
background-color: #053449;
text-transform: uppercase;
color: #ffffff;
font-size: 12px;
}
.lead-table .table-head-1 span {
padding: 20px 18px;
}
http://www.bootply.com/gsT2mwsA8h# http://www.bootply.com/gsT2mwsA8h#
Any help appreciated for this CSS noob. 此CSS菜鸟对此表示感谢。
Thanks 谢谢
span
is not a block element. span
不是块元素。
padding
will not work for inline elements. padding
对于内联元素不起作用。 But margin
will work. 但是
margin
会起作用。
margin: 20px 18px;
margin: 20px 18px;
or display:block;
display:block;
or display:inline-block;
display:inline-block;
to the span. padding
will take effect once you make it a block element. 一旦将其设置为块元素,
padding
将生效。
Unlike div
, p
1 which are Block Level elements which can take up padding
or margin
on all sides, span
2 cannot as it's an Inline element which takes up padding
or margin
horizontally only. 与
div
( p
1)是可以在所有面上占用padding
或margin
块级元素不同, span
2不能,因为它是仅在水平方向上占用padding
或margin
的Inline元素。
From the specification : 从规格 :
Use div
instead of span
...below code will work 使用
div
代替span
...下面的代码将起作用
.lead-table .table-head-1 {
background-color: #053449;
text-transform: uppercase;
color: #ffffff;
font-size: 12px;
}
.lead-table .table-head-1 .col-txt{
padding: 20px 18px;
}
<div class="lead-table">
<div class="row table-head-1">
<div class="col-md-9">
<div class='col-txt'><strong>My Leads</strong></div>
</div>
</div>
</div>
Just replace that both css with following, it may help you :- 只需将两个CSS替换为以下内容,它可能会对您有所帮助:-
.lead-table .table-head-1 {
background-color: #053449;
text-transform: uppercase;
color: #ffffff;
font-size: 12px;
padding: 20px 18px;
}
Your html needs to be wrapped in a "container" class division tag with bootstrap. 您的HTML需要使用引导程序包装在“容器”类划分标签中。
HTML: HTML:
<div class="container">
<div class="lead-table">
<div class="row table-head-1">
<div class="col-md-9">
<span><strong>My Leads</strong></span>
</div>
</div>
</div>
</div>
Also, your CSS can be reduced for what you have currently as shown below. 同样,可以将CSS缩小为当前显示的值,如下所示。
CSS: CSS:
/* CSS used here will be applied after bootstrap.css */
.lead-table{
background-color: #053449;
text-transform: uppercase;
color: #ffffff;
font-size: 12px;
}
.table-head-1{
padding: 20px 18px;
}
By default a span is an inline element. 默认情况下,跨度是内联元素。 You cannot add padding top or bottom to it unless you add
display:block
. 除非添加
display:block
,否则不能在其顶部或底部添加填充。
.lead-table .table-head-1 span {
padding: 20px 18px;
display:block;
}
Working code example: http://www.bootply.com/kSh1hNCkTb# 工作代码示例: http : //www.bootply.com/kSh1hNCkTb#
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.