你好,
我有以下 HTML:
<div class="controlTitleContainer ">
<label for="test">Titel</label>
<div class="q"> </div>
</div>
CSS 看起来像这样
.controlTitleContainer .label
{
font-size: 0.94em;
color: #778899;
display:inline;
}
.controlTitleContainer .q
{
background-image: url("Images/Common/Icons/questionMark_15x14.png");
height: 14px;
width: 15px;
float:left;
}
问题是div会放在label的左边而不是右边?为什么?
我尝试将 div 切换到 span 但没有成功。另外,如果我将 div 更改为 img intead,那么它会起作用,但是有一些我无法用 div 元素删除的不需要的边距。
请指教
Edit1:问题中的混淆现在应该得到解决,对此深表歉意。
MySolution:我创建了两个 div 元素(一个用于文本,一个用于图标),然后将两者都设置为左侧 float 。
最佳答案
你很困惑。您在问题标题中谈论 IMG
,然后在您的代码中出现 SPAN
,然后在您的文本中谈论 DIV
。
但我想这三个都在您的代码中引用了 SPAN
,因为您确实为 SPAN
元素设置了背景图像。
解决方案
无论如何。您的 span
根据您的 CSS 向左浮动。如果您在样式表中删除以下行,您的 span
将出现在您的 label
的右侧:
float: left; /* <- remove this */
Edit: I suppose your question got downvoted due to this confusion. If you want the community to help with detailed answers the least you could do is to take the time to formulate your question with the same amount of care as you expect back.
关于标签元素后的 HTML img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4915999/