【发布时间】:2017-04-26 04:04:06
【问题描述】:
我从服务器返回的文本包含回车(回车)。我问了一些人如何在多行中显示此文本,他们建议我使用white-space: pre。
没有white-space: pre,还有其他方法可以多行显示文本吗?或者有什么方法可以让pre 表现得像一个段落,但有多行而没有额外的填充?
这是我所拥有的:
.gallery-Gcontainer {
margin: 0 !important;
padding: 0;
}
#genericpartTitle,
.content {
padding-left: 20px;
}
.content .sidebar,
.content section {
display: inline-block;
width: 30%;
border: none;
vertical-align: top;
}
.content .sidebar img {
width: 200px;
}
<div class="gallery-Gcontainer">
<div class="header-area">
<h3 id="genericpartTitle">my page</h3>
<hr>
</div>
<div class="content">
<div class="sidebar">
<img class="img-sidebar" src="https://static.pexels.com/photos/30738/pexels-photo-30738.jpg" />
</div>
<section>
<h5 class="item-title">Welcome to my first page</h5>
<p style="white-space: pre" class="description">
Hello, anything will go here, text will come from the server like this, and I need to display it on multiple lines.
</p>
</section>
</div>
</div>
更新:
Putting:white-space: pre-line 按照答案中的建议,解决了 padding left 问题,但 padding-top 仍然有很大的空间。
【问题讨论】: