Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将某些文本右对齐到上面文本的右边缘?_Html_Css - Fatal编程技术网

Html 将某些文本右对齐到上面文本的右边缘?

Html 将某些文本右对齐到上面文本的右边缘?,html,css,Html,Css,我有几行文字。我希望最后一个右对齐,以便文本形成一个漂亮的列 这就是我想要实现的目标: Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore, While I nodded, nearly napping, suddenly there came a tapping, As of some one gently r

我有几行文字。我希望最后一个右对齐,以便文本形成一个漂亮的列

这就是我想要实现的目标:

Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore, While I nodded, nearly napping, suddenly there came a tapping, As of some one gently rapping, rapping at my chamber door. "'T is some visiter," I muttered, "tapping at my chamber door— Only this, and nothing more." 从前,在一个沉闷的午夜,当我疲惫不堪地沉思时, 在许多稀奇古怪的被遗忘的传说中, 当我点点头,几乎要打盹的时候,突然传来了敲门声, 就像有人轻轻地敲打,敲打我的房门。 “这是个来访者,”我咕哝着,“敲着我的房门。”- 只有这个,没有别的。” 我能告诉你最后一行吗:“把你自己右对齐到你上面文本的右边缘”


我真的不希望手动为文本指定宽度(即使在
em
s中),因为我不希望在用户调整大小或更改字体时断行。

float
包含段落的元素,
float:left
内容,以及
float:right
最后一行。浮动的容器将与整个段落一样宽,因此右浮动最后一行将使其右边缘与前面文本的右边缘对齐

例如:

<div style="float: left">
<span style="float: left">
Once upon a midnight dreary, while I pondered, weak and weary,<br/>
Over many a quaint and curious volume of forgotten lore,<br/>
While I nodded, nearly napping, suddenly there came a tapping,<br/>
As of some one gently rapping, rapping at my chamber door.<br/>
"'T is some visiter," I muttered, "tapping at my chamber door—<br/>
</span>
<span style="float: right; clear: left">Only this, and nothing more."</span>
</div>

float
包含段落的元素,
float:left
内容,
float:right
最后一行。浮动的容器将与整个段落一样宽,因此右浮动最后一行将使其右边缘与前面文本的右边缘对齐

例如:

<div style="float: left">
<span style="float: left">
Once upon a midnight dreary, while I pondered, weak and weary,<br/>
Over many a quaint and curious volume of forgotten lore,<br/>
While I nodded, nearly napping, suddenly there came a tapping,<br/>
As of some one gently rapping, rapping at my chamber door.<br/>
"'T is some visiter," I muttered, "tapping at my chamber door—<br/>
</span>
<span style="float: right; clear: left">Only this, and nothing more."</span>
</div>

你想把所有的东西都对齐吗?不,只是最后一行。对不起,这个例子并没有说清楚。你想把所有的东西都对齐吗?不,只是最后一行。对不起,这个例子并没有说清楚。太好了!最后一件事-我不认为有一种方法可以使整个事情(包含div)居中?页边距:自动似乎不起作用-我想是因为浮动。@Blorgbeard:已更新以适应。太好了!最后一件事-我不认为有一种方法可以使整个事情(包含div)居中?页边距:自动似乎不起作用-我想是因为浮动。@Blorgbeard:已更新以适应。