如何使这些部分的高度值等于此图像的某些部分?

时间:2015-06-04 19:34:19

标签: html css image css3

JSFiddle here!

如何在“我有什么”中制作col-right的部分'图像的一部分得到的高度等于与其相对的图像部分?

enter image description here

问题解释:

图片的高度为1610px(宽度为700px),其中粉红色部分的高度为440px,蓝色为380px,绿色为{{ 1}},黄色高度为380px。这是一张图片,我在Adobe PS中检查了这些尺寸。

现在我想要的是380px中的每个部分/部分(即具有.col-righth3元素的部分)应该具有h5相同的部分/部分右侧图像部分,即height中包含第一个h3h5的部分/部分应该与图像的粉红色部分具有相同的高度

我该怎么做?

我做了什么:

我尝试在.col-right section col-rightheight440px380px中为每个380px提供一个380px但是很明显,这不起作用,因为正在考虑的img是根据父元素的维度获取维度值,因为它的百分比值为width:50%height:80%

无论如何,您可以查看JSFiddle here



    @import url(<link href='http://fonts.googleapis.com/css?family=Open+Sans:700,300,600,400' rel='stylesheet' type='text/css'>);
    .section-big {
      padding: 100px 0;
    }
    .section-big .container {
      width: 970px;
      margin: 0 auto;
    }
    .section-big .col {
      width: 47%;
      display: inline-block
    }
    .section-big .col-left {
      float: left;
      text-align: right;
      padding-right: 25px;
    }
    .section-big .col-right {
      float: left;
      text-align: left;
      padding-left: 25px;
    }
    .section-big .col-left img {
      height: 80%;
      width: 50%;
    }
    h3 {
      color: #6c6969;
      transition: color 0.3s ease 0s;
      font-family: 'Open Sans', sans-serif;
      font-weight: 600;
      font-size: 40px;
      margin: 0;
    }
    h5 {
      color: #6c6969;
      transition: color 0.3s ease 0s;
      font-family: 'Open Sans', sans-serif;
      font-weight: 400;
      font-size: 20px;
      margin: 0;
    }
&#13;
<section class="section-big">

  <div class="container">
    <div class="col col-left">
      <img src="http://www.mediafire.com/convkey/9642/57q0fpdevvo1999zg.jpg?size_id=b" alt="Tun Tun!" />
    </div>
    <div class="col col-right">
      <section class="section-one">
        <h3>HEADING</h3>
        <h5>Paragraph paragraph</h5>
      </section>
      <section class="section-two">
        <h3>HEADING</h3>
        <h5>Paragraph paragraph</h5>
      </section>
      <section class="section-three">
        <h3>HEADING</h3>
        <h5>Paragraph paragraph</h5>
      </section>
      <section class="section-four">
        <h3>HEADING</h3>
        <h5>Paragraph paragraph</h5>
      </section>
    </div>
  </div>

</section>
&#13;
&#13;
&#13;

@ gui47在这里!

enter image description here

1 个答案:

答案 0 :(得分:1)

一般来说,有两种方法可以做到这一点,无论哪种方式使其响应,一切都必须设置为百分比高度。

请参阅以下演示。

1。使用内联图片。

<强> JsFiddle Demo

body {
    margin: 0;
}
.container {
    display: table;
    max-width: 50%;
    height: 100%;
}
.col {
    display: table-cell;
    vertical-align: top;
    height: 100%;
}
.col img {
    width: 100%;
    height: auto;
}
.col h3, .col h5 {
    padding: 0;
    margin: 0;
}
.col section:nth-child(1) {
    height: 29%;
}
.col section:nth-child(2) {
    height: 22%;
}
.col section:nth-child(3) {
    height: 23%;
}
.col section:nth-child(4) {
    height: 25%;
}
.col section:nth-child(odd) {
    background: aqua;
}
.col section:nth-child(even) {
    background: lime;
}
<section class="section-big">
    <div class="container">
        <div class="col col-left">
            <img src="http://www.mediafire.com/convkey/9642/57q0fpdevvo1999zg.jpg?size_id=b" alt="Tun Tun!" />
        </div>
        <div class="col col-right">
            <section class="section-one">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
            <section class="section-two">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
            <section class="section-three">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
            <section class="section-four">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
        </div>
    </div>
</section>

2. 使用背景图片。

<强> JsFiddle Demo

html, body {
    height: 100%;
    margin: 0;
}
.section-big { /* change the width/height here */
    height: 80%;
    width: 80%;
}
.container {
    display: table;
    table-layout: fixed;
    margin: auto;
    height: 100%;
    width: 100%;
}
.col {
    display: table-cell;
    vertical-align: top;
    height: 100%;
}
.col-left {
    background: url("http://www.mediafire.com/convkey/9642/57q0fpdevvo1999zg.jpg?size_id=b");
    background-size: auto 100%;
}
.col h3, .col h5 {
    padding: 0;
    margin: 0;
}
.col section:nth-child(1) {
    height: 30%;
}
.col section:nth-child(2) {
    height: 22%;
}
.col section:nth-child(3) {
    height: 22%;
}
.col section:nth-child(4) {
    height: 26%;
}
.col section:nth-child(odd) {
    background: aqua;
}
.col section:nth-child(even) {
    background: lime;
}
<section class="section-big">
    <div class="container">
        <div class="col col-left">
            <!-- <img src="http://www.mediafire.com/convkey/9642/57q0fpdevvo1999zg.jpg?size_id=b" alt="Tun Tun!" /> -->
        </div>
        <div class="col col-right">
            <section class="section-one">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
            <section class="section-two">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
            <section class="section-three">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
            <section class="section-four">
                <h3>HEADING</h3>
                <h5>Paragraph paragraph</h5>
            </section>
        </div>
    </div>
</section>