在h1中居div

时间:2016-07-27 01:08:34

标签: html css header anchor center

我正在尝试为freecodecamp创建一个组合,但是我无法找到如何将按钮居中,或者在页面上标记为“row”的div。我需要行div,因为我稍后会添加更多按钮,但是现在我只需要FCC按钮。下面是我的网站到目前为止我的html和css文件。欢迎任何帮助!

HTML:

#body {
  height: 100vh;
  width: 100%;
}

#mpp {
  font-family: Monospace;
  font-size: 50px;
  color: white;
  padding-top: 15%;
  margin: 0;
}
#land {
  background: url(http://img.hrhwalls.com/images2/ki13j11c4ef.jpg);
  width: 100%;
  height: 100vh;
}
#fcc {
  background-color: #016403;
  text-decoration: none;
  color: #FFFFFF;
  font-size: 17px;
  position: inherit;
}
#btnrow {
  right: 50%;
}

CSS:

login_form

2 个答案:

答案 0 :(得分:1)

#btnrow {
  display: flex;
  justify-content: center;
}

应该做的伎俩。见下面的工作示例



#body {
  height: 100vh;
  width: 100%;
}

#mpp {
  font-family: Monospace;
  font-size: 50px;
  color: white;
  padding-top: 15%;
  margin: 0;
}
#land {
  background: url(http://img.hrhwalls.com/images2/ki13j11c4ef.jpg);
  width: 100%;
  height: 100vh;
}
#fcc {
  background-color: #016403;
  text-decoration: none;
  color: #FFFFFF;
  font-size: 17px;
  position: inherit;
}
#btnrow {
  display: flex;
  justify-content: center;
}

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">

<!-- Web page starts here -->
<body id="body">
  <section id="land">
      <h1 id="mpp" class="text-center"> My Personal Portfolio </h1>
        <div class="row" id="btnrow">
          <a href="http://www.freecodecamp.com/zacmelendez" class="btn responsive" id="fcc"><i class="fa fa-file-code-o"> Free Code Camp</i></a>
        </div>
  </section>
  <section id="intro">
  </section>
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以为div赋予宽度并使用自动保证金为左侧和右侧值,这将使元素水平居中。

.row {
    margin: 0 auto;
    width: 150px; /*or any measurement*/
}