居中基于百分比的div [英] Centering a percent-based div

查看:126
本文介绍了居中基于百分比的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,一个客户问他的网站是基于百分比,而不是像素为基础。百分比设置为80%。正如你们知道的,如果是基于像素的容器,那么容器的中心是很容易的,但是如何确定基于百分比的主容器的中心位置?

Recently, a client asked that his site be percent-based rather than pixel-based. The percent was to be set to 80%. As you guys know, it is very easy to center the container if it is pixel-based but how do you center a percent-based main container?

#container
{
  width:80%;
  margin:0px auto;
}

这不会使容器居中:(

推荐答案

margin属性支持百分比值:

The margin property supports percentage values:

margin-left: 10%;
margin-right: 10%;

这篇关于居中基于百分比的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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