【问题标题】:Img height percent in table-cell using CSS使用 CSS 的表格单元格中的 Img 高度百分比
【发布时间】:2013-09-28 23:19:41
【问题描述】:

我在这里有一个 JSFiddle:http://jsfiddle.net/PEHbr/1 由于某种原因,我无法将图像高度设置为 50%。

<div class="column img">
    <div class="images right">
        <img src="{path-to-image}" />
    </div>
</div>

CSS:

.row {
    display: table-row;
    width: 100%;
}
.column { display: table-cell; height: 100%; position: relative; }
.img {  width: 22%; }
.txt { width: 50%; vertical-align: middle; }
.text p {
    width: 90%;
    margin: 10px auto;
    line-height: 1.5;
    white-space: pre-wrap;
    font-size: 18px;
    font-family: Lato;
}
.right { text-align: right; }
.images { height: 100%; position: relative; }
.images img { height: 50%; }

为什么我不能正确编辑图像的高度?

编辑:

我已经替换了图像的src,它适用于比高和正方形更宽的图像,但我要使用的图像是高矩形,这不起作用。这是为什么呢?

【问题讨论】:

    标签: html css image css-tables


    【解决方案1】:

    它对我有用。也许你的项目中有另一个 css 文件或代码改变了你的图片大小!!!

    <style type="text/css">
        .row {
            display: table-row;
            width: 100%;
        }
    
        .column {
            display: table-cell;
            height: 100%;
            position: relative;
        }
    
        .img {
            width: 22%;
        }
    
        .txt {
            width: 50%;
            vertical-align: middle;
        }
    
        .text p {
            width: 90%;
            margin: 10px auto;
            line-height: 1.5;
            white-space: pre-wrap;
            font-size: 18px;
            font-family: Lato;
        }
    
        .right {
            text-align: right;
        }
    
        .images {
            height: 100%;
            position: relative;
        }
    
            .images img {
                height: 50%;
            }
    
        .images20 img {
            height: 10%;
        }
    </style>
    

    <div class="column img">
        <div class="images right">
            <img src="img.jpg" />
        </div>
    </div>
    
    
    <div class="column img">
        <div class="images20 right">
            <img src="img.jpg" />
        </div>
    </div>
    

    【讨论】:

      【解决方案2】:

      请在下面页面的左框中检查此代码

      http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro

      <style type="text/css">
          .row {
              display: table-row;
              width: 100%;
          }
      
          .column {
              display: table-cell;
              height: 100%;
              position: relative;
          }
      
          .img {
              width: 22%;
          }
      
          .txt {
              width: 50%;
              vertical-align: middle;
          }
      
          .text p {
              width: 90%;
              margin: 10px auto;
              line-height: 1.5;
              white-space: pre-wrap;
              font-size: 18px;
              font-family: Lato;
          }
      
          .right {
              text-align: right;
          }
      
          .images {
              height: 100%;
              position: relative;
          }
      
              .images img {
                  height: 50%;
              }
      
          .images20 img {
              height: 20%;
          }
          /* 50% */
      </style>
      

      <div class="column img">
          <div class="images right">
              <img src="http://2.179.254.185/images/button/signout.png" />
          </div>
      </div>
      
      
      <div class="column img">
          <div class="images20 right">
              <img src="http://2.179.254.185/images/button/signout.png" />
          </div>
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-19
        • 2013-06-09
        • 1970-01-01
        • 2018-09-16
        • 1970-01-01
        • 2018-01-29
        • 2015-02-04
        相关资源
        最近更新 更多