为什么我的div在一个范围内不能正常工作? [英] Why doesn't my div inside a span work properly?
问题描述
我正在写下面的 HTML
标记:
< ;跨度>一些文本
< div id =ch>татата< / div>
< / span>
和款式:
span {
border:1px纯黑色;
text-align:center;
width:300px;
height:300px;
背景:aqua;
}
#ch {
width:100px;
身高:100px
背景:黄色;
}
- 为什么
高度
属性不适用于span
内部的div
元素,但会应用宽度 - 为什么我的
span
的右边框缺失?
你的标记是不正确的(加上缺少的分号如Steini所引用的,提及这是为了完整答案)
答案: 答案2 :添加 span 是
元素,所以在 span
中有一个 div
是个好主意,如果嵌套 span
内部 span
并给出内部跨度 display:block
property! p>
display:block to
span
更改默认行为
p>
I'm writing the following HTML
markup:
<span> Some Text
<div id="ch">татата</div>
</span>
and styles:
span{
border: 1px solid black;
text-align:center;
width: 300px;
height: 300px;
background: aqua;
}
#ch{
width:100px;
height:100px
background: yellow;
}
- Why is the
height
property not applied to adiv
element which inside thespan
, but width is applied? - Why is the right border of my
span
is missing?
Your markup is incorrect ( plus missing semi-colon as quoted by Steini, mentioning this for sake of completeness of answer )
Answer 1 : span
is an inline
element, so having a div
inside span
is a bad idea, also, it would be better, if you nest span
inside span
and give inner span display:block
property!
Answer 2 : add display:block
to span
to change the default behavior
working fiddle with correct markup
fiddle with the layout you wanted
这篇关于为什么我的div在一个范围内不能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!