Поля между 2 элементами, один из которых имеет «позиция: фиксированная»; - PullRequest
2 голосов
/ 27 октября 2019

Вот JSFiddle , чтобы лучше понять мою проблему. Когда один из двух списков, разделенных желтым разделителем, становится длинным, появляется вертикальная полоса прокрутки браузера, что нормально. Однако, когда вы прокрутите вниз до очень , текст Example_2.1 не будет виден, потому что он скрыт ВНИМАНИЕ! поле, которое имеет положение : фиксированное; значение.

.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>

Как установить поле на выше поля ВНИМАНИЕ! , чтобы последняя строка списка былавсегда видел? Важно, чтобы параметры самого списка (например, интервалы между строками или абзацами) остались такими же , как и сейчас.

Спасибо!

Ответы [ 2 ]

2 голосов
/ 27 октября 2019

Вот как вы можете сделать это с JS. То, что это делает, получает высоту comment-box и затем устанавливает поле для последнего meaning деления.

// 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 деления. Для этого вам нужно будет обернуть их в контейнер, чтобы вы могли использовать псевдо :last-child селектор, например:

.meaning:last-child {
    margin-bottom: 120px /* or whatever height you decide */
}
1 голос
/ 27 октября 2019

Вы можете обернуть ваш HTML-код в div и задать ему нижнее поле, как показано ниже:

.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>
...