没有定义高度和内容的垂直居中div

时间:2016-06-26 02:56:32

标签: html css wordpress

我有一个Wordpress网站,我想在Jumbotron div中垂直居中内容(网站使用Bootstrap框架)如果可能的话没有表格,因为它破坏了jumbotron中的其他功能。

编辑:子div居中但内部的内容不是

HTML

...
<div class="row">
    <div class="jumbotron" background-image:url('...');">
        <div id="s-text">               
            <?php echo $content ?>  (function to generate content not shown)
        </div>
    </div>    
</div>

CSS

.jumbotron { 
position: relative;
min-height: 600px; 
width: 100%;
border-radius: 0 !important;
margin: 0; padding: 0;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}

#s-text { 
position: absolute; 
text-align: center;
margin: auto;
max-width: 60%;
top: 0; right: 0; left: 0; bottom: 0; 
transform:translateY(-50%) 
}

.jumbotron {
  position: relative;
  min-height: 600px;
  width: 100%;
  margin: 0;
  padding: 0;
  border-radius: 0 !important;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
}
#s-text {
  position: absolute;
  display: inline-block;
  text-align: center;
  margin: auto;
  max-width: 60%;
  top: 50%;
  right: 0;
  left: 0;
  bottom: 0;
  transform: translateY(-50%)
}
#s-text p {
  position: relative;
  font-weight: 500;
  font-size: 1em;
  line-height: 1.4em;
  color: #fff;
}
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
  <div class="jumbotron">
    <div id="s-text">
      <p>content content content content content content content content content content content content content content content content content content content content content</p>
    </div>
  </div>
</div>
<!-- end of s-txt-->

0 个答案:

没有答案