如何使用CSS中心内联div? [英] how to center an inline div using css?

查看:120
本文介绍了如何使用CSS中心内联div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用css定位内联div(而不是其内容)?

How can I center an inline div (not its content) using css?

非常重要的是:div的宽度是未知的(我不能指定它)

VERY IMPORTANT: the width of the div is unknown (I can not specify it)

推荐答案

如果通过inline表示,其CSS显示属性设置为 inline 然后你可以通过给中间父容器a text-align:center

If by inline you mean, its CSS display property is set to inline then you can center it by giving the immediate parent container a text-align:center

一个div在另一个div,你可以按照这种方法,如果你可以添加一个包装器和浮动两个:

If you mean a div within another div, you can follow this approach if you can add a wrapper and float both:

如何水平居中一个可变宽度的浮动元素?

这篇关于如何使用CSS中心内联div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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