简体   繁体   English

HTML CSS左边距和右边距不希望将div居中

[英]HTML CSS margin-left and margin-right don't want to center a div

I'm learning css and html and i have this problem, where the margin-left and margin-right in the ".logo" div class don't want to center the div. 我正在学习css和html,并且我有此问题,其中“ .logo” div类中的margin-left和margin-right不想将div居中。 Please help because i done reserch, i checked the code and everything looks good, so I have no idea whats going on. 请帮忙,因为我完成了研究,我检查了代码,一切看起来都很好,所以我不知道发生了什么。

 body { background-color: #303030; color: #ffffff; } .wrapper { width:100%; } .header { width:100px; padding:40px 0; } .logo { width:450px; font-size:48px; border: 1px solid white; margin-left: auto; margin-right: auto; } 
 <html lang="pl"> <head> <meta charset="utf-8"/> <title>site</title> <link rel="stylesheet" href="style.css" type="text/css"/> </head> <body> <div class="wrapper"> <div class="header"> <div class="logo"> LOGO </div> </div> </div> </body> </html> 

Your header is only 100px while your logo is 450px , you can check this fiddle for demo . 标头仅为100px ,徽标为450px ,可以查看此小提琴进行演示

.wrapper {
  width: 100%;
}

.header {
  width: 1000px;
  padding: 40px 0;
}

.logo {
  width: 450px;
  font-size: 48px;
  border: 1px solid white;
  margin-left: auto;
  margin-right: auto;
}

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

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