html - 具有悬停覆盖的等宽 + 高度响应式 div

标签 html css twitter-bootstrap hover responsive

我无法使我的 div 的高度匹配。我需要它们使 div 的高度与最多的内容相匹配——这通常很容易,但我正在使用还包含更多文本的叠加层来执行此操作。我不能用固定的高度或宽度来做,因为我需要布局来响应。单元格基本上需要是 col-md-2,文本换行时高度最高,它更像是一个正方形,col-sm-6 是长而窄的,col-xs-12 也是长而狭窄的。

enter image description here

它不一定是 Bootstrap ,但它需要具有这种效果。另一个问题是我需要尽可能多地内联,因为我将它交付给客户以粘贴到他们的 drupal 站点,而无需访问后端,所以请忽略我的粗内联代码。

我几乎明白了,叠加层有效,高度由内容决定,但我无法让高度与最长的相匹配。谁能看出我在这里做错了什么??

#table{ 
    display: table;
    border-collapse: collapse;
    width: 100%;
}
.tr{ 
    display: table-row; 
}
.td{ 
    display: table-cell;
    vertical-align: top;
    text-align: center;
    height: 100%;
    }
    

.overlay {
  position: absolute;
  vertical-align: middle;
  top: 50%;
  left: 50%;
  height: 100%;
  width: 100%;
  background-image: url('https://premium.wpmudev.org/blog/wp-content/uploads/2015/02/fullwidth-small.png');
  background-position: center top;
  background-size: 500% auto;
  opacity: 1;
  transition: .5s ease;
}

.overlay:hover {
  opacity: 0;
}

.text {
  color: white;
  height: 100%;
  top: 50%;
  left: 50%;
  font-size: 20px;
  position: absolute;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
  opacity: 1;
}

.text:hover {
  opacity: 0;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
 
}

.cell {
  font-size: 14px;
  
}
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

<div id="table" style="width: 100%">
        <div class="td col-md-12" style="background-image: url('https://premium.wpmudev.org/blog/wp-content/uploads/2015/02/fullwidth-small.png');
  background-position: center top;
  background-size: 500% auto;  text-align: center; padding-top: 10%; padding-bottom: 10%">test</div>
    </div>
   
<div id="table">    
   

 
    
        <div class="td col-md-2 col-md-offset-1 col-sm-6 col-xs-12" 
        style="color: #0169A9;  -webkit-box-shadow:inset 0px 0px 0px 6px #0169A9; -moz-box-shadow:inset 0px 0px 0px 6px #0169A9;
    box-shadow:inset 0px 0px 0px 6px #0169A9;       font-size: 14px;
    font-weight: bold;
    margin-top: 15px;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 1.2;">To find out more about the making of this toolkit, click here
        <div class="overlay text">
         Test this
      </div>
      </div>
      
      
      
        <div class="td col-md-2 col-sm-6 col-xs-12"  style="color: #0169A9;  -webkit-box-shadow:inset 0px 0px 0px 6px #0169A9; -moz-box-shadow:inset 0px 0px 0px 6px #0169A9;
    box-shadow:inset 0px 0px 0px 6px #0169A9;       font-size: 14px;
    font-weight: bold;
    margin-top: 15px;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 1.2;">To find out more about the making of this toolkit
        <div class="overlay text">
         Test this
      </div>
      </div>
        
        
        <div class="td col-md-2 col-sm-6 col-xs-12"  style="color: #0169A9;  -webkit-box-shadow:inset 0px 0px 0px 6px #0169A9; -moz-box-shadow:inset 0px 0px 0px 6px #0169A9;
    box-shadow:inset 0px 0px 0px 6px #0169A9;       font-size: 14px;
    font-weight: bold;
    margin-top: 15px;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 1.2;">To find out more about the making of this toolkit, click here toolkit, click here
        <div class="overlay text">
         Test this
      </div>
      </div>
        
        
        
       <div class="td col-md-2 col-sm-6 col-xs-12"  style="color: #0169A9;  -webkit-box-shadow:inset 0px 0px 0px 6px #0169A9; -moz-box-shadow:inset 0px 0px 0px 6px #0169A9;
    box-shadow:inset 0px 0px 0px 6px #0169A9;       font-size: 14px;
    font-weight: bold;
    margin-top: 15px;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 1.2;">To find out more about the making of this toolkit, click here
        <div class="overlay text">
         Test this
      </div>
      </div>
        
        
        
       <div class="td col-md-2 col-sm-6 col-xs-12"  style="color: #0169A9;  -webkit-box-shadow:inset 0px 0px 0px 6px #0169A9; -moz-box-shadow:inset 0px 0px 0px 6px #0169A9;
    box-shadow:inset 0px 0px 0px 6px #0169A9;       font-size: 14px;
    font-weight: bold;
    margin-top: 15px;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 1.2;">To find out more about the making of this toolkit, click here
        <div class="overlay text">
         Test this
      </div>
      </div>
        
        
       
        <div class="clear-all">
         </div>

    
</div>
</body>

最佳答案

对不起,我很忙,这是一个工作示例:

//we need to iterate through row childs
$('.row').each(function() {
    //Set a var to store the highest height
    var maxHeight = 0;
    //Then, we iterate through all cols inside the row, searching for the highest one.
    $('.col-xs-4', this).each(function() {
        if($(this).height() > maxHeight) {
         maxHeight = $(this).height();  
        }
    });
    //Now, we have the height value of the highest one, so we can apply this height to all row childs.
    $('.col-xs-4', this).each(function() {
        $(this).height(maxHeight); 
     });
});
.col-xs-4{
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">


<div class="container-fluid">
  <div class="row">
    <div class="col-xs-4">
      <p>text</p>
      <p>text</p>
      <p>text</p>
    </div>
    <div class="col-xs-4">
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
    </div>
    <div class="col-xs-4">
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
    </div>
  </div>
</div>

关于html - 具有悬停覆盖的等宽 + 高度响应式 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49178088/

相关文章:

css - React-Bootstrap 中的面板标题大小没有改变

jquery - 在 div 上设置最大高度

html - 在移动 View 中放大的视差背景图像

Javascript 秒表自动启动

html - 缺少底部的网络表单

jquery - 在小型设备上将菜单更改为按钮

javascript - Bootstrap 表详细信息 View 没有加号图标

javascript - 仅显示一行带有 css 的元素,与用户分辨率无关?

twitter-bootstrap - 如何使用 Visual Studio 2013 设置 Bootstrap SASS/SCSS?

css - Bootstrap 圆形响应图像未调整到相同的圆圈大小