2

我想要做的是在特定的 Y 位置有一个 div 元素,但浮动到左侧或右侧(以便页面上的其他文本将围绕它流动)。我似乎找不到正确的属性组合..

position:relative;float:right 有效,但 div 位于包含元素的顶部

position:relative;top:1in;float:right 将 div 向下移动,但文本流过的区域仍然在该区域的顶部,而不是 +1in 区域

position:absolute 完全禁用浮动

这是一个简单的例子:

<div style='position:relative;top:1in;float:right;border:0.1in solid;'>
<p>This is on the right</p>
</div>
<p>This is the text that should flow around the textbox.  Make as long as needed...</p>

我真正想要的是区域,但还没有浏览器真正支持这一点。

有任何想法吗?谢谢..

4

1 回答 1

2

如果你想从顶部偏移一个浮点数,文本在它周围流动,你必须在它上面插入另一个零宽度的浮点数来实现偏移。像这样:http: //jsfiddle.net/YKYmj/7/

#floater {
    float: right;
    clear: right;    
    border: 1px solid gray;
    background-color: #ccc;
    margin: 10px;
    width: 100px;
    height: 100px;
}

.wrapper:before {
    content: '';
    float:right;
    height:1in;
} 


<div class="wrapper">
    <div id="floater">In offset, floated box</div>
    <p>Lorem ipsum dolor sit amet, consectetur  ...
</div>
于 2013-08-02T18:27:02.127 回答