【发布时间】:2019-01-22 06:11:58
【问题描述】:
我需要在其他文本中间插入一个内联块。
块中的文本应始终分成两行(只有一个单词时除外)。
内联块的内容未知。 宽度应根据内容而变化。
例子:
我的代码:
div.main {
font-size: 30px;
padding: 30px;
width: 630px;
}
div.two-lines {
display: inline-block;
font-size: 40%;
height: 27px;
background: #35b1e6;
padding: 10px;
color: #6df0ff;
vertical-align: middle;
}
/* This needs to go */
div.two-lines:first-of-type {
width: 194px;
}
div.two-lines:nth-of-type(2) {
width: 39px;
}
<div class="main">
In the middle of a paragraph
<div class="two-lines">INLINE-BLOCK, WHICH CONTAINS TWO EQUALLY LONG LINES.</div>,
with text preceding and following it.
Some more text, and here comes a
<div class="two-lines">SHORT ONE</div>!
You see? Two lines!
</div>
【问题讨论】:
-
我没有看到没有 JavaScript 的方法。您在
two-lines中的文本是否来自服务器控制的来源?你能在那里打破它吗? -
我可以。我只是想知道纯 CSS 是否可行。
-
以某种骇人听闻的方式开放?