简体   繁体   English

页脚始终位于移动设备和桌面设备的底部CSS上

[英]footer always on bottom CSS on mobile and desktop

I was looking around how to add a footer to the bottom of the page in both mobile and desktop, I did attempt 我一直在寻找如何在移动设备和台式机页面底部添加页脚的方法,我确实尝试过

    .footer
{
    height: 40px; 
    width:100%; 
    background-color: #ffffff; 
    opacity: 1;
    border-top:1px solid #9a9696;
    position: relative;
    right: 0;
    bottom: 0;
    left: 0;
}

However this doesn't seem to work, there seems to be a gap between the bottom of the page and the footer 但是,这似乎不起作用,页面底部和页脚之间似乎存在间隙

remove relative and add fixed. 删除相对并添加固定。

html {
  height: 100%;
  box-sizing: border-box;
}
body {
  position: relative;
  margin: 0;
  padding-bottom: 6rem;
  min-height: 100%;
}

    .footer {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      padding: 1rem;
      background-color: #efefef;
      text-align: center;
    }

Try adding this code to your CSS. 尝试将此代码添加到CSS中。 Should make it work normally. 应该使其正常工作。

CSS: CSS:

.footer {
    height: 40px;
    width: 100%;
    background-color: #ffffff;
    opacity: 1;
    border-top: 1px solid #9a9696;
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
}

@media only screen and (max-width : 1100px){ /* You can edit the max-width value to match what you need */
  .footer {
    height: 40px;
    width: 100%;
    background-color: #ffffff;
    opacity: 1;
    border-top: 1px solid #9a9696;
    position: relative;
    right: 0;
    bottom: 0;
    left: 0;
    margin-top:30px; /* You can edit the value of the margin top as you need */
  }
}

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

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