【发布时间】:2019-04-23 03:49:11
【问题描述】:
这是我的标记
<div class="code php">
<div class="container">
<div class="line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 </div>
<code>
<?php
$people = array('henry', 'foo', array('jeff', 'bar'), 'tom', 'barry');
foreach($people as $person) {
if (is_array($person) {
foreach($person as $innerPerson) {
if ($innerPerson == 'bar') {
break 2;
}
}
}
}
?>
</code>
</div>
</div>
更新
上面的固定格式。很重要,因为它在 CSS 中使用了white-space: pre。
这是我的 CSS
.code {
display: block;
margin: 1em 0 1em 0.3em;
padding: 0.8em;
}
.code .container {
background: #efe;
white-space: pre;
border-left: 3px solid #6d9743;
font-size: 1em;
line-height: 1.1em;
padding: 0.8em;
}
.code .caption {
display: block;
font-size: 90%;
margin-top: 0.5em;
color: #333;
}
code,
.code .line-numbers {
font-family: Consolas, Monaco, Lucida Console, Liberation Mono, Courier New, serif;
border: 0px solid red;
}
.code .line-numbers {
float: left;
padding-right: 0.8em;
color: #ccc;
}
这就是正在发生的事情!
damn http://alexanderdickson.com/so.png
请注意行号不匹配?它曾经完美地工作。我最近经常玩它,让自己添加一个标题,我想我已经搞砸了。 (我确实需要研究版本控制!)
谁能看到我做错了什么?我已经尝试了行高、填充等,并尽我所能使用 Firebug 进行了检查。
谢谢
另一个更新
此处的真实示例:http://www.alexanderdickson.com/articles/php/exiting-a-loop-early/
注意:我已尝试删除所有代码格式(所有<spans> 等)但仍然存在问题!
已修复
它现在正在使用这个 CSS
.code {
display: block;
margin: 1em 0 1em 0.3em;
padding: 0.8em;
}
.code .container {
background: #efe;
border-left: 3px solid #6d9743;
font-size: 1em;
line-height: 1.5em;
padding: 0.8em;
white-space: pre;
font-family: Consolas, Monaco, Lucida Console, Liberation Mono, Courier New, serif;
}
.code .line-numbers {
float: left;
padding-right: 0;
color: #ccc;
width: 2em;
}
.code .caption {
display: block;
font-size: 90%;
margin-top: 0.5em;
color: #333;
}
【问题讨论】:
-
如果您的唯一目标是显示代码,那么为什么不使用 syntaxhighlighter。 alexgorbatchev.com/wiki/SyntaxHighlighter是最简单高效的代码展示方式。