题
我怎样才能得到 here
和 and here
位于右侧,与 lorem ipsums 位于同一行?请参阅以下内容:
Lorem Ipsum etc........here
blah.......................
blah blah..................
blah.......................
lorem ipsums.......and here
解决方案
<div style="position: relative; width: 250px;">
<div style="position: absolute; top: 0; right: 0; width: 100px; text-align:right;">
here
</div>
<div style="position: absolute; bottom: 0; right: 0; width: 100px; text-align:right;">
and here
</div>
Lorem Ipsum etc <br />
blah <br />
blah blah <br />
blah <br />
lorem ipsums
</div>
尽管您可能需要调整“顶部”和“底部”值,但您已经非常接近了。
其他提示
将要显示在右侧的文本向右浮动,并在标记中确保该文本及其周围的范围出现在应显示在左侧的文本之前。如果它没有首先发生,您可能会遇到浮动文本出现在不同行上的问题。
<html>
<body>
<div>
<span style="float:right">here</span>Lorem Ipsum etc<br/>
blah<br/>
blah blah<br/>
blah<br/>
<span style="float:right">and here</span>lorem ipsums<br/>
</div>
</body>
</html>
请注意,这适用于任何线条,而不仅仅是顶角和底角。
如果包含 Lorum Ipsum 的元素的位置设置为绝对,则可以通过 CSS 指定位置。“here”和“and here”元素需要包含在块级元素中。我将使用这样的标记。
print("<div id="lipsum">");
print("<div id="here">");
print(" here");
print("</div>");
print("<div id="andhere">");
print("and here");
print("</div>");
print("blah");
print("</div>");
这是上面的 CSS。
#lipsum {position:absolute;top:0;left:0;} /* example */ #here {position:absolute;top:0;right:0;} #andhere {position:absolute;bottom:0;right:0;}
同样,只有当 #lipsum 通过绝对定位时,上述方法才有效(可靠)。
如果没有,您将需要使用 float 属性。
#here, #andhere {float:right;}
您还需要将标记放在适当的位置。为了更好地呈现,您的两个 div 可能需要一些填充和边距,以便文本不会全部运行在一起。
<style>
#content { width: 300px; height: 300px; border: 1px solid black; position: relative; }
.topright { position: absolute; top: 5px; right: 5px; text-align: right; }
.bottomright { position: absolute; bottom: 5px; right: 5px; text-align: right; }
</style>
<div id="content">
<div class="topright">here</div>
<div class="bottomright">and here</div>
Lorem ipsum etc................
</div>
或者更好的是,使用适合您需要的 HTML 元素。它更干净,并产生更精简的标记。例子:
<dl>
<dt>Lorem Ipsum etc <em>here</em></dt>
<dd>blah</dd>
<dd>blah blah</dd>
<dd>blah</dd>
<dt>lorem ipsums <em>and here</em></dt>
</dl>
浮动 em
到右边(与 display: block
),或将其设置为 position: absolute
其父级为 position: relative
.
您需要将“此处”放入 <div>
或者 <span>
和 style="float: right"
.
第一行由 3 组成 <div>
s。一个外部包含两个内部 <div>
s。第一个内 <div>
将有 float:left
这将确保它保持在左侧,第二个将有 float:right
, ,这会将其粘在右侧。
<div style="width:500;height:50"><br>
<div style="float:left" >stuff </div><br>
<div style="float:right" >stuff </div>
...显然内联样式不是最好的主意 - 但你明白了。
2,3,4都是单身 <div>
s。
5 的工作方式与 1 类似。
您也许可以使用绝对定位。
容器箱应设置为 position: relative
.
右上角的文本应设置为 position: absolute; top: 0; right: 0
。右下角的文本应设置为 position: absolute; bottom: 0; right: 0
.
你需要尝试一下 padding
阻止框的主要内容在绝对定位元素下方运行,因为它们存在于文本内容的正常流之外。
您只需要将 div 元素向右浮动并为其留出边距即可。确保在这种情况下不要使用“绝对”。
#date {
margin-right:5px;
position:relative;
float:right;
}