简体   繁体   English

如何在本网站的末尾添加页脚?

[英]How can I add a footer at the end of this website?

I am trying to create a footer at the end of this website but for some reason it appears above the products :我正在尝试在本网站的末尾创建一个页脚,但由于某种原因,它出现在产品上方:

错误的页脚屏幕截图

And when I change the browser size :当我更改浏览器大小时:

调整大小的页面截图

But I want a footer like this :但我想要这样的页脚:

好的页脚截图

Here is my code :这是我的代码:

HTML : HTML:

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet"   href="{% static 'main.css' %}">
</head>
<body style="background-color: #36454F;">
    {% for i in p%} 
 
    <div class='card'>
      <div class="number">{{i.Number}}</div>
      <img src="{{i.image}}"></img>
      <p id="id">{{i.description}}</p>
      <a href="{{i.buy}}" target='_blank' rel='noopener noreferrer'>
        <button><span class="price"> ${{i.price}}</span> buy</button>
      </a>
    </div>
 
    {%endfor%}
    
    <div class="footer">
        <h3>hello</h3>
    </div>
</body>
</html>

CSS : CSS:

.card {
  max-width: 400px;
  margin: 0auto;
  text-align: center;
  font-family: arial;
  border-style: solid;
  border-width: 6px;
  position:  relative;
  top: 611px;
  margin-bottom: 33px;
  margin-right: 33px;
  justify-content: center;
  float: left;
}

.footer {
  position: relative;
  height: 130px;
  clear: both;
  background-color: red;
}

.card img {
  height: 400px;
  width: 400px;
  vertical-align: middle;
}

.price {
  background-color: #f44336;
  font-size:22px;
  border-radius: 3px;
  position: absolute;
  bottom: 0px;
  right: 0px;
  padding: 3px;
}

.card button {
  border: none;
  color: white;
  background-color: #000;
  position: relative ;
  cursor: pointer;
  width: 100%;
  height: 100px;
  font-size: 44px;
  align-items: center;
}

.card button:hover {
  opacity: .5;
  background-color: #330;
}

#id {
  background-color: palevioletred;
  color: white;
  margin: 0;
  font-size: 17px;
}

.number {
  width: 50px;
  height: 50px;
  background-color: #330;
  color: yellow;
  border-radius: 50%;
  position: absolute;
  top: -22px;
  right: -22px;
  justify-content: center;
  align-items: center;
  display: flex;
  font-size: 22px;
}

@media (max-width: 1864px) {
  .card {
    max-width: 300px;
  }

  .price {
    font-size:20px;
  }

  .card img {
    height: 300px;
    width: 300px;
  }
}

I tried to set a negative bottom property to push it to the end :我试图设置一个负的bottom属性将其推到最后:

.footer {
  position: relative;
  bottom: -674px;
  height: 130px;
  clear: both;
  background-color: red;
}

But it didn't help.但这没有帮助。 How can i solve the problem?我该如何解决这个问题?

To set the footer to the bottom of the page, you need to use this CSS:要将页脚设置为页面底部,您需要使用以下 CSS:

.footer {
   position:absolute;
   bottom:0;
   width:100%;
   height:60px;   /* Height of the footer */
   background:#6cf; /* Set your own background */
}

If you want it to stay at the bottom of the page and stretch along the bottom, I'd do something like this with the CSS如果你想让它留在页面底部并沿着底部伸展,我会用 CSS 做这样的事情

.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: (whatever you want);
color: (color of the text, whatever you want);
text-align: center; /*unless you want the text aligned differently*/
}

Also look up how to use the grid-container if you want the items of the footer in rows like the example you gave.如果您希望页脚的项目像您给出的示例一样按行排列,请查看如何使用网格容器。

You need the footer tag to do its job!你需要页脚标签来完成它的工作!

Read more about the footer tag here: https://www.geeksforgeeks.org/html5-footer-tag/在此处阅读有关页脚标签的更多信息: https ://www.geeksforgeeks.org/html5-footer-tag/

Reference: https://code-boxx.com/keep-html-footers-at-bottom/参考: https ://code-boxx.com/keep-html-footers-at-bottom/


The easy ways to keep a footer at the bottom with modern CSS are:使用现代 CSS 将页脚保持在底部的简单方法是:

  1. Use footer { position: fixed} or footer { position: sticky } to keep the at the bottom.使用 footer { position: fixed}footer { position: sticky }保持底部。

  2. Use a flexbox layout that "stretches" the body section, keep the footer at the bottom.使用“拉伸”主体部分的 flexbox 布局,将页脚保持在底部。

    body{ display: flex; flex-direction: column; }

    main{ flex-grow: 1; }

  3. Lastly, use a grid layout to achieve the same "stretch body section".最后,使用网格布局来实现相同的“拉伸主体部分”。

    <header>HEAD</header> <main>MAIN</main> <footer>FOOT</footer>

    html, body { height: 100%;}

    body { disply: grid; grid-template-rows: auto 1fr auto; }

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

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