代码之家  ›  专栏  ›  技术社区  ›  Noah Wallaart

无法居中对齐我的按钮

  •  2
  • Noah Wallaart  · 技术社区  · 8 年前

    我正在制作一个投资组合网站,因为我需要为学校提供它。 现在我正在尝试文本对齐网页上的按钮。我试了很多, 为li、ol和几个类提供:text-align:center、margin-right/margin-left:auto。似乎什么都不管用。我现在已经被困了1.5个多小时了,所以如果你们中有人能帮我解决这个问题,那将是一件非常棒的事情。

    提前非常感谢!

    诺亚

    此处图片: https://imgur.com/EAQTdVM

    HTML:

    <div class="jumbotron">
    
            <div class="container container-fluid">
                <div class="row">
                    <div class="col-md-12 midden ">
                        <ol>
                            <li><a href="#" role="button">Contact</a></li>
                            <li><a href="#" role="button">Work</a></li>
                        </ol>
                    </div>
                </div>
    
    
                <div class="row">
                    <div class="col-md-3-offset-3">
    
    
                        <h1>Noah Wallaart</h1>
                    </div>
    
                    <div class="col-md-6">
                    </div>
                </div>
            </div>
        </div>
    
    
    
    
    Css:
    
    
    .jumbotron {
        background: url("/image/background4.JPG") no-repeat scroll center center / cover;
        height: 720px;
        margin-top: -20px;
    }
    
    div h1 {
        font-family: 'Open Sans', sans-serif;
        font-weight: 400;
        font-size: 50px;
        color: white !important;
        text-align: center;
        margin-top: 0.2em;
    }
    
    p {
        font-family: 'Open Sans', sans-serif;
        font-size: 30px;
        color: white;
    }
    
    a {
        text-decoration: none;
        color: black;
        font-family: 'Open Sans', sans-serif;
        border: 3px solid black;
        padding: 10px 20px 10px 20px;
        display: inline;
        float: left;
        margin: 20px;
    }
    
    li {
        display: inline;
        float: right;
    }
    
    a:hover {
        text-decoration: none;
        background-color: #BDBFBD;
        color: white;
        border: 3px solid white;
    }
    
    
    /* Lookbook */
    
    section {
        width: 80%;
        margin-left: auto;
        margin-right: auto;
    }
    
    .row-margin {
        margin-bottom: 20px;
        margin-top: 20px;
    }
    
    .img-responsive {
        display: block;
        max-width: 100%;
        height: auto;
    }
    
    .less-padding {
        padding: 0px;
    }
    
    
    /* Buttons */
    
    li a {
        text-decoration: none;
        color: white;
        font-weight: 200 font-family: 'Roboto', sans-serif;
        border: 0.15em solid white;
        padding: 10px 20px 10px 20px;
        display: inline;
        float: left;
        margin: 20px;
    }
    
    
    li {
        display: inline;
        width: 120px;  
    }
    
    a:hover {
        text-decoration: none;
        background-color: #BDBFBD;
        color: white;
        border: 3px solid white;
        margin-bottom: 0px;
        margin-left: 20px;
    }
    
    3 回复  |  直到 8 年前
        1
  •  1
  •   Sara Inés Calderón    8 年前

    你的一些标记是关闭的,“中午”不是一个单词,你所要做的就是“文本中心” 一行 而且效果很好。祝你好运

    <div class="jumbotron">
    
        <div class="container container-fluid">
            <div class="row text-center">
                <div class="col-md-12">
                    <ul class="list-unstyled list-inline">
                        <li><a href="#" role="button">Contact</a></li>
                        <li><a href="#" role="button">Work</a></li>
                    </ul>
                </div>
            </div>
    
    
            <div class="row">
                <div class="col-md-3-offset-3">
    
    
                    <h1>Noah Wallaart</h1>
                </div>
    
                <div class="col-md-6">
                </div>
            </div>
        </div>
    </div>
    
        2
  •  0
  •   Jinu Kurian    8 年前

    现在,添加这些样式

    .midden ol {
        margin-top: 0;
        margin-bottom: 10px;
        display: table; 
        margin: 0 auto;
    }
    .midden li{
      float: none;
    }
    

    .midden ol {
        margin-top: 0;
        margin-bottom: 10px;
        display: table;
        margin: 0 auto;
    }
    .midden li{
      float: none;
    }
    
    .jumbotron {
        background: url("http://www.govisitcostarica.com/images/photos/full-hot-air-balloons-near-arenal.jpg") no-repeat scroll center center / cover;
        height: 720px;
        margin-top: -20px;
    }
    
    div h1 {
        font-family: 'Open Sans', sans-serif;
        font-weight: 400;
        font-size: 50px;
        color: white !important;
        text-align: center;
        margin-top: 0.2em;
    }
    
    p {
        font-family: 'Open Sans', sans-serif;
        font-size: 30px;
        color: white;
    }
    
    a {
        text-decoration: none;
        color: black;
        font-family: 'Open Sans', sans-serif;
        border: 3px solid black;
        padding: 10px 20px 10px 20px;
        display: inline;
        float: left;
        margin: 20px;
    }
    
    li {
        display: inline;
        float: right;
    }
    
    a:hover {
        text-decoration: none;
        background-color: #BDBFBD;
        color: white;
        border: 3px solid white;
    }
    
    
    /* Lookbook */
    
    section {
        width: 80%;
        margin-left: auto;
        margin-right: auto;
    }
    
    .row-margin {
        margin-bottom: 20px;
        margin-top: 20px;
    }
    
    .img-responsive {
        display: block;
        max-width: 100%;
        height: auto;
    }
    
    .less-padding {
        padding: 0px;
    }
    
    
    /* Buttons */
    
    li a {
        text-decoration: none;
        color: white;
        font-weight: 200 font-family: 'Roboto', sans-serif;
        border: 0.15em solid white;
        padding: 10px 20px 10px 20px;
        display: inline;
        float: left;
        margin: 20px;
    }
    
    
    li {
        display: inline;
        width: 120px;  
    }
    
    a:hover {
        text-decoration: none;
        background-color: #BDBFBD;
        color: white;
        border: 3px solid white;
        margin-bottom: 0px;
        margin-left: 20px;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="jumbotron">
    
            <div class="container container-fluid">
                <div class="row">
                    <div class="col-md-12 midden ">
                        <ol>
                            <li><a href="#" role="button">Contact</a></li>
                            <li><a href="#" role="button">Work</a></li>
                        </ol>
                    </div>
                </div>
    
    
                <div class="row">
                    <div class="col-md-3-offset-3">
    
    
                        <h1>Noah Wallaart</h1>
                    </div>
    
                    <div class="col-md-6">
                    </div>
                </div>
            </div>
        </div>
        3
  •  0
  •   Nick Larsen    8 年前

    当您使用Bootstrap时,您不希望覆盖框架提供的属性。相反,你所需要做的就是给容器 text-center 上课,应该会很好。

    <div class="jumbotron">
    
        <div class="container container-fluid">
            <div class="row">
                <div class="col-md-12 text-center"> <!-- THIS LINE CHANGED -->
                    <ol>
                        <li><a href="#" role="button">Contact</a></li>
                        <li><a href="#" role="button">Work</a></li>
                    </ol>
                </div>
            </div>
    
    
            <div class="row">
                <div class="col-md-3-offset-3">
    
    
                    <h1>Noah Wallaart</h1>
                </div>
    
                <div class="col-md-6">
                </div>
            </div>
        </div>
    </div>