我有这样的代码:
code {
width: 520px;
margin: 0 0 30px 200px;
}

<code>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/0.10.4/js/jquery.terminal.min.js"></script><br/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/0.10.4/css/jquery.terminal.min.css" rel="stylesheet"/>
</code>
&#13;
但保证金仅添加到第一行,我尝试使用此css添加white-space: pre-wrap;
(在css tricks上找到):
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
但是我根本没有保证金。如何在代码标记中添加边距并在文字包装太大的情况下进行文本换行?
答案 0 :(得分:1)
您可以尝试使用<code>
调整display: block
元素本身的显示方式,这会影响padding
或margin
等属性的应用:
code {
display: block;
width: 520px;
margin: 0 0 30px 200px;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word;
}
示例强>
您可以see an interactive example of this in action here以及下面的内容:
答案 1 :(得分:0)
似乎我需要添加包装器:
.code_wrapper {
width: 520px;
margin: 0 0 30px 200px;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
<div class="code_wrapper">
<code>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/0.10.4/js/jquery.terminal.min.js"></script><br/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/0.10.4/css/jquery.terminal.min.css" rel="stylesheet"/>
</code>
</div>
答案 2 :(得分:0)
您可以 inside a div like this:
<div class='outer_code' >
<code>...</code>
</div>
Then in CSS
<div class='outer_code' >
<code>...</code>
</div>