使某些内容转到页面下一行的 CSS 是什么?
如何使元素自动定位在页面中的新行上?在 HTML 中,我可以使用
,但是如何在 CSS 中添加类似 换行符 的内容?
例如,假设我有以下代码:
<p>Lorem ipsum dolor sit amet,
<span id="elementId">consectetur adipisicing elit.</span>
Magni totam velit ex delectus fuga fugit</p>
跨度仍然与文本的其余部分位于同一行。如何纯粹通过 CSS 将跨度文本移至新行?
另一个例子是使用 display: inline-block
或 float
时:
<div class="smalldiv">Lorem ipsum dolor sit amet</div>
<div class="smalldiv">Lorem ipsum dolor sit amet</div>
<div class="smalldiv" id="elementId">Lorem ipsum dolor sit amet</div>
<div class="smalldiv">Lorem ipsum dolor sit amet</div>
.smalldiv {
display: inline-block; // OR
float: left;
}
How can I move one of the
s on a new line创建一个新行?How can I make an element automatically be positioned on a new line in the page? In HTML I could use <br>
, but how do I add something like a line-break in CSS?
Say I have the following code for example:
<p>Lorem ipsum dolor sit amet,
<span id="elementId">consectetur adipisicing elit.</span>
Magni totam velit ex delectus fuga fugit</p>
The span is still positioned on the same line as the rest of the text. How can I move the span text on a new line purely through CSS?
Another example is when using display: inline-block
or float
:
<div class="smalldiv">Lorem ipsum dolor sit amet</div>
<div class="smalldiv">Lorem ipsum dolor sit amet</div>
<div class="smalldiv" id="elementId">Lorem ipsum dolor sit amet</div>
<div class="smalldiv">Lorem ipsum dolor sit amet</div>
.smalldiv {
display: inline-block; // OR
float: left;
}
How can I move one of the <div>
s on a new line to create a new row?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以想到两个选项,但没有更多细节,我无法确定哪个更好:
这将迫使元素换行如果它不在同一行上line 作为浮动元素。
这将迫使元素清除浮动,并移动到“新行”。
据我所知,如果元素与另一个
position
为fixed
或absolute
位于同一行,则不会,强制“换行”,因为这些元素将从文档的正常流程中删除。There are two options that I can think of, but without more details, I can't be sure which is the better:
This will force the element to a 'new line' if it's not on the same line as a floated element.
This will force the element to clear the floats, and move to a 'new line.'
In the case of the element being on the same line as another that has
position
offixed
orabsolute
nothing will, so far as I know, force a 'new line,' as those elements are removed from the document's normal flow.让元素显示为块:
Have the element display as a block:
这取决于为什么某些东西首先在同一条线上。
clear
在浮动的情况下,display: block
在内联内容自然流动的情况下,没有什么可以击败position:absolute
作为前一个元素将被它从正常流程中取出。It depends why the something is on the same line in the first place.
clear
in the case of floats,display: block
in the case of inline content naturally flowing, nothing will defeatposition: absolute
as the previous element will be taken out of the normal flow by it.