如何使多个div显示在一行,但仍保留宽度? [英] How to make multiple divs display in one line but still retain width?

查看:276
本文介绍了如何使多个div显示在一行,但仍保留宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,您可以将元素设置为display:inline,如果您希望它们显示在同一行中。但是将元素设置为inline意味着width属性将无意义。

Normally, you set elements to display: inline if you want them to display in the same line. However setting an element to inline means that the width attribute would be meaningless.

如何使div处于同一行而不使它们内联?

How do you make divs to be in the same line without making them inline?

推荐答案

您可以使用 display:inline-block

此属性允许DOM元素拥有块元素的所有属性,但保持其内联。有一些缺点,但大部分时间是足够好。 为什么它很好,为什么它可能

This property allows a DOM element to have all the attributes of a block element, but keeping it inline. There's some drawbacks, but most of the time it's good enough. Why it's good and why it may not work for you.

EDIT:唯一的现代浏览器有一些问题是IE7。请参见 Quirksmode.org

The only modern browser that has some problems with it is IE7. See Quirksmode.org

这篇关于如何使多个div显示在一行,但仍保留宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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