Html 在 div 中创建换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/34165311/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
create a line break within a div
提问by spex5
I will have 3 icons side by side that will float left when the window shrinks. Under each icon, I'd like to add some text. I can pretty much get it as you can see below.
我将有 3 个并排的图标,当窗口缩小时它们会向左浮动。在每个图标下,我想添加一些文字。正如你在下面看到的那样,我几乎可以得到它。
.icons {
 BORDER-TOP: black 1px solid; 
  HEIGHT: 100px; 
  BORDER-RIGHT: black 1px solid; 
  WIDTH: 100px; 
  BORDER-BOTTOM: black 1px solid; 
  FLOAT: left; 
  BORDER-LEFT: black 1px solid
}<div class="icons">div 1</br><a>some text</a></div>
<div class="icons">div 2</div>
<div class="icons">div 3</div>In jsfiddle, this </br>tag seems to come up as invalid.  Is there a valid and / or better way to accomplish this?
在 jsfiddle 中,这个</br>标签似乎无效。有没有有效和/或更好的方法来实现这一目标?
回答by JD Davis
You're getting an error thrown in jsfiddle due to your linebreak syntax being wrong.
由于换行语法错误,您在 jsfiddle 中抛出错误。
You're using </br>when you should be using <br/>
你在</br>应该使用的时候使用<br/>
2020/HTML5 EDIT
2020/HTML5 编辑
You no longer need to use self-closing tags in HTML5 (though browsers can still handle them), instead you can simply use <br>.
您不再需要在 HTML5 中使用自关闭标签(尽管浏览器仍然可以处理它们),您可以简单地使用<br>.
回答by Michael Benjamin
Just apply display: blockto your text elements.
只需应用于display: block您的文本元素。
a { display: block; }
The will force each element to consume the full available width of the container, and subsequent elements to the next line.
将强制每个元素消耗容器的全部可用宽度,并将后续元素消耗到下一行。
回答by It Assistors
Instead of </br>use <br>or <br />
而不是</br>使用<br>或<br />
<br />is a valid tag whereas </br>is not so.
<br />是一个有效的标签,而事实</br>并非如此。
Use :
用 :
<div class="icons">div 1
<br>some text
</div>
<div class="icons">div 2<br>some
<br>some text
</div>
<div class="icons">div 3
<br>some text
</div>
P.S.
聚苯乙烯
<a>is anchor tag and it is not a good option for adding little elements to your webpage. Instead use <span>tag which will be more efficient.
<a>是锚标记,它不是向网页添加小元素的好选择。相反,使用<span>标签会更有效。
回答by Sidney Gijzen
You have a syntax error in your <br>tag
您的<br>标签中有语法错误
So this
<div class="icons">div 1</br><a>some text</a></div>
所以这
<div class="icons">div 1</br><a>some text</a></div>
should become
<div class="icons">div 1<br><a>some text</a></div>
应该成为
<div class="icons">div 1<br><a>some text</a></div>

