【发布时间】:2016-02-01 00:24:45
【问题描述】:
我想使用 CSS 在列中并排显示两条文本。左列文本的长度是可变的,而右列文本是固定的并且总是相同的长度。
我希望两个“列”彼此相邻浮动到左侧,例如
[Variable Text] [Fixed text]
如果变量文本很长,我希望它换行。 例如,
Here is a very long Hello World
piece of variable
text which wraps
如果变量文本很短,我的代码可以工作,但如果变量文本换行,我会得到不需要的空格。 例如,
Here is a very long Hello World
piece of variable
text which wraps
这是我的代码:
#wrapper {
margin-right: 100px;
}
#left-col {
float: left;
max-width: 100%;
background-color: #CCF;
}
#right-col {
float: left;
width: 100px;
margin-right: -100px;
background-color: #FFA;
}
#cleared {
clear: both;
}
<div id="wrapper">
<div id="left-col">Here is a very long piece of text which wraps</div>
<div id="right-col">Hello World</div>
<div id="cleared"></div>
</div>
【问题讨论】:
-
我不确定我是否理解您的问题。如果你有长文本
#left-col换行,这没关系,但如果你有短文本,你会得到额外的空间,你想避免吗? -
您能解释一下您尝试并排放置的内容(含义/语义)是什么。是脚注吗?
-
对我来说看起来像是标准文本换行。我认为它被称为“内联盒模型”,您对此无能为力。
-
谢谢你们到目前为止的cmets...@Tasos K - 不,它与此相反。如果左列换行,我会在两列之间获得额外的空格。
-
您提供的代码 sn-p 没有您描述的问题。也许是其他原因导致了这个问题?
标签: html css layout css-float two-columns