为什么我的背景颜色不显示在<p>上?

时间:2017-06-07 15:26:30

标签: html css

我很困惑为什么背景颜色没有出现在这段代码上。 "1"类上有填充但即使指定了颜色也没有颜色。在容器类中查找问题。

请帮忙。

body {
  margin: 0px;
  background-color: #fff;
}


/*
font-family: 'Lato', sans-serif;
font-family: 'Fjalla One', sans-serif;
font-family: 'Gloria Hallelujah', cursive;
*/

.welcome {
  font-family: 'Gloria Hallelujah', sans-serif;
  font-size: 45;
  text-align: center;
  color: #000;
}

.sub1 {
  font-family: 'Lato', sans-serif;
  font-size: 30;
  color: #000;
  text-indent: 20;
}

.sub2 {
  font-family: 'Lato', sans-serif;
  font-size: 25;
  color: #000;
  text-indent: 20;
}

.container {
  position: relative;
  width: 100%;
  height: 600px;
}


/*.container img {
    position: absolute;
    width: 1800px;
   	background-size: cover;*/


}
@-webkit-keyframes xfade {
  0% {
    opacity: 1;
  }
  
  33% {
    opacity: 1;
  }
  
  44% {
    opacity: 0;
  }
  
  89% {
    opacity: 0;
  }
  
  100% {
    opacity: 1;
  }
}
@keyframes xfade {
  0% {
    opacity: 1;
  }
  
  33% {
    opacity: 1;
  }
  
  44% {
    opacity: 0;
  }
  
  89% {
    opacity: 0;
  }
  
  100% {
    opacity: 1;
  }
}
.container p:nth-child(3) {
  -webkit-animation: xfade 45s 0s infinite;
  animation: xfade 45s 0s infinite;
}
.container p:nth-child(2) {
  -webkit-animation: xfade 45s 15s infinite;
  animation: xfade 45s 15s infinite;
}
.container p:nth-child(1) {
  -webkit-animation: xfade 25s 30s infinite;
  animation: xfade 25s 30s infinite;
}
.container {
  position: relative;
}
.container img {
  position: absolute;
}
.1 {
  width: 100%;
  height: 100%;
  padding: 100px;
  /*background-image: url(Pictures/cupcakes.jpg)*/
  
  background-color: #00FFFF;
  overflow: auto;
  background-size: cover;
}
<html>

<head>
  <title>JAM Bakery</title>
  <link rel="stylesheet" type="text/css" href="home.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <link href="https://fonts.googleapis.com/css?family=Fjalla+One|Gloria+Hallelujah|Lato" rel="stylesheet">
</head>

<body>
  <br>
  <div class="content">
    <h1 class="welcome">Welcome to JAM Bakery!</h1>
    <div class="slogan">
      <h2 class="sub1">Creamy, Sweet, Toasted</h2>
      <h2 class="sub2">Your Choice.</h2>

      <div class="container">
        <p class="1">1</p>
        <p class="2"></p>
        <p class="3"></p>
      </div>

    </div>
  </div>
</body>

</html>

请检查您可能会看到的任何其他问题。谢谢。

2 个答案:

答案 0 :(得分:7)

&#34; 1&#34;不是有效的CSS类。 CSS类必须以字母,连字符或下划线开头。

有关详细信息,请参阅this answerthe W3C spec document

答案 1 :(得分:3)

CSS类名不应该是数字,它应该以字母开头或 - (连字符)或_(下划线)

body {
  margin: 0px;
  background-color: #fff;
}


/*
font-family: 'Lato', sans-serif;
font-family: 'Fjalla One', sans-serif;
font-family: 'Gloria Hallelujah', cursive;
*/

.welcome {
  font-family: 'Gloria Hallelujah', sans-serif;
  font-size: 45;
  text-align: center;
  color: #000;
}

.sub1 {
  font-family: 'Lato', sans-serif;
  font-size: 30;
  color: #000;
  text-indent: 20;
}

.sub2 {
  font-family: 'Lato', sans-serif;
  font-size: 25;
  color: #000;
  text-indent: 20;
}

.container {
  position: relative;
  width: 100%;
  height: 600px;
}


/*.container img {
    position: absolute;
    width: 1800px;
   	background-size: cover;*/


}
@-webkit-keyframes xfade {
  0% {
    opacity: 1;
  }
  
  33% {
    opacity: 1;
  }
  
  44% {
    opacity: 0;
  }
  
  89% {
    opacity: 0;
  }
  
  100% {
    opacity: 1;
  }
}
@keyframes xfade {
  0% {
    opacity: 1;
  }
  
  33% {
    opacity: 1;
  }
  
  44% {
    opacity: 0;
  }
  
  89% {
    opacity: 0;
  }
  
  100% {
    opacity: 1;
  }
}
.container p:nth-child(3) {
  -webkit-animation: xfade 45s 0s infinite;
  animation: xfade 45s 0s infinite;
}
.container p:nth-child(2) {
  -webkit-animation: xfade 45s 15s infinite;
  animation: xfade 45s 15s infinite;
}
.container p:nth-child(1) {
  -webkit-animation: xfade 25s 30s infinite;
  animation: xfade 25s 30s infinite;
}
.container {
  position: relative;
}
.container img {
  position: absolute;
}
.t1 {
  width: 100%;
  height: 100%;
  padding: 100px;
  /*background-image: url(Pictures/cupcakes.jpg)*/
  
  background-color: #00FFFF;
  overflow: auto;
  background-size: cover;
}
<html>

<head>
  <title>JAM Bakery</title>
  <link rel="stylesheet" type="text/css" href="home.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <link href="https://fonts.googleapis.com/css?family=Fjalla+One|Gloria+Hallelujah|Lato" rel="stylesheet">
</head>

<body>
  <br>
  <div class="content">
    <h1 class="welcome">Welcome to JAM Bakery!</h1>
    <div class="slogan">
      <h2 class="sub1">Creamy, Sweet, Toasted</h2>
      <h2 class="sub2">Your Choice.</h2>

      <div class="container">
        <p class="t1">1</p>
        <p class="t2"></p>
        <p class="t3"></p>
      </div>

    </div>
  </div>
</body>

</html>