html - CSS - 类移出位置

标签 html css

我应该做这样的事情:

enter image description here

但它实际上看起来像:

enter image description here

正如你在图像上看到的那样,当我在那里添加图像或文本时,“左”类无缘无故地离开了它的位置,而且我 100% 确定文本或图像小于 block 的宽度/高度,所以我真的不知道如何继续和解决这个问题。

我的 HTML:

 <div id="sub-content">
    <span class="left">
    <img src="images/foto.png">
    <span class="topic-name"> Název topicu nebo článku </span>
    </span>
    <span class="middle"></span>
    <span class="right"></span>
 </div>

我的 CSS:

#sub-content{
    margin-left: 20px;
    margin-top: 0px;
    background-image: url("images/sub_content_bg.png");
    background-repeat: repeat-x;
    height: 145px;
    width: 987px;
    display:inline-block;
}
#sub-content .left{
    width: 326px;
    height: 145px;
    display: inline-block;        
}

#sub-content .left img{
    width: 122px;
    height: 121px;
    display: inline-block;
    margin-top: 0px;
    margin-left: 5px;        
}

#sub-content .left .topic-name{
    width: 150px;
    margin-bottom: 130px;
    margin-left: 10px;
    display: inline-block;
    vertical-align: top;
    text-decoration: underline;
    font-weight: 14px;         
} 

#sub-content .middle{
    background-color: orange;
    width: 326px;
    height: 145px;
    display: inline-block;         
}

#sub-content .right{
    background-color: yellow;
    width: 326px;
    height: 145px;
    display: inline-block;         
}

有人可以帮我设计这个样式或者告诉我我做错了什么吗?

附注也可以在以下位置找到实时预览:funedit.com/andurit/new/

最佳答案

如果将 overflow:hidden 添加到 .left div,它将正确对齐。

参见:JSFiddle

(我还将内部 span 替换为 div,因为 div 不应出现在 span 中)。

关于html - CSS - 类移出位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23015678/

相关文章:

javascript - 响应当前显示部分的网页元素

html - 溢出 : hidden with border radius not working on Safari

html - 可点击的重叠 div 和焦点

html - iframe 在父级内部的高度为零,没有高度和底部填充

html - "Float:right"未应用于提交按钮

php - 除最后一行外的中心 float

javascript - jquery slider 在我到达最后一个后不会继续

html - 单独的 css 文件不适用于 html 文件,但将 css 放在与 html 相同的文件中

javascript - 更改页面间隔的正文背景

PHP - 页面只允许一个管理员注册