如何在不知道宽度的情况下居中对齐div? [英] How can I center align a div without knowing the width?

查看:150
本文介绍了如何在不知道宽度的情况下居中对齐div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了这个,前景似乎暗淡。我对使用表不感兴趣。我有6个左右一个元素内联块,组成一个菜单。它是光滑的,除了所有的'a元素'设置为width:auto;以适应他们的文本。没有明确的宽度,我不能中心对齐它们。我有一个容器div和一个孩子div,包裹我的'a元素'。

I've looked this up and the outlook seems bleak. I'm not interested in using a table. I have 6 or so 'a element' inline-blocks that make up a menu. It's slick, except all the 'a elements' are set to width: auto; to accommodate their text. Without an explicit width, I'm not able to center align them. I have a container div and a child div that wraps around my 'a elements'.

任何想法?
感谢
Mike

Any thoughts? Thanks Mike

推荐答案

您可以设置 a 元素到 margin:0 auto ,但在IE6中无效。在IE6中,您应该将wrapper div设置为 text-align:center ,并且(可选)将 a 元素的文本对齐设置为< align:left

You could set the style of the a element to margin: 0 auto, but that doesn't work in IE6. In IE6, you should set the wrapper div to text-align: center, and (optionally) set the text-alignment for the a element back to text-align: left

这篇关于如何在不知道宽度的情况下居中对齐div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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