我正在Github页面上构建一个网站,并且试图更改页脚的颜色。
如您所见,我的课程是“ footer”。
在CSS上,我将background-color属性设置为#000000。
但是,我仍然无法在桌面上看到黑色的背景色。(我可以在移动页面上看到,因为我设置了媒体查询)
代码如下。



@media screen and (min-width: 1000px) {

html, body{
  font-family: "Comfortaa";
}

.header-logo{
  float: left;
  padding: 10px 30px;
}

.header li:hover{
  border-bottom: 2px solid #24ABE2;
}

.header a{
  float:left;
  display:block;
  color:black;
}


.header-link li{
  float: left;
  padding: 5px 60px;
  font-size: 20px;
  color:#24ABE2;
}

/* Dropdown Button */
.droplist{
  border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 240px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 20;
  margin-top: 29px;
  height: 210px;
  color:#24ABE2;
}
/* Links inside the dropdown */
.dropdown-content a {
  color: #24ABE2;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  z-index: 20;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
  border-bottom: 2px solid #24ABE2;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
  display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
  background-color: white;
}


.footer-logo{
  float: left;
  padding: 15px 20px;
  width: 300px;
  height: auto;
  margin-left: 30px;
  margin-top: 20px;
}

.footer-list{
  margin-top:10px;
  font-size: 20px;
  color: #ccfbff;
  float: right;
  padding: 2px 8px;
  margin-right: 40px;
}

.footer-list li{
  padding: 10px;
}

}


@media screen and (max-width: 1000px) {
html, body{
  font-family: Nunito;
}


.header-logo{
  text-align:center;
  margin-left:20px;
  padding: 10px 30px;
}

.header li{
  display:none;
}

.header-link{
 display:none;
}

.footer-logo{
  padding: 15px 10px;
  width: 300px;
  height: 90px;
  margin:auto;
  text-align:center;
}

.footer-logo img{
  width: 300px;
  height: auto;
  margin:auto;
  text-align:center;
}

.footer-list{
  display:block;
  margin:auto;
  font-size: 20px;
  color: #ccfbff;
  padding: 2px 8px;
  text-align:center;
}

.footer-list li{
  margin:auto;
  padding: 5px;
  font-size:20px;
  text-align:center;
}

}



/* CSS for default design */
html { scroll-behavior: smooth; }

html, body{
  height: 100%;
  width: 100%;
  margin: 0px 0px 0px 0px;
  z-index:-10;
}

/* Settings of a tag for whole page*/
a:link {
  text-decoration: none;
  cursor: pointer;
}

a:visited {

  text-decoration: none;
  cursor: pointer;
}

a:hover {
  text-decoration: none;
  cursor: pointer;
}
a:active {
  text-decoration: none;
  cursor: pointer;
}

.header {
  border-bottom:2px solid #0E76BC;
  background-color: white;
  height: 60px;
  position: fixed;
  top: 0px;
  bottom: 0px;
  right: 0px;
  left: 0px;
  opacity: 90%;
  margin: 0px 0px 0px 0px;
  z-index:10;
}

.header-logo{
  width: 300px;
  height: auto;
}

li{
  list-style: none;
}

.footer{
  height: auto;
  background-color: #000000 !important;
  width: 100%;
  margin: 0px 0px 0px 0px;
}

.footer a:link {
  color: #ccfbff;
}

.footer a:visited {
  color: #ccfbff;
}

.footer a:hover {
  color: #ccfbff;
}

.footer a:active {
  color: #ccfbff;
}

<div class="footer">
      <img src="https://i.ibb.co/p4LvvdH/Copy-of-LOGO-White.png" alt="SLED Logo" class="footer-logo" />
      <div class="footer-list">
       <ul>
        <a href="#top"><li>Back to Top</li></a>
        <a href="https://instagram.com/jcbmssledteam/"><li>Instagram</li></a>
        <a href="https://www.facebook.com/jcbooth.sled"><li>Facebook</li></a>
        <a href="mailto: [email protected]"><li>[email protected]</li></a>
        <a href="https://www.fcboe.org/jcbms"><li>J.C. Booth Middle School</li></a>
        <a href="https://www.fcboe.org"><li>Fayette County Public Schools</li></a>
       </ul>
      </div>
</div>

最佳答案

每当我们在子项上给float属性时,父母就会自动将自己的高度设置为0,因此请输入:

    .footer:before,
    .footer:after
    {
        clear: both;
        display: block;
        content: '';
    }

关于html - 无法更改页脚背景颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59606047/

10-12 18:56