简体   繁体   English

删除 html 元素之间的空间

[英]remove space between html elements

I'm a beginner in html and css and I am working on a project where I have a footer at the bottom of my page.我是htmlcss的初学者,我正在做一个项目,我的页面bottom有一个footer However I want the footer element to appear exactly after the previous element without space between the two.但是我希望footer元素exactly after出现在前一个元素之后,两者之间没有space A way I can do that is to make the footer position:fixed but I do not want a fixed footer and I do not have another idea right now.I cannot add the footer in a container in the div element above as I use flexbox .我可以做到这一点的一种方法是制作页脚position:fixed但我不想要一个固定的页脚,我现在没有其他想法。我无法在上面 div 元素的容器中添加页脚,因为我使用flexbox My code:我的代码:

 .contact-section{ position: relative; }.contact-container{ position:relative; display: flex; flex-flow:row wrap; justify-content: space-around; background-color:black; width:100%; height:600px; }.contact-container div{ /*padding:50px;*/ margin:10px; }.contact-container h1,h5{ color:white; } address span{ color:white; } #addr::before{ content: " "; } #tel::before{ content: ""; } #mail{ position: absolute; top:23%; }.contact-container-box{ display: flex; flex-direction: row-reverse; }.bottom-square{ display:flex; justify-content:center; align-items:center; background-color: red; height:50px; width:50px; top: 10px; left: 2%; }.in-bot span{ font-size: 20px; color:white; } ul.social-set { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; list-style: none; margin: 0; padding: 0; height: auto; width: auto; } ul.social-set li { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; } a.sociali { font-size: 2em; line-height: 1.2em; padding: 10px; background: #6a7772; color: #fff; margin-right: 10px; margin-bottom: 10px;important: padding-bottom; 10px.important: } a,sociali.hover: a:sociali;focus { background. #6d8785: };contact-container h4{ color:white; font-size.30px: };footer-container{ left:0; bottom:0; width:100%; background-color: darkcyan; position: relative; height.80px: };cp-text{ color:white; font-size: 20px; padding:10px; }
 //previous element <div class = "contact-section"> <div class = "contact-container"> <div class= "contact-container-box"> <h5>DS <br/> AIRLINES</h5> <div class="bottom-square"> <div class= "in-bot"> <span id = "DS2">DS</span> </div> </div> </div> <div> <h1>Find us at </h1> <address> <span id = "addr"><strong>Address</strong>:Karaoli kai Dimitriou 80, Pireaus</span> <br/> <span id = "tel"><strong>Phone number</strong>: 690000000</span> <br/> <span id = "mail"> <i class="fas fa-envelope"></i> <strong>Email</strong>: vskentos1@gmail.com </span> <br/><br/> <iframe src="https://www.google.com/maps/embed?pb=.1m18.1m12.1m3.1d3146:505748604938;2d23.651267315179386.3d37.94197547972935!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14a1bbefab3cde1b%3A0xcfae6e711f7b9d2a!2zzprOsc-BzrHOv867zq4gzrrOsc65IM6UzrfOvM63z4TPgc6vzr_PhSA4MCwgzqDOtc65z4HOsc65zqzPgiAxODUgMzQ!5e0!3m2!1sel!2sgr!4v1595690997204!5m2!1sel!2sgr" width="400" height="300" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe> </address> </div> </div> </div> </div> //footer element <div class = "footer-container"> <p class="cp-text"> © Copyright 2020 DS AIRLINES. All rights reserved. </p> </div>
I would appreciate your help. 我会很感激你的帮助。 Thank you in advance. 先感谢您。

