CSS两个div宽度50%在一行中,在文件中有换行符 [英] CSS two div width 50% in one line with line break in file

查看:824
本文介绍了CSS两个div宽度50%在一行中,在文件中有换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用百分比作为宽度来构建流体布局。这样做我尝试这样:

I try to build fluid layout using percentages as widths. Do do so i tried this:

<div style="width:50%; display:inline-table;">A</div>
<div style="width:50%; display:inline-table;">B</div>

在这种情况下,他们不会站在一行,但如果我删除它们之间的换行, :

In that case they wont stand in one line, but if i remove line break between them, like this:

    <div style="width:50%; display:inline-table;">A</div><div style="width:50%;   display:inline-table;">B</div>

那么它工作正常。哪里有问题?我怎么能这样做,但不使用绝对位置和浮动。

then it works fine. Where is the problem? How can i do someting like that but without using absolute position and float.

p.s。对不起英语。
p.s.s.我希望我很好地解释我的问题

p.s. sorry for english. p.s.s. i hope i good explain my problem

推荐答案

问题是,当某事是内联的,每个whitepsace是一个实际的空间。所以它会影响元素的宽度。我建议使用float或display:inline-block。 (只要不要在div之间留下任何空格)。

The problem is that when something is inline, every whitepsace is an actual space. So it will influence the width of the elements. I recommend using float or display: inline-block. (Just don't leave any whitespace between the divs).

演示: http ://jsfiddle.net/N9mzE/1/

<div style="width:50%; display: inline-block">A
</div><div style="width:50%; display: inline-block;">B
</div>

这篇关于CSS两个div宽度50%在一行中,在文件中有换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