[英]Missing span element
I have a problem with a span
element in IE (currently tested against IE9 and IE10). 我在IE中有一个
span
元素有问题(目前已针对IE9和IE10进行了测试)。 When I open F12 Developer Tools and select that span
element I can't find it on screen. 当我打开F12开发人员工具并选择该
span
元素时,在屏幕上找不到它。 However, if I manually assign a background-color
other than transparent
or inherit
it is shown at its expected place. 但是,如果我手动分配
transparent
或inherit
以外的background-color
,则会在其预期位置显示它。
The problem is, that the span
element is used as alignment element for a popup, but since the element is missing, the popup is incorrectly aligned. 问题在于,
span
元素用作弹出框的对齐元素 ,但是由于缺少该元素,因此弹出框未正确对齐。
I wasn't able to observe that behavior in jsfiddle , yet. 我还没有在jsfiddle中观察到这种行为。 And also can't test it in other browsers.
并且也无法在其他浏览器中对其进行测试。
Here is how the significant markup looks like: 重要标记如下所示:
<div id="div1">
<div id="div2">
<span>
<input id="in" value="Somename"></input>
<label for="in">Person surname:</label>
</span>
</div>
</div>
And the corresponding CSS like shown in the developer tools (except for the background-color
attributes): 以及相应的CSS(如开发人员工具中所示)(
background-color
属性除外):
#div1 {
background-color: grey;
cursor: auto;
font-family: Thoma, Verdana, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
text-align: left;
color: #000000;
bottom: 0px;
height: auto;
left: 0px;
position: absolute;
right: 0px;
top: 0px;
width: auto;
}
#div2 {
background-color: blue;
cursor: auto;
font-family: Thoma, Verdana, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
text-align: left;
color: #000000;
}
span {
/* background-color: red; */
font-family: Thoma, Verdana, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
text-align: left;
color: #000000;
margin-left: 0px;
margin-right: 0px;
box-sizing: border-box;
width: 100%;
}
input {
/*background-color: transparent;*/
color: #000000;
padding: 1px 2px 1px 3px;
font-family: Thoma, Verdana, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
margin: 1px;
border: 1px solid #b9b9b4;
overflow-x: hidden;
overflow-y: auto;
width: 90%;
}
label {
cursor: auto;
font-family: Thoma, Verdana, Helvetica, sans-serif;
font-weight: normal;
text-align: left;
color: #000000;
left: 0px;
top: -99999px;
font-size: 0px;
position: absolute;
}
Any ideas, why the span
tag could be missing? 有什么想法,为什么
span
标签会丢失?
Maybe I should clarify, I'am not so much interested in a solution (since I already found one), but in an explanation why I observe this different behavior. 也许我应该澄清一下,我对解决方案并不是很感兴趣(因为我已经找到了一种解决方案),而是在解释为什么我观察到这种不同的行为。 Both for IE vs Jsfiddle and with vs without background-color.
不论是IE vs Jsfiddle以及有vs没有背景色。
I am not responsible for the HTML markup, and can't change that. 我对HTML标记概不负责,也无法更改。 I have only limited access to change the CSS.
我只有有限的权限来更改CSS。
Add " display: block; " to the span element css. 在span元素css中添加“ display:block; ”。
The span element default display property is inline and with this you can't set width, height, margin or padding properties. span元素的默认显示属性是内联 , 因此无法设置width,height,margin或padding属性。 So the span element is not missing but have a 0px width and the height of the line-height of font property.
因此,不缺少span元素,但其宽度为0px,字体属性的行高为高度。
Regards! 问候!
Either use display:block or float:left Tested on IE9-10 使用display:block或float:left 在IE9-10上测试
Also note that: use div instead, span tag is not designed to use like this and not a problem to create another #div3 unless you have something specific. 还要注意:使用div代替,span标记不是设计成这样使用,除非您有特定要求,否则创建另一个#div3并不是问题。
span {
background-color: red;
display:block; /* float:left; */
font-family: Thoma, Verdana, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
text-align: left;
color: #000000;
margin-left: 0px;
margin-right: 0px;
box-sizing: border-box;
width: 100%;
}
Definition and Usage The <span>
tag is used to group inline-elements
in a document. 定义和用法
<span>
标记用于对文档中的行inline-elements
进行分组。
The <span>
tag provides no visual change by itself. <span>
标记本身不提供视觉更改。
The <span>
tag provides a way to add a hook to a part of a text or a part of a document. <span>
标记提供了一种将钩子添加到文本的一部分或文档的一部分的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.