【问题标题】:HTML CSS margin-left and margin-right don't want to center a divHTML CSS margin-left 和 margin-right 不想让 div 居中
【发布时间】:2017-09-09 14:23:16
【问题描述】:

我正在学习 css 和 html,但我遇到了这个问题,“.logo”div 类中的 margin-left 和 margin-right 不想让 div 居中。请帮忙,因为我做了研究,我检查了代码,一切看起来都很好,所以我不知道发生了什么。

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>

【问题讨论】:

  • 问题是.header小于.logo

标签: html css


【解决方案1】:

你的标题只有100px,而你的标志是450px,你可以检查这个fiddle for demo

.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;
}

【讨论】:

  • 哇,因为代码中有 1 个愚蠢的零,我几乎失去了一个小时试图看看有什么问题。非常感谢您的快速回复:D
  • 是的,我是 StackOverflow:D 的新手,但肯定没问题
猜你喜欢
  • 1970-01-01
  • 2019-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-04
  • 2014-05-16
相关资源
最近更新 更多