html - 如何使这些部分的高度值等于该图像的各个部分?

标签 html image css

JSFiddle here!

如何使图像“WHAT I HAVE”部分的 col-right 部分的高度等于图像的相对部分?

enter image description here

问题解释:

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

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

我该怎么做?

我尝试了什么:

我试图给 col-right 中的每个 section height 440px,380px 380px380px,但显然这不起作用,因为所考虑的 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;
    }
<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>


@gui47 这里!

enter image description here

最佳答案

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

请参阅以下演示。

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>

关于html - 如何使这些部分的高度值等于该图像的各个部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30652612/

相关文章:

php - 即使 PHP 在 IE 中也有 'bugs'

html - 将层叠的 css 菜单修复到顶部

html - 我可以在 flexbox 行之间有一条线吗?

html - 如何从 HTML/CSS 中的大写句子中生成一个字符串?

android - 运行一段时间后,我收到消息,如不幸的是,你的应用程序已停止(Listview/Recyclerview 中的许多项目)

html - 调整页面大小时将 Logo 保持在页面中间

css - OpenLayers 3 - 在 map 外添加比例线

jquery - Div 位置固定滚动条不起作用

PHP - 例如,当需要条件 html block 时如何避免 "echo"HTML

c# - 加载图片文件 Image.FromFile VS FileStream