HTML/CSS 背景重复问题

标签 html css

请告诉我为什么这段代码会重复页面底部的背景图片 Dash Task ,以及为什么第三个 <span class="price">$1000 p/night</span>在底部之前仍然可见 <div>被点击了吗?

$("div").on('click', function() {
  $(this).toggleClass('show-description');
});
body {
  background: url("http://i.imgur.com/AXRyd9w.jpg");
  background-size: cover;
  background-position: center;
  max-width: 800px;
  font-family: Helvetica, sans-serif;
  margin: 0 auto;
}

div {
  height: 350px;
  background-size: cover;
  position: relative;
  max-width: 800px;
  margin: 40px 15px;
  border: solid black;
  border-width: 3px 0px 0px 0px;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  text-align: justify;
}

h1 {
  text-align: center;
  font-family: 'Lobster', cursive;
  font-size: 100px;
  margin: 25px 0 -10px 0;
}

h2 {
  text-align: center;
  font-family: 'Quicksand', sans-serif;
  margin: 25 0 -10 0;
}

p {
  font-family: Arial;
  line-height: 25px;
  margin: 0 auto;
  padding: 10px;
  color: rgba(255,255,255,1);
  background: rgba(70,0,0,1);
  background: linear-gradient(bottom, rgba(70,0,0,1), rgba(70,0,0,.7));
  background: -webkit-linear-gradient(bottom, rgba(70,0,0,1), rgba(70,0,0,.7));
  background: -moz-linear-background(bottom, rgba(70,0,0,1), rgba(70,0,0.7));
  position: absolute;
  bottom: 0;
  height: 20px;
  letter-spacing: .5;
}

small {
  opacity: 0;
}

.show-description p {
  height: 180px;
  background: rgba(70,0,0,1);
  background: linear-gradient(bottom, rgba(0,0,0,1), rgba(70,0,0,.7));
  background: -webkit-linear-gradient(bottom, rgba(0,0,0,1), rgba(70,0,0,.7));
  background: -moz-linear-background(bottom, rgba(0,0,0,1), rgba(70,0,0.7));
  font-size: 26px;
}

.show-description small {
  opacity: 1;
  font-size: 14px;
  line-height: 20px;
}

.flintstones {
  background: url("http://i.imgur.com/5v4yJbe.png?1");
}

.hobbit {
  background: url("http://i.imgur.com/IF2IhA0.png?1");
}

.plane {
  background: url("http://i.imgur.com/AwDgcdK.png?1");
}

.price {
  float: right;
  font-size: 16px;
  font-family: 'Quicksand', sans-serif;
  opacity: 1;
}

@media (max-width: 600px) {
  h1 {
    font-size: 40px;
    margin: 10px 0 10px 0;
  }

  h2 {
    font-size: 16px;
    margin: 10px 0 -5px 0;
  }

  div {
    margin: 20px 10px;
  }

  p {
    font-size: 14px;
  }

  small {
    font-size: 11px
    line-height: 3px;
  }

  .price {
    font-size: 12px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Lobster|Quicksand" rel="stylesheet">

<h1>Catley's Cribs</h1>
<h2>Luxury homes and apartments</h2>

<div class="flintstones">
<p>Make your bed rock!</br></br><small>Travel back in time to this Flinstones inspired getaway nestled away in the heart of Lincolnshire. Just a 15 minute walk from Grimsby train station.</br><span class="price">$700 p/night</span></small></p>
</div>

<div class="hobbit">
<p>Welcome to MiddleEarth!</br></br><small>Orcs, goblins, wizards and elves your kinda thing? Why not get in touch with your Gandalf in our hobbit themed holiday home, a stone's throw from Sheffield City Centre.</br><span class="price">$500 p/night</span></small></p>
</div>

<div class="plane">
<p>Come fly with me!</br></br><small>Are you a real sucker for a long haul flight, well now you can spend 100% of your holiday time nestled away in your very own economy class cabin. With fully functioning toilets and emergency exits, this aero-partment is sure to blow you away.</br><span class="price">$1000 p/night</span></small></p>
</div>

最佳答案

所有段落在自己的父亲下都是可见的,但第一和第二个在下一个框下并且不可见,但最后一个不是。最后一个div,他的段落<div class="plane"><p>...</p></div>之后创建一个可见的空间。

添加 overflow:hidden;到你的 div flintstones/hobbit/plane 去修复。

关于HTML/CSS 背景重复问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43966132/

相关文章:

javascript - 我怎样才能让幻灯片停止播放?我可以通过哪些方式改进代码?

html - 产品图片,png,某些页面不透明,Nova 主题,bigcartel

javascript - Paydirt 主页幻灯片放映的超棒放大镜/放大效果

javascript - 为什么在此内联事件处理程序之后使用 return false 和 return true?

javascript - 使用查询获取 HTML 表 <thead> 元素

html - 带有 overflow-x :auto and flex-grow:1 子项的 Flex-box

css - 带有主体的 html 高度和 chrome 上的默认边距

java - 如何在MySQL中存储时间

html - 如何让视频垂直居中

css - ASP.NET MVC 5 中心文本框 css