将pre标签包裹在表格单元格内

4
我使用最新的 Twitter Bootstrap,但是在表格单元格内使用pre标签时遇到了一些问题。如果行太长,应该会创建水平滚动条,但事实并非如此。 http://jsfiddle.net/52VtD/6958/ 这是一个没有 pre 标签的例子。
<div class="row">
    <div class="container">
        <div class="col-md-3" style="border: 1px solid red;">
            this is col-md-3? yes :)
            <table class="table">
                <thead>
                    <tr><th>author</th><th>content</th></tr>
                </thead>
                <tbody>
                    <tr><td>somebody</td><td></td></tr>
                </tbody>
            </table>
        </div>
        <div class="col-md-9" style="border: 1px solid black;">test</div>
    </div>
</div>

http://jsfiddle.net/52VtD/6959/ 这是一个涉及 pre 标签的示例。

<div class="row">
    <div class="container">
        <div class="col-md-3" style="border: 1px solid red;">
            this is col-md-3? no :(
            <table class="table">
                <thead>
                    <tr><th>author</th><th>content</th></tr>
                </thead>
                <tbody>
                    <tr><td>somebody</td><td>why I cannot wrap it?<br/><pre>&lt;?php<br/>class A<br/>{<br/>    function foo()<br/>    {<br/>        if (isset($this)) {<br/>            echo '$this is defined (';<br/>            echo get_class($this);<br/>            echo &quot;)\n&quot;;<br/>        } else {<br/>            echo &quot;\$this is not defined.\n&quot;;<br/>        }<br/>    }<br/>}<br/><br/>class B<br/>{<br/>    function bar()<br/>    {<br/>        // Note: the next line will issue a warning if E_STRICT is enabled.<br/>        A::foo();<br/>    }<br/>}<br/><br/>$a = new A();<br/>$a-&gt;foo();<br/><br/>// Note: the next line will issue a warning if E_STRICT is enabled.<br/>A::foo();<br/>$b = new B();<br/>$b-&gt;bar();<br/><br/>// Note: the next line will issue a warning if E_STRICT is enabled.<br/>B::bar();<br/>?&gt;</pre></td></tr>
                </tbody>
            </table>
        </div>
        <div class="col-md-9" style="border: 1px solid black;">test</div>
    </div>
</div>

我不知道该怎么做,我尝试了很多次使用CSS属性。

1个回答

10

尝试使用:

<pre><code> your example code here </code></pre>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接