意外的css位置:绝对行为

问题描述 投票:0回答:1

我的css位置有问题。例如,当我在元素上设置position absolute时,它们会在页面上获得空间但不会显示。我的代码如下所示(我在我用过的一些旧的tabb框上做过)。希望有人知道这个解决方案,任何帮助将不胜感激!

$(".tabBoxContainer").css({
  "position": "absolute",
  "top": "50px",
  "float": "none",
  "z-index": "100"
});
#tabBoxContent {
  position: relative;
  top: 50px;
  overflow: auto;
}

.tabBoxContainer {
  position: relative;
  float: left;
  color: #232323;
}

.fixedTabContent {
  position: absolute !important;
  top: 50px !important;
  left: 0 !important;
}

.tabBoxArticle {
  float: left;
  width: 33%;
  box-sizing: border-box;
  padding: 10px;
}

.tabBoxArticle img {
  width: 90%;
}

.tabBoxArticle h1 a {
  color: #222 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="tabBoxContent">
  <div class="tabBoxContainer" id="tabBoxHTML">
    <div class="tabBoxArticle">
      <img src="img/juneca-rebra.jpg" alt="">
      <h1><a href="#">Lorem ipsum dolor sit amet</a></h1>
    </div>
    <div class="tabBoxArticle">
      <img src="img/jaja-sa-sunkom.jpg" alt="">
      <h1><a href="#">Lorem ipsum dolor sit amet</a></h1>
    </div>
    <div class="tabBoxArticle">
      <img src="img/keciga.jpg" alt="">
      <h1><a href="#">Lorem ipsum dolor sit amet</a></h1>
    </div>
  </div>
  <!-- /#tabBoxContainer -->
  <div class="tabBoxContainer" id="tabBoxCSS">
    <div class="tabBoxArticle">
      <img src="img/piletina-na-mlimarski-nacin.jpg" alt="">
      <h1><a href="#">Somme dummy long article title</a></h1>
    </div>
    <div class="tabBoxArticle">
      <img src="img/pohovana-paprika.jpg" alt="">
      <h1>Somme dummy long article title</h1>
    </div>
    <div class="tabBoxArticle">
      <img src="img/pohovani-sir.jpg" alt="">
      <h1>Somme dummy long article title</h1>
    </div>
  </div>
  <!-- /#tabBoxContainer -->
  <div class="tabBoxContainer" id="tabBoxJQuery">
    <div class="tabBoxArticle">
      <img src="img/rriblji-paprikas.jpg" alt="">
      <h1>Dummy long article title</h1>
    </div>
    <div class="tabBoxArticle">
      <img src="img/sat1.jpg" alt="">
      <h1></h1>
    </div>
    <div class="tabBoxArticle">
      <img src="img/satova-zakuska.jpg" alt="">
      <h1>Dummy long article title</h1>
    </div>
  </div>
  <!-- /#tabBoxContainer -->
</section>
<!-- /#tabBoxContent -->

我也试过用jquery添加一个类,但是当我设置绝对值时它不会显示它。

javascript jquery html css positioning
1个回答
1
投票

这是你的#tabBoxContent CSS打破它。如果你删除overflow: auto,它应该使绝对定位的元素再次显示。

然后,基于你的问题,或者你为什么首先把overflow: auto放在它上面,你正在努力实现的目标并不明显。

© www.soinside.com 2019 - 2024. All rights reserved.