2 个元素之间的边距,其中一个具有 "position: fixed;"

Margin between 2 elements, one of which has "position: fixed;"

这里是JSFiddle 以更好地理解我的问题。 当由黄色分隔线分隔的两个列表中的任何一个变长时,浏览器的垂直滚动条就会出现,这很好。但是,当您向下滚动到 very 底部时,文本 Example_2.1 将不可见,因为它被 ATTENTION! 框隐藏,该框具有 position: fixed; value.

.divider {
  border-bottom: 2px solid #fec303;
  margin-top: 15px;
  margin-bottom: 25px;
}

.meanings_and_examples {
  display: flex;
  flex-direction: column;
}

ol.circle {
  list-style-type: none;
}

li {
  line-height: 1.6;
}

ol.circle>li {
  counter-increment: item;
  margin-bottom: 2px;
  margin-left: 2.5em;
}

ol.circle>li::before {
  margin-right: 1em;
  margin-left: -2.7em;
  content: counter(item);
  background: #1f2c60;
  border-radius: 100%;
  color: white;
  width: 1.7em;
  text-align: center;
  display: inline-block;
}

ul {
  list-style-type: none;
  padding-bottom: 10px;
  padding-left: 2.5em;
}

.meaning {
  font-family: Tahoma, Geneva, sans-serif;
  width: auto;
  text-align: left;
  color: #1f2c60;
  text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.2);
  font-size: 3vw;
  font-weight: 700;
}

.example {
  width: auto;
  text-align: left;
  font-style: italic;
  font-weight: 400;
}

.example_translated {
  width: auto;
  text-align: left;
  color: #5d78e5;
}

.comment_box {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: fixed;
  bottom: 0;
  text-align: left;
  background: #fff8e5;
}

.comment_title {
  font-family: Verdana, Geneva, sans-serif;
  color: rgba(231, 237, 22, 0.58);
  margin-top: 8px;
  margin-left: 10px;
  text-shadow: 0 0 0.5em #f92504, 0 0 0.5em #f92504, 0 0 0.5em #f92504;
  font-size: 3vw;
  font-weight: 700;
}

.comment_text {
  width: auto;
  font-family: Tahoma, Geneva, sans-serif;
  color: #1f2c60;
  margin: 15px 10px 20px;
  text-shadow: none;
  font-size: 2vw;
  font-weight: 400;
}
<div class="meaning">
  <ol class="circle">
    <li>Text_1</li>
    <div class="example">
      <ul>
        <li>Example_1.1</li>
      </ul>
    </div>
    <li>Text_2</li>
    <div class="example">
      <ul>
        <li>Example_2.1</li>
        <li>Example_2.2</li>
      </ul>
    </div>
  </ol>
</div>

<div class="divider"></div>

<div class="meaning">
  <ol class="circle">
    <li>Text_1</li>
    <div class="example">
      <ul>
        <li>Example_1.1</li>
      </ul>
    </div>
    <li>Text_2</li>
    <div class="example">
      <ul>
        <li>Example_2.1</li>
      </ul>
    </div>
  </ol>
</div>

<div class="comment_box">
  <div class="comment_title">ATTENTION!
  </div>
  <div class="comment_text">Comment: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...
  </div>
</div>

如何在注意!上方 设置边距,以便始终看到列表的最后一行? 列表本身的参数(如行或段落之间的间隔)保持与现在相同是很重要的。

谢谢!

您可以将您的 HTML 代码包装在 div 中并给它一个 margin-bottom,如下所示:

.divider {
  border-bottom: 2px solid #fec303;
  margin-top: 15px;
  margin-bottom: 25px;
}

.meanings_and_examples {
  display: flex;
  flex-direction: column;
}

ol.circle {
  list-style-type: none;
}

li {
  line-height: 1.6;
}

ol.circle > li {
  counter-increment: item;
  margin-bottom: 2px;
  margin-left: 2.5em;
 }

ol.circle > li::before {
  margin-right: 1em;
  margin-left: -2.7em;
  content: counter(item);
  background: #1f2c60;
  border-radius: 100%;
  color: white;
  width: 1.7em;
  text-align: center;
  display: inline-block;
 }

ul {
  list-style-type: none;
  padding-bottom: 10px;
  padding-left: 2.5em;
}

.meaning {
  font-family: Tahoma, Geneva, sans-serif;
  width: auto;
  text-align: left;
  color: #1f2c60;
  text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.2);
  font-size: 3vw;
  font-weight: 700;
}

.example {
  width: auto;
  text-align: left;
  font-style: italic;
  font-weight: 400;
}

.example_translated {
  width: auto;
  text-align: left;
  color: #5d78e5;
}

.comment_box {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: fixed;
  bottom: 0;
  text-align: left;
  background: #fff8e5;
}

