html - 为什么我的绝对定位元素在某些情况下放错了位置?

标签 html css twitter-bootstrap-3

我有一个帖子列表,我使用 ng-repeat 和 bootstrap 网格为每个帖子创建单独的行。在这些里面,我有一个字体超棒的图标书签,该图标顶部的文本具有绝对定位。它们都相对于它们所在的 div class='image-wrapper' 具有相对定位。我的问题是日期的绝对定位在视觉上似乎有所不同,即使 css 相同。

<div ng-repeat="post in $ctrl.posts | filter:{category:'tournament'}">
    <div class="row">
      <div class="col-12 col-sm-6">
          <img src="{{post.photo_link}}" class='img-fluid pb-3'></img>
      </div><!--End od col-sm-6-->
      <div class="col-12 col-sm-6">
          <div class="row">
              <div class="col-12">
                  <h2 class='zaffre text-center h5' ng-bind="post.title"></h2>
              </div><!--End of col-12-->
              <div class="col-12 text-center image-wrapper">
                <i class="fa fa-bookmark fa-5x zaffre" aria-hidden="true"></i>
                <div class='month-wrapper'><span ng-bind="post.date | date:'MMM'"></span></div>
                <div class='date-wrapper'><span ng-bind="post.date | date:'dd'"></span></div>
                <p class='text-sm-left mt-2' ng-bind="post.body"></p>
              </div>         
          </div><!--End of row-->

      </div><!--End od col-sm-6-->
    </div><!--End of row-->
  </div><!--End of ng-repeat-->

CSS

.image-wrapper{
position:relative;

.month-wrapper{
   position:absolute;
   top:4%;
   left:45%;
   color:white;
}

.date-wrapper{
   position:absolute;
   top:12%;
   left:48%;
   color:white;
}

enter image description here

最佳答案

问题是您的最高值 (12%) 会根据框的高度而变化。由于这个原因,百分比值是不可靠的。相反,使用像素值或重新设计布局以使用填充或其他定位机制。

关于html - 为什么我的绝对定位元素在某些情况下放错了位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47422983/

相关文章:

javascript - 我有两个 bootstrap 弹出式旋转木马,但它们相互重叠,不能独立使用,我该如何解决这个问题?

html - 如何围绕圆边旋转对象(div)?仅 CSS

javascript - 滚动条是否在不使用 Javascript 的情况下滚动到底部?

javascript - 一个接一个的多个 Bootstrap Modals

javascript - Bootstrap/Javascript/JQuery 使按钮一次改变一种颜色

css - HTML5 CSS 和 Rails 模板

html - 如何在 HTML 中的段落末尾(3 行)制作星号

javascript - 使用 jQuery,如何将信息存储在动态创建的 div 中?

jquery - 我应该如何解决这个 css-hack 问题?

html - 在悬停时出现的 div 中出现文本时遇到问题