css修复图像后出现的空白区域

时间:2018-05-04 17:27:31

标签: html css

我已经尝试了所有我知道的选项。请帮我删除图像和div标签之间的空白区域。我不知道为什么白色出现在图像和div下方。我无法弄清楚CSS错在哪里。我从早上开始就一直在努力,但我无法找到解决方案。

请帮帮我。我上传了screenshot

clear
input long patid float date
1015 18766
1018 13135
1020 13325
1025 14384
1029 14514
1050 13501
1070 14523
1071 14878
1090 14701
1092 14159
end
format %td date

gen year = year(date) 

list 

     +--------------------------+
     | patid        date   year |
     |--------------------------|
  1. |  1015   19may2011   2011 |
  2. |  1018   18dec1995   1995 |
  3. |  1020   25jun1996   1996 |
  4. |  1025   20may1999   1999 |
  5. |  1029   27sep1999   1999 |
     |--------------------------|
  6. |  1050   18dec1996   1996 |
  7. |  1070   06oct1999   1999 |
  8. |  1071   25sep2000   2000 |
  9. |  1090   01apr2000   2000 |
 10. |  1092   07oct1998   1998 |
     +--------------------------+

2 个答案:

答案 0 :(得分:0)

它是下行空间(悬挂在'y'和'p'底部的位),因为默认情况下img是一个内联元素。此属性消除了差距。

只需将display: block添加到您的img样式即可。

jsfiddle

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rent-O-Roof</title>
    <style type="text/css">
      body{
      width: 100%;
      margin: 0;
      padding: 0;
      height: 100%;
      overflow: hidden;
      }
      .topnav{
      overflow: hidden;
      background-color: #333;
      }
      .topnav a{
      float: left;
      display: block;
      color: #f2f2f2;
      text-align: center;
      padding: 14px 16px;
      text-decoration: none;
      font-size: 17px;
      }
      .topnav a:hover{
      background-color: #ddd;
      color: black;
      }
      .active{
      background-color: #4CAF50;
      color: white;
      }
      .topnav .icon{
      display: none;
      }
      @media screen and (max-width: 600px){
      .topnav a:not(:first-child) {display: none;}
      .topnav a.icon {
      float: right;
      display: block;
      }
      }
      @media screen and (max-width: 600px){
      .topnav.responsive {position: relative;}
      .topnav.responsive .icon {
      position: absolute;
      right: 0;
      top: 0;
      }
      .topnav.responsive a{
      float: none;
      display: block;
      text-align: left;
      }
      }
      /* Style the footer */
      .footer {
      background-color:#777555 ;
      padding: 10px;
      text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="topnav" id="myTopnav">
      <a href="#home" class="active">Home</a>
      <a href="#aboutus">About US</a>
      <a href="#contact">Contact US</a>
      <a href="#about">google form</a>
      <a href="#about">facebook page</a>
      <a href="#about">CUSTOMER REVIEW</a>
      <a href="#about">CAREERS</a>
      <a href="#about">TERM</a>
      <a href="#about">OPTIONS</a>
      <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a>
    </div>
    <script>
      function myFunction() {
          var x = document.getElementById("myTopnav");
          if (x.className === "topnav") {
              x.className += " responsive";
          } else {
              x.className = "topnav";
          }
      }
    </script>
    <div style="overflow: hidden;">
      <img src="http://via.placeholder.com/350x150" style="width: 100%; height: 150px; overflow: hidden; padding: 0; display: block;">
      <div style="background-color: red; font-size: 48px;">About Us
      </div>
    </div>
  </body>
</html>

答案 1 :(得分:0)

display: block添加到像Zhenya Telegin所说的img标签中,或者给“about”div一个负边距值,例如margin-top: -4px