gpt4 book ai didi

javascript - 页脚 div 位于另一个 div 之下

转载 作者:行者123 更新时间:2023-11-29 17:49:47 25 4
gpt4 key购买 nike

我有一个包含一些文本的 div 和另一个我用照片列表和页脚 div 填充的。页脚 div 应该在照片 div 下面,但它却在照片下面。这是我的代码:

div.gallery {
margin: 5px;
border: 2px solid #ccc;
float: left;
width: 280px;
}

div.gallery:hover {
border: 2px solid #777;
}

div.gallery img {
width: 80%;
height: auto;
margin: auto;
}

div.desc {
padding: 15px;
text-align: left;
}
<div>
<p>Software Engineer
</div>

<div id="test">
<div id="comments">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>

<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>

<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
<div id="footer" style="background:blue;height:100px;width:100%">
<div style="background:blue;height:200px;width:100%"></div>
</div>

这里是截图

enter image description here

我该如何解决?

最佳答案

问题可能是因为 float 。尝试使用 Clearfix

尝试将此类添加到评论中。(修改了部分HTML)

试一试。

HTML

<div>
<p>Software Engineer
</div>

<div id="test">
<div id="comments" class="clearfix">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>

<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>

<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
</div>

<div id="footer" style="background:blue;width:100%">
<div style="background:blue;width:100%"> footer div here</div>
</div>

CSS

.clearfix::after {
content: "";
display: table;
width: 100%;
clear: both;
}

div.gallery {
margin: 5px;
border: 2px solid #ccc;
float: left;
width: 280px;
}

div.gallery:hover {
border: 2px solid #777;
}

div.gallery img {
width: 80%;
height: auto;
margin: auto;
}

div.desc {
padding: 15px;
text-align: left;
}

.clearfix::after {
content: "";
width: 100%;
display: table;
clear: both;
}
<div>
<p>Software Engineer
</div>

<div id="test">
<div id="comments" class="clearfix">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>

<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>

<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
</div>

<div id="footer" style="background:blue;width:100%">
<div style="background:blue;width:100%"> footer div here</div>
</div>

Link for reference

希望这对您有所帮助...

关于javascript - 页脚 div 位于另一个 div 之下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45098622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com