这里是JSFiddle,可以更好地了解我的问题。 当由黄色分隔符分隔的两个列表之一变长时,会显示浏览器的垂直滚动条,这很好。但是,当您向下滚动到非常底部时,将不会显示文本 Example_2.1 ,因为 ATTENTION隐藏了该文本!框,其位置为:固定; 值。
.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>
我如何在 ATTENTION!框的上方上设置边距,以便始终看到列表的最后一行? 重要的是,列表本身的参数(例如行或段落之间的间隔)必须保持相同。
谢谢!
答案 0 :(得分:2)
这是使用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 */
}
答案 1 :(得分:1)
您可以将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>