CSS 如何在CSS中的DIV后删除换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17973207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove line break after DIV in CSS
提问by alias51
Is there a way to prevent a line break after a div with css, but to have one div min width and the other max width?
有没有办法防止在带有 css 的 div 之后换行,但是有一个 div 最小宽度和另一个最大宽度?
For example I have
例如我有
<div class="label">My Label:</div>
<div class="text">My text</div>
and want it to display like:
并希望它显示如下:
My Label: My text
Where My text floats right, and my label takes all the remaining width?
我的文本向右浮动,而我的标签占据所有剩余宽度?
I am using the following CSS, but the .text div keeps wrapping:
我正在使用以下 CSS,但 .text div 不断换行:
div
{
display: inline-block;
}
.label {
border:1px solid blue;
width:100%;
}
.text {
border:1px solid red;
float:right;
}
**UPDATE: JS FIDDLE *http://jsfiddle.net/jPrMG/
**更新:JS FIDDLE * http://jsfiddle.net/jPrMG/
Thanks for your help
谢谢你的帮助
采纳答案by Ilya Streltsyn
回答by Spudley
It's not a 'line break' that you're seeing; it's because <div>
elements default to being a block
element.
这不是您看到的“换行符”;这是因为<div>
元素默认为block
元素。
If you want to change the behaviour so that they appear on the same line, you can change the display
property in CSS, like so:
如果你想改变行为使它们出现在同一行,你可以改变display
CSS 中的属性,如下所示:
display:inline;
or
或者
display:inline-block;
If you still want to have width
or min-width
property (as stated in the question) then you would need the latter of those two, inline-block
.
如果您仍然想要拥有width
或min-width
财产(如问题中所述),那么您将需要这两者中的后者,inline-block
.
Hope that helps.
希望有帮助。