[英]Padding of divs that are to the right of a div floated left
I have a <div>
with a fixed width and height floated left, and to the right of it I have two other <div>
s. 我有一个
<div>
,左边有一个固定的宽度和高度,在它的右边我还有两个<div>
s。 I want to have one of the <div>
s flush against the left-floated <div>
's border, and the other indented slightly. 我希望其中一个
<div>
与左侧浮动<div>
的边界齐平,另一个略微缩进。 Here is what I have at the moment... 这就是我现在所拥有的......
<div
id="leftDiv"
style="border:1px solid grey;
width:300px;
height:400px;
float:left;">
This is a left floated div with a fixed width and height
</div>
<div id="rightDiv">
<div id="flushDiv">This should be flush.</div>
<div id="indentDiv" style="padding:25px">This should be indented.</div>
</div>
But what happens with the above html is that both the <div>
s with id's 'flushDiv' and 'indentDiv' are flush against the right side of the <div>
with id leftSideDiv
. 但是,上述HTML的情况是,无论是
<div>
s的ID的“flushDiv”和“indentDiv”是对的右侧平齐<div>
id为leftSideDiv
。
I can why this happens when I set a visible border on the rightDiv
. 当我在
rightDiv
上设置可见边框时,我可以解释为什么会rightDiv
。 It's left side is actually flush with the left side of the leftDiv
. 它的左侧实际上与
leftDiv
的左侧齐平。 And both elements are already padded well over the 25px indentation that I want for indentDiv
, so they both end up flush against the right side of leftDiv
. 而这两个要素都已经填充了超过我想为25px的缩进
indentDiv
,所以他们都最终对右侧平齐leftDiv
。
If I float rightDiv
right, I get the desired indentation effect, almost. 如果我
rightDiv
右浮动,我几乎可以获得所需的缩进效果。 indentDiv
is now indented with respect to flushDiv
, but flushDiv
is no longer flush against the right side of rightDiv
. indentDiv
现在相对于flushDiv
缩进,但flushDiv
不再与rightDiv
的右侧齐平。
Ok, I'm not even sure I'm following myself anymore. 好吧,我甚至不确定我是否已经关注自己了。
Does anyone understand what I'm asking and have a solution? 有谁知道我在问什么并有解决方案? I'll try to sum it up:
我会试着总结一下:
How can I have two divs to the right of a left floated div, where one is flush agains the left floated div's right border, and the other is offset? 我如何在左浮动div的右侧有两个div,其中一个是左浮动div的右边界再次刷新,另一个是偏移?
Is this what you are trying to accomplish? 这是你想要完成的吗? I put borders around them so you can see them... Here is an example on jsfiddle.com
我在它们周围放置了边框,这样你就可以看到它们......这是jsfiddle.com上的一个例子
http://jsfiddle.net/hawUs/ http://jsfiddle.net/hawUs/
<div id="leftDiv" style="border:1px solid grey;width:300px;height:400px; float:left;">
This is a left floated div with a fixed width and height
</div>
<div id="rightDiv" style=" float:left;">
<div id="flushDiv" style="border:1px solid grey; float">This should be flush.</div>
<div id="indentDiv" style="padding:25px;border:1px solid grey;">This should be indented. </div>
</div>
Update: You can also change the padding
on the div #indentDiv
to use margin
instead. 更新:您还可以更改div
#indentDiv
上的padding
以使用margin
。 See example: http://jsfiddle.net/hawUs/1/ 参见示例: http : //jsfiddle.net/hawUs/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.