简体   繁体   English

如何将父div中的子div与边距居中?

[英]how can I center child div inside parent div with margins?

Here is the code 这是代码

div.content_inner {
    background-color: white;
    -moz-box-shadow: 1px 5px 10px #000;
    -webkit-box-shadow: 1px 5px 10px #000;
    box-shadow: 1px 5px 10px #000;
    margin-left: 10%;
    margin-right: 10%;
}

Website is http://twoandahalfmiles.polymath.io 网站是http://twoandahalfmiles.polymath.io

I'm trying to get the white content are to have margins on each side and I want it to stretch to the top of the website, it doesn't currently do that either. 我试图让白色内容在每一方都有利润,我希望它延伸到网站的顶部,它目前也没有这样做。

Thanks in advance! 提前致谢!

You can define a fixed width, and set the left and right side margin value of auto.Like this: 您可以定义固定宽度,并设置auto的左右边距值。如下所示:

.content {
  width: 940px;
  margin-left: auto;
  margin-right: atuo;
}
div.content_inner {
    background-color: white;
    -moz-box-shadow: 1px 5px 10px #000;
    -webkit-box-shadow: 1px 5px 10px #000;
    box-shadow: 1px 5px 10px #000;
   /* margin-left: 10%;
    margin-right: 10%;*/ /*please delete*/
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM