[英]CSS Alignment issue with div and img float:left in IE7
I have to show 4 news with images, date and title of publication in sort of two column - left column for image, right column for date and title. 我必须以两列显示带有图像,日期和出版物标题的4条新闻-图像的左列,日期和标题的右列。
Tried different approaches using dl and and now div with class dl to achieve the arrangement, worked only in FF and IE8 and 9. 尝试使用dl和现在使用dl类的div来实现这种安排的不同方法,仅在FF和IE8和9中有效。
IE7 doesnt apply alignment I wanted. IE7不适用我想要的对齐方式。
Arranged jsfiddle for testing - the issue shows when result window is wider than usual. 安排了jsfiddle进行测试-当结果窗口比平常宽时,该问题就会显示。
Would accept also suggestions for better HTML structure of showing news. 还将接受有关更好的显示新闻的HTML结构的建议。
<div style="clear:both"></div>
Putting that between each item fixes it for IE7. 将其放在每个项目之间可修复IE7。 Or take the clearfix from the html5 boilerplate http://html5boilerplate.com/
或从html5样板http://html5boilerplate.com/中获取clearfix
Alternatively you can wrap each dt/dd pair in a div 或者,您可以将每个dt / dd对包装在div中
here is the working version Check the updated jsfiddle 这是工作版本检查更新的jsfiddle
Please find the changes in css and HTML structure below :- 请在下面找到CSS和HTML结构的更改:
CSS: CSS:
#section{
width: 560px;
float: left;
font-size: 0.8em;
position: relative;
}
.dl .dd h4{
font-size: 0.9em;
}
.dl h4 a{
text-decoration: none;
font-weight: normal;
}
.dl h4 a:hover{
text-decoration: underline;
}
.dl .dt{
float: left;
width: 100px;
height: 75px;
font-size: 0.5em;
margin: 0 0 5px 0;
}
.dl .dd{
width: 480px;
float: right;
}
.dl .wrapper { /* new element added */
overflow: hidden;
height: 100%;
padding: 10px 0 5px;
}
.dl .dd p{
font-size: 0.7em;
font-style: italic;
}
/* No need of this code
.dl:after,
.dl .dt:after,
.dd:after,
.dl .dt img:after
{
content:"";
height: 0;
clear: both;
display: block;
}
*/
HTML: HTML:
<div class="dl">
<div class="wrapper">
<div class="dt"><img src="/news_pics/16.jpg" alt="pic 1" width="100px" height="75px"/> </div>
<div class="dd"><p>12 06 2012</p><h4><a href="#">News 1 title khfk ds khf kdsfkdsh fkkds hfkhdsjkf kj kjs hdfkjdsk kds k hfkjhds k ks hdfkjhds fjk hdsk hfkjds kgjkl f dflgk dflkdf lk lf jdl glklk dllgdldl l dfljlgkjdflgkjdf</a></h4></div>
</div>
<div class="wrapper">
<div class="dt"><img src="/news_pics/16.jpg" alt="pic 2" width="100px" height="75px"/></div>
<div class="dd"><p>21 05 2012</p><h4><a href="#">News 2 title</a></h4></div>
</div>
<div class="wrapper">
<div class="dt"><img src="/news_pics/16.jpg" alt="pic 3" width="100px" height="75px"/></div>
<div class="dd"><p>19 05 2012</p><h4><a href="#">News 3 title title khfk ds khf kdsfkdsh fkkds hfkhdsjkf kj kjs hdfkjdsk kds k hfkjhds k ks hdfkjhds fjk hdsk hfkjds kgjkl f dflgk dflkdf lk lf jdl glklk dllgdldl l dfljlgkjdflgkjdf</a></h4></div>
</div>
<div class="wrapper">
<div class="dt"><img src="/news_pics/16.jpg" alt="pic 4" width="100px" height="75px"/></div>
<div class="dd"><p>8 05 2012</p><h4><a href="#">News 4 title</a></h4></div>
</div>
EDIT: 编辑:
The <div class="wrapper"
helps to clear the float
and display the elements properly in all browsers including IE6 & 7. <div class="wrapper"
有助于清除float
并在包括IE6和7在内的所有浏览器中正确显示元素。
:before
and :after
don't work in IE7 :before
和:after
在IE7中不起作用
see :after and :before css pseudo elements hack for IE 7 参见:after和:before IE 7的CSS伪元素hack
For your quick reference i put the fiddle checkout this 供您快速参考,我把这个小提琴结帐
The issue there is you put the section width 560px;
那里的问题是您将部分
width 560px;
and the content inside will exceed the limit so that issue occures. 并且里面的内容将超过限制,从而发生问题。 and the
<p>
tag with the highest width 以及宽度最大的
<p>
标签
Changes: 变化:
.dl .dd p{
width: 210px; //changed
font-size: 0.7em;
font-style: italic;
}
for every dd,dt div surrond with a main div 为每个dd,dt div加上一个主要div
<div class="fix_float">
<dt>
date content
</dt>
<dd>
text content
</dd>
</div>
enter code here
try this html: 试试这个HTML:
<ul class="ul">
<li class="li">
<img src="/news_pics/16.jpg" class="thumb" width="100" height="75">
<div class="text">
<p class="date">
12 06 2012
</p>
<h4>
<a href="" class="title">
News 1 title khfk ds khf kdsfkdsh fkkds hfkhdsjkf kj kjs hdfkjdsk kds k hfkjhds k ks hdfkjhds fjk hdsk hfkjds kgjkl f dflgk dflkdf lk lf jdl glklk dllgdldl l dfljlgkjdflgkjdf
</a>
</h4>
</div>
</li>
<li class="li">
<img src="/news_pics/16.jpg" class="thumb" width="100" height="75">
<div class="text">
<p class="date">
12 06 2012
</p>
<h4>
<a href="" class="title">
News 1 title khfk ds khf kdsfkdsh fkkds hfkhdsjkf kj kjs hdfkjdsk kds k hfkjhds k ks hdfkjhds fjk hdsk hfkjds kgjkl f dflgk dflkdf lk lf jdl glklk dllgdldl l dfljlgkjdflgkjdf
</a>
</h4>
</div>
</li>
</ul>
and css 和css
.ul {
margin: 0;
padding: 0;
list-style: none;
}
.li {
overflow: hidden;
margin-bottom: 5px;
}
.thumb {
float: left;
width: 100px;
height: 75px;
}
.text {
margin-left: 120px;
}
.title {
font-size: 0.9em;
text-decoration: none;
font-weight: normal;
}
.title:hover {
text-decoration: underline;
}
in jsfiddle http://jsfiddle.net/sgMKy/ 在jsfiddle中http://jsfiddle.net/sgMKy/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.