html - 为什么我的位置绝对不起作用?

标签 html css twitter-bootstrap grid-layout

我正在尝试在我的网站上制作这个组件。我想在左边有一些文字,在右边有图片。它应该根据文本大小进行调整,并且必须始终位于底部。我认为这可以通过 position: absolutebottom: 0 实现。但它不起作用。它总是在我所在行的顶部,我不知道为什么。

.b-image {
  position: absolute;
  bottom: 0;
}

.over-image {
  position: relative;
}

.content-width {
  max-width: 1440px;
  min-width: 300px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
}

section {
  padding: 48px 0;
  border-bottom: 1px solid #0000ff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<section>
  <div class="row">
    <div class="content-width">
      <div class="content col-md-6">
        <h1>
          Headline
        </h1>
        <p>
          foo foo foo foo foo foo foo foo foo foo foo foo foo foo
        </p>
      </div>
      <div class="col-md-6 over-image">
        <img class="b-image" src="http://placehold.it/100x100" alt="">
      </div>
    </div>
  </div>
</section>

最佳答案

您可以使用 flex 实现这一点。删除 position: absolute 并将 display: flex;.content-widthalign-self: flex-end;.over-image

.over-image{
    position: relative;
    align-self: flex-end;
}
.content-width {
    max-width: 1440px;
    min-width: 300px;
    margin:    0 auto;
    padding:   0 24px;
    position:  relative;
    display: flex;

}

section {
    padding: 48px 0;
    border-bottom: 1px solid $primary-color-10;
}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  
  <section>
    <div class="row">
          <div class="content-width">
            <div class="content col-md-6">
                <h1>
                  Headline
                </h1>
                <p>
                foo foo foo foo foo foo foo foo foo foo foo foo foo foo
                </p>
                <h1>
                  Headline
                </h1>
                <p>
                foo foo foo foo foo foo foo foo foo foo foo foo foo foo
                </p>
                <h1>
                  Headline
                </h1>
                <p>
                foo foo foo foo foo foo foo foo foo foo foo foo foo foo
                </p>
            </div>
            <div class="col-md-6 over-image">
              <img class="b-image" src="http://placehold.it/200x200" alt="">
            </div>
        </div>
    </div>
</section>

关于html - 为什么我的位置绝对不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45631790/

相关文章:

.net - 使用 Html.TextBoxFor 时可以将文本框设置为只读吗?

html - Css 下拉菜单不显示

html - Font awesome stacking square 和 square-o 不对齐

css - 字体在 IE7 和 IE8 上不工作,在 IE9、10、Firefox 和所有其他浏览器上工作

html - bootstrap 4 中窗口宽度减小时如何包装容器以适合顶部容器下方?

css - svg 分组元素联合悬停

html - 使用 Bootstrap 使搜索输入宽度为 100%

html - Bootstrap - 水平滚动条

php - Codeigniter - Bootstrap Modal - 传递数据

javascript - Bootstrap 3 在 IE8 中不工作(检查其他答案)