使用边距自动和中心将浮动左Div居中 [英] Use Margin Auto and Center to center Float Left Div

查看:103
本文介绍了使用边距自动和中心将浮动左Div居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题曾被问过很多次。

I know this question had been asked many times.

将div对齐到中心

但是,我遵循他们的建议:

However, I follow their suggestion :

<center>
  <div style="margin : auto; text-align: center">
    <a href="#" style="float: left; margin-right: 10px;">Menu Item 1</a>
    <a href="#" style="float: left; margin-right: 10px;">Menu Item 2</a>
    <a href="#" style="float: left; margin-right: 10px;">Menu Item 3</a>
  </div>
</center>

使用中心和边距自动,文本对齐中心...我仍然无法居中菜单项。

By using "Center" and "Margin Auto", "Text Align Center" ... I still unable to center the menu item.

推荐答案

使用inline-block代替float left。

use inline-block instead of float left.

<center>
  <div style="margin : auto; text-align: center">
    <a href="#" style="display: -moz-inline-box; display: inline-block; left; margin-right: 10px;">Menu Item 1</a>
    <a href="#" style="display: -moz-inline-box; display: inline-block; margin-right: 10px;">Menu Item 2</a>
    <a href="#" style="display: -moz-inline-box; display: inline-block; margin-right: 10px;">Menu Item 3</a>
  </div>
</center>

这篇关于使用边距自动和中心将浮动左Div居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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