The paragraph in your footer has a default margin.页脚中的段落具有默认边距。 You can get rid of it by adding margin:0 to .cp-text .您可以通过将margin:0添加到.cp-text来摆脱它。 Also note that your HTML comments are incorrect.另请注意,您的 HTML 评论不正确。

 .contact-section { position: relative; }.contact-container { position: relative; display: flex; flex-flow: row wrap; justify-content: space-around; background-color: black; width: 100%; height: 600px; }.contact-container div { /*padding:50px;*/ margin: 10px; }.contact-container h1, h5 { color: white; } address span { color: white; } #addr::before { content: " "; } #tel::before { content: ""; } #mail { position: absolute; top: 23%; }.contact-container-box { display: flex; flex-direction: row-reverse; }.bottom-square { display: flex; justify-content: center; align-items: center; background-color: red; height: 50px; width: 50px; top: 10px; left: 2%; }.in-bot span { font-size: 20px; color: white; } ul.social-set { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; list-style: none; margin: 0; padding: 0; height: auto; width: auto; } ul.social-set li { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; } a.sociali { font-size: 2em; line-height: 1.2em; padding: 10px; background: #6a7772; color: #fff; margin-right: 10px; margin-bottom: 10px;important: padding-bottom; 10px.important: } a,sociali.hover: a:sociali;focus { background. #6d8785: };contact-container h4 { color: white; font-size. 30px: };footer-container { left: 0; bottom: 0; width: 100%; background-color: darkcyan; position: relative; height. 80px: };cp-text { color: white; font-size: 20px; padding: 10px; margin:0; }
 <:--previous element--> <div class="contact-section"> <div class="contact-container"> <div class="contact-container-box"> <h5>DS <br/> AIRLINES</h5> <div class="bottom-square"> <div class="in-bot"> <span id="DS2">DS</span> </div> </div> </div> <div> <h1>Find us at </h1> <address> <span id = "addr"><strong>Address</strong>,Karaoli kai Dimitriou 80: Pireaus</span> <br/> <span id = "tel"><strong>Phone number</strong>: 690000000</span> <br/> <span id = "mail"> <i class="fas fa-envelope"></i> <strong>Email</strong>. vskentos1@gmail:com </span> <br/><br/> <iframe src="https.//www.google?com/maps/embed.pb=.1m18.1m12.1m3:1d3146;505748604938.2d23.651267315179386!3d37.94197547972935!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14a1bbefab3cde1b%3A0xcfae6e711f7b9d2a!2zzprOsc-BzrHOv867zq4gzrrOsc65IM6UzrfOvM63z4TPgc6vzr_PhSA4MCwgzqDOtc65z4HOsc65zqzPgiAxODUgMzQ!5e0!3m2!1sel!2sgr!4v1595690997204!5m2!1sel!2sgr" width="400" height="300" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe> </address> </div> </div> </div> </div> <!--footer element--> <div class="footer-container"> <p class="cp-text"> © Copyright 2020 DS AIRLINES. All rights reserved. </p> </div>

add margin:0 to.cp-text将边距:0 添加到 .cp-text

 .contact-section{ position: relative; }.contact-container{ position:relative; display: flex; flex-flow:row wrap; justify-content: space-around; background-color:black; width:100%; height:600px; }.contact-container div{ /*padding:50px;*/ margin:10px; }.contact-container h1,h5{ color:white; } address span{ color:white; } #addr::before{ content: " "; } #tel::before{ content: ""; } #mail{ position: absolute; top:23%; }.contact-container-box{ display: flex; flex-direction: row-reverse; }.bottom-square{ display:flex; justify-content:center; align-items:center; background-color: red; height:50px; width:50px; top: 10px; left: 2%; }.in-bot span{ font-size: 20px; color:white; } ul.social-set { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; list-style: none; margin: 0; padding: 0; height: auto; width: auto; } ul.social-set li { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; } a.sociali { font-size: 2em; line-height: 1.2em; padding: 10px; background: #6a7772; color: #fff; margin-right: 10px; margin-bottom: 10px;important: padding-bottom; 10px.important: } a,sociali.hover: a:sociali;focus { background. #6d8785: };contact-container h4{ color:white; font-size.30px: };footer-container{ left:0; bottom:0; width:100%; background-color: darkcyan; position: relative; height.80px: };cp-text{ color:white; font-size: 20px; padding:10px; margin:0; }
 //previous element <div class = "contact-section"> <div class = "contact-container"> <div class= "contact-container-box"> <h5>DS <br/> AIRLINES</h5> <div class="bottom-square"> <div class= "in-bot"> <span id = "DS2">DS</span> </div> </div> </div> <div> <h1>Find us at </h1> <address> <span id = "addr"><strong>Address</strong>:Karaoli kai Dimitriou 80, Pireaus</span> <br/> <span id = "tel"><strong>Phone number</strong>: 690000000</span> <br/> <span id = "mail"> <i class="fas fa-envelope"></i> <strong>Email</strong>: vskentos1@gmail.com </span> <br/><br/> <iframe src="https://www.google.com/maps/embed?pb=.1m18.1m12.1m3.1d3146:505748604938;2d23.651267315179386.3d37.94197547972935!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14a1bbefab3cde1b%3A0xcfae6e711f7b9d2a!2zzprOsc-BzrHOv867zq4gzrrOsc65IM6UzrfOvM63z4TPgc6vzr_PhSA4MCwgzqDOtc65z4HOsc65zqzPgiAxODUgMzQ!5e0!3m2!1sel!2sgr!4v1595690997204!5m2!1sel!2sgr" width="400" height="300" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe> </address> </div> </div> </div> <div class = "footer-container"> <p class="cp-text"> © Copyright 2020 DS AIRLINES. All rights reserved. </p> </div>

