简体   繁体   English

当我应用“边距:自动”时,页脚不居中

[英]Footer doesn't center when I apply 'margin: auto'

I've tried this and the footer doesn't center.我试过这个,页脚没有居中。 I tried to put display: block or inline-block but that doesn't serve me either.我试图放置 display: block 或 inline-block 但这也不适合我。

HTML: HTML:

<div id="secondfooter">
   <p>COPYRIGHT 2020 HYUNDAI AUTO ROMANIA. TOATE DREPTURILE REZERVATE.</p>
</div>

CSS: CSS:

#secondfooter {

    width: 900px;
    margin: auto;
    font-size: 13px;
    background: #c00000;
    font-family: arial;
    text-align: center;
    color: white;
    float: left;
}

Here is jsfiddle link:这是jsfiddle链接:

https://jsfiddle.net/bogdan9/o14p39ek/ https://jsfiddle.net/bogdan9/o14p39ek/

Try by removing float left, it should work:尝试通过删除浮动左侧,它应该工作:

#secondfooter {
    width: 900px;
    margin: auto;
    font-size: 13px;
    background: #c00000;
    font-family: arial;
    text-align: center;
    color: white;
}

I removed it and it looks working to me.我删除了它,它看起来对我有用。

Use flexbox and width: 100%.使用 flexbox 和宽度:100%。 No matter what screen are you on, it will be in center.无论您在哪个屏幕上,它都会在中心。

 #secondfooter { margin: auto; font-size: 13px; background: #c00000; font-family: arial; color: white; width: 100%; display: flex; align-items: center; justify-content: center; }
 <div id="secondfooter"> <p>COPYRIGHT 2020 HYUNDAI AUTO ROMANIA. TOATE DREPTURILE REZERVATE.</p> </div>

give width: 100% to #secondfooterwidth: 100%#secondfooter

#secondfooter {
  width: 100%;
  margin: auto;
  font-size: 13px;
  background: #c00000;
  font-family: arial;
  text-align: center;
  color: white;
}

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

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