0

我在这里有一个 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图像的,它适用于比高和正方形更宽的图像,但我要使用的图像是高矩形,这不起作用。为什么是这样?

4

2 回答 2

0

它对我有用。也许你的项目中有另一个 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>

于 2013-09-28T23:42:23.943 回答
0

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

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>

于 2013-09-28T23:45:51.837 回答