使用Flexbox将一个div放在Bootstrap Carousel中

时间:2018-05-02 11:05:13

标签: html css twitter-bootstrap flexbox carousel

我试图使用Flexbox在我的Bootsrap Carousel中间添加一个圆形div。我还希望旋转木马背景能够覆盖100vh高度和100%宽度的页面。

我遇到的问题是圆圈出现在页面底部而不是直接在中间。我已经使用top和margin-top在页面中居中,但我想使用Flexbox使其完美地位于页面的中心。此外,背景图片从不覆盖整个页面

非常感谢任何帮助



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Muli:200,300,400" rel="stylesheet">
    <script src="app.js"></script>
</head>
<body>
  <div id="fullpage">
    <div id="process" class="vertical-center">

      <div id="processCarousel" class="carousel slide" data-ride="carousel">
          <!-- Indicators -->
          <ol class="carousel-indicators">
            <li data-target="#processCarousel" data-slide-to="1" class="active"></li>
            <li data-target="#processCarousel" data-slide-to="2"></li>
            <li data-target="#processCarousel" data-slide-to="3"></li>
          </ol>
        
          <!-- Wrapper for slides -->
          <div class="carousel-inner ">
            <div class="item active ">
              <div class="process-container">
                  <img src="https://images.pexels.com/photos/127673/pexels-photo-127673.jpeg?auto=compress&cs=tinysrgb&h=350" style="object-fit: cover; height:100vh; width:100%;">
                  <div class="vertical-center">
                      <div class="circle vertical-center">
                          <div class="circle-text">
                              <h1>Test</h1>
                              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, dolore?</p>
                          </div>
                      </div>
                  </div>
              </div> 
            </div>
        
            <div class="item">
                <div class="process-container">
                    <img src="http://worldlandforms.com/landforms/wp-content/uploads/2015/03/Beach-1024x683.jpg" style="object-fit: cover; height:100vh; width:100%;">
                    <div class="vertical-center">
                        <div class="circle vertical-center">
                            <div class="circle-text">
                                <h1>Test2</h1>
                                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, dolore?</p>
                            </div>
                        </div>
                    </div>
                </div> 
              </div>
        
              <div class="item">
                  <div class="process-container">
                      <img src="http://www.ucl.ac.uk/european-institute/events/2016-17/Ocean.png" style="object-fit: cover; height:100vh; width:100%;">
                      <div class="vertical-center">
                          <div class="circle vertical-center">
                              <div class="circle-text">
                                  <h1>Test3</h1>
                                  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, dolore?</p>
                              </div>
                          </div>
                      </div>
                  </div> 
                </div>
          </div>
        
          <!-- Left and right controls -->
          <a class="left carousel-control" href="#processCarousel" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left"></span>
            <span class="sr-only">Previous</span>
          </a>
          <a class="right carousel-control" href="#processCarousel" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right"></span>
            <span class="sr-only">Next</span>
          </a>
        </div>
      </div>
  </div>
</body>
&#13;
<div id="mainContent" class="row">
    <div class="valign-wrapper">
        <div id="root" class="col s12 xl l6"></div>
    </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

试试这个。这对你有帮助。

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

.vertical-center{
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
}

.circle{
  background-color: #ff9933;
  z-index: 300;
  height: 200px;
  width:200px;
  border-radius: 50%;
}

.process-container {
  position: relative;
  height: 100vh;
  width: 100%;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
}

.circle-text {
  text-align: center;
  color: white;
  font-family: 'Muli', sans-serif;
  font-weight: 200;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Muli:200,300,400" rel="stylesheet">
    <script src="app.js"></script>
</head>
<body>
  <div id="fullpage">
    <div id="process">

      <div id="processCarousel" class="carousel slide" data-ride="carousel">
          <!-- Indicators -->
          <ol class="carousel-indicators">
            <li data-target="#processCarousel" data-slide-to="1" class="active"></li>
            <li data-target="#processCarousel" data-slide-to="2"></li>
            <li data-target="#processCarousel" data-slide-to="3"></li>
          </ol>
        
          <!-- Wrapper for slides -->
          <div class="carousel-inner ">
            <div class="item active ">
              <div class="process-container" style="background-image: url('https://images.pexels.com/photos/127673/pexels-photo-127673.jpeg?auto=compress&cs=tinysrgb&h=350')">
                
                  <div class="vertical-center">
                      <div class="circle">
                          <div class="circle-text">
                              <h1>Test</h1>
                              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, dolore?</p>
                          </div>
                      </div>
                  </div>
              </div> 
            </div>
        
            <div class="item">
                <div class="process-container" style="background-image: url('http://worldlandforms.com/landforms/wp-content/uploads/2015/03/Beach-1024x683.jpg')">
              
                    <div class="vertical-center">
                        <div class="circle">
                            <div class="circle-text">
                                <h1>Test2</h1>
                                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, dolore?</p>
                            </div>
                        </div>
                    </div>
                </div> 
              </div>
        
              <div class="item">
                  <div class="process-container" style="background-image: url('http://www.ucl.ac.uk/european-institute/events/2016-17/Ocean.png')">
                   
                      <div class="vertical-center">
                          <div class="circle">
                              <div class="circle-text">
                                  <h1>Test3</h1>
                                  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, dolore?</p>
                              </div>
                          </div>
                      </div>
                  </div> 
                </div>
          </div>
        
          <!-- Left and right controls -->
          <a class="left carousel-control" href="#processCarousel" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left"></span>
            <span class="sr-only">Previous</span>
          </a>
          <a class="right carousel-control" href="#processCarousel" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right"></span>
            <span class="sr-only">Next</span>
          </a>
        </div>
      </div>
  </div>
</body>