html - 当 'top' 值更改时,文本不会留在父 div 中

标签 html css twitter-bootstrap

我有一些图像想显示在我的文本后面,我希望文本在父 div 中居中(水平和垂直居中),但是每当我将“顶部”值更改为 50% 时,文本会跳转到在其父 div 之外的页面顶部。

我正在使用 Bootstrap。

.row_comm {
        .community-body{
          position: absolute;
          top: 50%;   
        }
        img {
          display: block;
          width: 100%;
        }
    }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
 
 <div class="row row_comm">
      <div class="container">
        <div class="col-lg-4 col-lg-offset-2">
          <img src="https://via.placeholder.com/100x100" class="active">
          <img src="https://via.placeholder.com/100x100" class="inactive">
          <img src="https://via.placeholder.com/100x100" class="inactive">
        </div>
        <div class="community-body">
          <div class="row">
            <div class="col-lg-6 col-lg-offset-4">
              <h1>Join.</h1>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-5 col-lg-offset-7">
              <p class="lead">Some text.</p>
            </div>
          </div>
        </div>
      </div>
    </div>

最佳答案

您需要分配相对于 community-block 父级的位置,因此在这种情况下将 row_com 设置为 position: relative

关于html - 当 'top' 值更改时,文本不会留在父 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55007719/

相关文章:

jQuery 移动元素并页面闪烁

javascript - 删除文件,文件属性无法读取未定义

css - 在单个页面上使用多个 z-index

html - Bootstrap 固定导航栏、粘性页脚、动态缩放内容

javascript - 为什么我的输入框的值没有被返回?

jquery - 显示折叠面板并编辑其他面板类

php - 提交表单方法get时保留$_GET ['p']

javascript - 当没有 Javascript 时使网站无响应

css - 显示内联容器上不需要的水平滚动

css - Bootstrap 3 - 没有插入符号和上圆 Angular 的下拉登录表单