html - 盒子上的空间太多 - HTML

标签 html css

我创建了一个盒子 here .

但是顶部和底部的空间太大了。

请看这里的图片:

enter image description here

如何删除顶部和底部之间的额外间距:
1.标题和日期
2.按钮和文字
3.按钮和下方多余的间距

这是我的 HTML:

<div class="col-1-3"><img src="http://www.iliveaccountable.com/wp-content/uploads/2016/11/iliveaccountable.jpg" alt="" />
<h3 style="font-family: 'Montserrat'; text-align: center;">TAKING IT TO THE SOURCE</h3>
<h4 style="font-family: 'Montserrat'; text-align: center;">11/13/2016</h4>
<a href="http://www.iliveaccountable.com/oldsite/iliveconnected-patterns/" target="_blank">
<button class="btn btn-block btn-primary">Watch Video</button>
</a>
</div>

这是我的 CSS:

h4 {
  text-align: center;
}
.col-1-3 {
  padding: 10px;
  width: 28%;
  float: left;
margin: 1%;
 border: 1px solid #dedede;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
border-radius: 7px;
}
.col-1-3 img {
  width: 100%;
}

.btn-block{
    display: block;
    width: 100%;
}
@media only screen and (max-width: 767px) {
  .col-1-3 {width: 44%;}

}
@media only screen and (max-width: 590px) {
  .col-1-3 {width: 94%;}

}

我只想有足够的空间,但这个间距太大了。

最佳答案

让div.col-1-3内所有元素的margin和padding为0

检查这个片段

h4 {
  text-align: center;
}
.col-1-3 * {
  padding: 0;
  margin: 0;
}
.col-1-3 {
  width: 28%;
  float: left;
  margin: 1%;
  border: 1px solid #dedede;
  -webkit-border-radius: 7px;
  -moz-border-radius: 7px;
  border-radius: 7px;
}
.col-1-3 img {
  width: 100%;
}
a {
  margin: 0;
}
h3 {
  margin: 0;
}
h4 {
  margin: 0;
}
.btn-block {
  display: block;
  width: 100%;
}
@media only screen and (max-width: 767px) {
  .col-1-3 {
    width: 44%;
  }
}
@media only screen and (max-width: 590px) {
  .col-1-3 {
    width: 94%;
  }
}
<div class="col-1-3">
  <img src="http://www.iliveaccountable.com/wp-content/uploads/2016/11/iliveaccountable.jpg" alt="">
  <h3 style="font-family: 'Montserrat'; text-align: center;">TAKING IT TO THE SOURCE</h3>
  <h4 style="font-family: 'Montserrat'; text-align: center;">11/13/2016</h4>
  <p>
    <a href="http://www.iliveaccountable.com/oldsite/iliveconnected-patterns/" target="_blank">
      <button class="btn btn-block btn-primary">Watch Video</button>
    </a>
  </p>
</div>

希望对你有帮助

关于html - 盒子上的空间太多 - HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40643702/

相关文章:

Jquery,变量中的多个 CSS 属性

css - 添加 list-style-type 以响应内联样式

html - UILabel sizetofit 隐藏了属性文本中的一些单词

HTML 表格垂直和水平滚动

javascript - iphone删除模式下app抖动的算法

html - li 导航栏内的文本在 Chrome/Safari 中为两行,但在 Firefox 中为一行

html - 我一直在 Windows 7 上编写我的网站,只是在 Windows 8 上继续,它搞砸了

jquery - 给 jquery toggleclass() 添加效果

javascript - 如何向前而不是向后添加文本

java - 如何让用户通过 Stripe 而不是我的 Wordpress 网站进行付款?