如何在jumbotron中设置<h1>和<p>的位置?

时间:2017-02-01 12:24:20

标签: html css twitter-bootstrap

您好我想知道如何在jumbotron中设置h1和p的位置。让我们说我想把我的h1放在jumbotron的左下角,而在h1下我希望有p但是有一点左填。

&#13;
&#13;
.jumbotron {
  max-width: 100%;
  padding-top: 80px;
  padding-bottom: 80px;
  color: inherit;
  background-color: orange;
}
.jumbotron h1 {
  position: relative;
  display: block;
  font-weight: bold;
  font-size: 30px;
  color: white;
  padding-left: 40px;
  padding-bottom: 80px;
}
.jumbotron p {
  position: absolute;
  display: block;
  color: white;
  font-size: 20px;
}
&#13;
<div class="jumbotron">
  <h1> Reserve your place </h1>
  <p>..before somebody will overtake you</p>
</div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

你设置了一些不必要的定位。绝对没有理由给h1定位relativeabsolutep

老实说,根据你使用它的方式来判断,我说你应该做一些学习和实验来充分理解这些机制。

&#13;
&#13;
.jumbotron {
  max-width: 100%;
  padding-top: 80px;
  padding-bottom: 80px;
  color: inherit;
  background-color: orange;
}
.jumbotron h1 {
  display: block;
  font-weight: bold;
  font-size: 30px;
  color: white;
  padding-left: 40px;
}
.jumbotron p {
  display: block;
  color: white;
  font-size: 20px;
  padding-left: 40px;
}
&#13;
<div class="jumbotron">
  <h1> Reserve your place </h1>
  <p>..before somebody will overtake you</p>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

希望这能帮到你!

.jumbotron {
    max-width: 100%;
    padding-top: 40px;
    padding-bottom: 80px;
    color: inherit;
    background-color: orange;
}
.jumbotron h1 {
    position: relative;
    display: block;
    font-weight: bold;
    font-size: 30px;
    color: white;
    padding-left: 40px;
}
.jumbotron p {
    position: absolute;
    display: block;
    color: white;
    font-size: 20px;
    padding-left:40px;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    <link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="jumbotron">
        <h1> Reserve your place </h1>
        <p>..before somebody will overtake you</p>
    </div>
<script src="https://code.jquery.com/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</body>
</html>

答案 2 :(得分:0)

我已经做过这样的事情,并且它的工作方式使我的文本与中心,左侧或右侧对齐。

<div class="jumbotron text-center container">
      <h1>This is demo</h1>
  </div> 

希望这会有所帮助。