Html text-align:center; 不起作用

Ven*_*enx 3 html css text-align

我在这里有一个问题,我想把文本#top_page h1居中,但它不起作用,我不知道为什么.谁能提出一些想法?我尝试了一切,但文字对齐:中心; 和浮动:右或左也不起作用.

我搜索谷歌寻求帮助,并查看堆栈溢出相同的问题,但没有一个解决问题,所以我要求你们帮忙.

body {
        background: url(img/bg.jpg) no-repeat center center fixed; 
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
      display: inline-block;
      font-family: 'Cabin', sans-serif;

    }

    a {
        text-decoration: none;
        color: black;
        font-family: 'Cabin', sans-serif;
    }

    li {
        float: right;
        margin-top: 3px;
        margin-right: 50px;
        color: white;
        font-family: 'Cabin', sans-serif;
        font-size: 15px;
    }

    header {
        display: block;
        position: fixed;
        top: 0px;
        left: 0px;
        width: 100%;
        height: 50px;
        background: white;
        font-family: 'Cabin', sans-serif;
        z-index: 999999;
    }

    a:hover {
        color: crimson;
        font-family: 'Cabin', sans-serif;
    }

    span {
        width: 100%;
    }

    #top_page h1 {
        font-size: 80px;
        color: white;
        margin-top: 250px;
        display: block;
        text-align: center;
        font-family: 'Cabin', sans-serif;
    }

    #top_page h3 {
        font-size: 40px;
        margin-top: -40px;
        color: white;
        text-align: center;
        margin-left: 315px;
        font-family: 'Droid Sans', sans-serif;
    }
Run Code Online (Sandbox Code Playgroud)

小智 5

你的标题有100%的宽度,但身体没有.只需添加width: 100%body.