.comment_title {
  font-family: Verdana, Geneva, sans-serif;
  color: rgba(231, 237, 22, 0.58);
  margin-top: 8px;
  margin-left: 10px;
  text-shadow: 0 0 0.5em #f92504, 0 0 0.5em #f92504, 0 0 0.5em #f92504;
  font-size: 3vw;
  font-weight: 700;
}

.comment_text {
  width: auto;
  font-family: Tahoma, Geneva, sans-serif;
  color: #1f2c60;
  margin: 15px 10px 20px;
  text-shadow: none;
  font-size: 2vw;
  font-weight: 400;
}
<div  style="margin-bottom:100px">
<div class="meaning" >
<ol class="circle">
  <li>Text_1</li>
<div class="example">
   <ul>
      <li>Example_1.1</li>     
   </ul>
</div>
  <li>Text_2</li>
<div class="example">
   <ul>
      <li>Example_2.1</li>     
      <li>Example_2.2</li>     
   </ul>
</div>
</ol>
</div>

<div class="divider"></div>

<div class="meaning">
<ol class="circle">
  <li>Text_1</li>
<div class="example">
   <ul>
      <li>Example_1.1</li>     
   </ul>
</div>
  <li>Text_2</li>
<div class="example">
   <ul>
      <li>Example_2.1</li>     
   </ul>
</div>
</ol>
</div>
</div>
<div class="comment_box">
<div class="comment_title">ATTENTION!
</div>
<div class="comment_text">Comment: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...
</div>
</div>

这是您可以使用 JS 实现的方法。这样做是获取 comment-box 的高度,然后在最后一个 meaning div.

上设置边距

// Need to set an id on the comment-box. Now we select it.
let comment_box = document.getElementById('comment-box');
// Get the comment_box calculated height
let comment_box_height = comment_box.clientHeight;
// Gather all of the .meaning divs.
let meaning_array = document.querySelectorAll('.meaning');
// get the last meaning div from the node list.
let last = [].slice.call(meaning_array).pop();
// set the margin on the last meaning div.
last.style.marginBottom = comment_box_height + 'px';
.divider {
  border-bottom: 2px solid #fec303;
  margin-top: 15px;
  margin-bottom: 25px;
}

.meanings_and_examples {
  display: flex;
  flex-direction: column;
}

ol.circle {
  list-style-type: none;
}

li {
  line-height: 1.6;
}

ol.circle>li {
  counter-increment: item;
  margin-bottom: 2px;
  margin-left: 2.5em;
}

ol.circle>li::before {
  margin-right: 1em;
  margin-left: -2.7em;
  content: counter(item);
  background: #1f2c60;
  border-radius: 100%;
  color: white;
  width: 1.7em;
  text-align: center;
  display: inline-block;
}

ul {
  list-style-type: none;
  padding-bottom: 10px;
  padding-left: 2.5em;
}

.meaning {
  font-family: Tahoma, Geneva, sans-serif;
  width: auto;
  text-align: left;
  color: #1f2c60;
  text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.2);
  font-size: 3vw;
  font-weight: 700;
}

.example {
  width: auto;
  text-align: left;
  font-style: italic;
  font-weight: 400;
}

.example_translated {
  width: auto;
  text-align: left;
  color: #5d78e5;
}

.comment_box {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: fixed;
  bottom: 0;
  text-align: left;
  background: #fff8e5;
}

.comment_title {
  font-family: Verdana, Geneva, sans-serif;
  color: rgba(231, 237, 22, 0.58);
  margin-top: 8px;
  margin-left: 10px;
  text-shadow: 0 0 0.5em #f92504, 0 0 0.5em #f92504, 0 0 0.5em #f92504;
  font-size: 3vw;
  font-weight: 700;
}

.comment_text {
  width: auto;
  font-family: Tahoma, Geneva, sans-serif;
  color: #1f2c60;
  margin: 15px 10px 20px;
  text-shadow: none;
  font-size: 2vw;
  font-weight: 400;
}
<div class="meaning">
  <ol class="circle">
    <li>Text_1</li>
    <div class="example">
      <ul>
        <li>Example_1.1</li>
      </ul>
    </div>
    <li>Text_2</li>
    <div class="example">
      <ul>
        <li>Example_2.1</li>
        <li>Example_2.2</li>
      </ul>
    </div>
  </ol>
</div>

<div class="divider"></div>

<div class="meaning">
  <ol class="circle">
    <li>Text_1</li>
    <div class="example">
      <ul>
        <li>Example_1.1</li>
      </ul>
    </div>
    <li>Text_2</li>
    <div class="example">
      <ul>
        <li>Example_2.1</li>
      </ul>
    </div>
  </ol>
</div>

<div class="comment_box" id="comment-box">
  <div class="comment_title">ATTENTION!
  </div>
  <div class="comment_text">Comment: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...
  </div>
</div>

另一种方法,如建议的那样,只需将静态边距设置为最后一个 meaning div。为此,您必须将它们包装在一个容器中,以便您可以使用伪 :last-child 选择器,例如:

.meaning:last-child {
    margin-bottom: 120px /* or whatever height you decide */
}