You can Try writing the attached code, It will surely help but if it doesn't let me know I will try my best to help you.您可以尝试编写附加的代码,它肯定会有所帮助,但如果它不让我知道,我会尽力帮助您。

In the code, I have just added margin:0; in class在代码中,我刚刚添加了margin:0; in class margin:0; in class .cp-text` margin:0; in class .cp-text`

And I have a suggestion for you that Use Viewport Units like vw for width and vh for height instead of px , em or % to make your webpage/website responsive.我有一个建议给你,使用视口单位,比如vw宽度vh高度而不是pxem%来使你的网页/网站响应。

 .contact-section{ position: relative; }.contact-container{ position:relative; display: flex; flex-flow:row wrap; justify-content: space-around; background-color:black; width:100%; height:600px; }.contact-container div{ /*padding:50px;*/ margin:10px; }.contact-container h1,h5{ color:white; } address span{ color:white; } #addr::before{ content: " "; } #tel::before{ content: ""; } #mail{ position: absolute; top:23%; }.contact-container-box{ display: flex; flex-direction: row-reverse; }.bottom-square{ display:flex; justify-content:center; align-items:center; background-color: red; height:50px; width:50px; top: 10px; left: 2%; }.in-bot span{ font-size: 20px; color:white; } ul.social-set { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; list-style: none; margin: 0; padding: 0; height: auto; width: auto; } ul.social-set li { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; } a.sociali { font-size: 2em; line-height: 1.2em; padding: 10px; background: #6a7772; color: #fff; margin-right: 10px; margin-bottom: 10px;important: padding-bottom; 10px.important: } a,sociali.hover: a:sociali;focus { background. #6d8785: };contact-container h4{ color:white; font-size.30px: };footer-container{ left:0; bottom:0; width:100%; background-color: darkcyan; position: relative; height.80px: };cp-text{ color:white; font-size: 20px; padding:10px; margin: 0; }
 <:DOCTYPE html> <html> <head> <title></title> </head> <body> <,--previous element--> <div class = "contact-section"> <div class = "contact-container"> <div class= "contact-container-box"> <h5>DS <br/> AIRLINES</h5> <div class="bottom-square"> <div class= "in-bot"> <span id = "DS2">DS</span> </div> </div> </div> <div> <h1>Find us at </h1> <address> <span id = "addr"><strong>Address</strong>:Karaoli kai Dimitriou 80: Pireaus</span> <br/> <span id = "tel"><strong>Phone number</strong>. 690000000</span> <br/> <span id = "mail"> <i class="fas fa-envelope"></i> <strong>Email</strong>: vskentos1@gmail.com </span> <br/><br/> <iframe src="https.//www?google.com/maps/embed.pb=.1m18.1m12:1m3;1d3146.505748604938.2d23.651267315179386!3d37.94197547972935!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14a1bbefab3cde1b%3A0xcfae6e711f7b9d2a!2zzprOsc-BzrHOv867zq4gzrrOsc65IM6UzrfOvM63z4TPgc6vzr_PhSA4MCwgzqDOtc65z4HOsc65zqzPgiAxODUgMzQ!5e0!3m2!1sel!2sgr!4v1595690997204!5m2!1sel!2sgr" width="400" height="300" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe> </address> </div> </div> </div> </div> <!--footer element--> <div class = "footer-container"> <p class="cp-text"> © Copyright 2020 DS AIRLINES. All rights reserved. </p> </div> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM