我试图将图像浮动到右边。这应该很简单。它在FF和Chrome中看起来很好,但在IE中,文字并没有环绕图像。我认为这与我给段落标签的风格有关。无论如何,任何见解都会受到赞赏!
式:
.story {
margin: 0 0 0 360px;
padding-top: 30px;
padding-left: 30px;
max-width: 900px;
width: 75%;
}
.story p {
line-height: 150%;
font-size: 20px;
}
.half-embed {
float: right;
position:relative;
margin-right:-100px;
margin-left:20px;
display: inline !important;
clear:both;
}
.imageborder {
border: 1px solid lightgray;
padding: 10px;
}
HTML:
<div class="story">
<p>Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.</p>
<p>Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.</p>
<p><img src="images/myimage.jpg" class="half-embed imageborder" /></p>
<p>Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.</p>
<p>Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.</p>
</div>
答案 0 :(得分:0)
您正在设置display:inline ...您不能浮动内联元素。
另外,请确保您正在设置doctype。否则,你将在IE中处于怪癖模式。
html的第一行应该是:
<!doctype html>
从段落中删除图像。它有自己的块级范围,并且应该强制其他元素挂在它下面。不确定为什么它不能在浏览器中保持一致,但这就是它应该如何工作。
答案 1 :(得分:0)
您正在浮动图片,该图片位于display: inline-block
元素中(默认情况下)== <p>
所以<p>
占据了veiwport的整个宽度,即使你的图像是浮动的。因此,您的文字无法包裹您的图片(使用此处提供的hTML),因为您的文字位于其他<p>
中:
<p>Now ....</p>
<p><img src="images/myimage.jpg" class="half-embed imageborder" /></p>
<p>...</p>
要让文字环绕图像,您应该这样做:
<p>
<img src="images/myimage.jpg" class="half-embed imageborder" alt="">
Now we are engage......//oper that we
</p>
.half-embed {
float: right;
margin: 0 0 20px 20px;
display: block;
}
答案 2 :(得分:0)
Mark的答案适用于我的测试页面,但不适用于我的实际页面,因此缺少某些内容。但总的来说,IE7刚刚被打破。我的浮动无处不在,但在那里,甚至更高版本的IE。因此,我将简化IE7的页面并警告观众这一事实。