简体   繁体   English

div中的多行文本边框(html / css)

[英]Border around multiline text in a div (html/css)

I want to have a border around multiline text, I have: 我希望在多行文字周围有一个边框,我有:

Morbi hendrerit pretium nibh quis <span style='border: 1px solid black;'>
mattis. Blah blah blah</span> blah blah...

Now, when the span spans more than one line, the border is created around each line of text, which I don't want to happen - I am aiming for a border around a whole block, with the text being inline (display:block/inline-block don't do the job properly). 现在,当跨度跨越多行时,边界是围绕每行文本创建的,我不想发生 - 我的目标是围绕整个块的边框,文本是内联的(显示:块) / inline-block不能正常工作)。

Is there a way of achieving that without playing with javascript? 有没有办法实现这一点而不玩javascript?

Wrap the whole string in a div and set it to display: inline-block. 将整个字符串包装在div中并将其设置为显示:inline-block。

<div style="border: 1px solid black; display: inline-block">
  Morbi hendrerit pretium nibh quis<br>
  mattis. Blah blah blah blah blah...
</div>

Use <div> instead of <span>. 使用<div>而不是<span>. It might fix the issue. 它可能会解决问题。

What about using an inline div instead of a span? 使用内联div而不是跨度怎么样?

Morbi hendrerit pretium nibh quis <div class="inline-border"> mattis. 
Blah blah blah</div> blah blah...

and in your CSS 在你的CSS中

.inline-border {border: 1px solid black;display:inline}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM