Div具有动态图像大小

时间:2014-05-23 13:42:08

标签: html css

我有这个结构:一个主要的div和里面我有两个div。在第一个,我有一个宽度为60%的图像。另一个有35%的宽度。在第二个div中,我还有两个div,宽度为100%,高度为50%(每个div)。主div中的所有div都有图像。

我想要做的是div在主div中,具有图像的大小。 正如您所看到的,在小提琴中,第一个图像(主要div中的第一个div)正确显示。但另一个div(在主div内)没有正确显示。

到目前为止,这是:

FIDDLE DEMO

我的div html:

<div class="features">
<div class="firstFeatureLine">
    <div class="firstLeft">
        <div id="cultureNews" class="outerbox">
            <img src="http://www.lookouch.com/www/assets/newImages/home/modulos/culturenews.jpg" />
            <div id="featuresTitle">
                Culture News
            </div>
        </div>
    </div>
    <div class="firstRight">
        <div id="firstRightUp">
            <div id="portfolio" class="outerbox">
            <img src="http://www.lookouch.com/www/assets/newImages/home/modulos/portfolio.jpg" />
                <div id="featuresTitle">
                    Portfolio
                </div>
            </div>
        </div>
        <div id="firstRightDown">
            <div id="culturenews1" class="outerbox">
            <img src="http://www.lookouch.com/www/assets/newImages/home/modulos/culturenews 1.jpg" />
                <div id="featuresTitle">
                    Culture News
                </div>
            </div>
        </div>
    </div>
</div>

<div class="secondFeatureLine">
    <div class="secondLeft">
        <div id="portfolio1" class="outerbox">
            <img src="http://www.lookouch.com/www/assets/newImages/home/modulos/portfolio.jpg" />
            <div id="featuresTitle">
                Portfolio
            </div>
        </div>
    </div>

    <div class="secondRight">
        <div id="school" class="outerbox">
            <img src="http://www.lookouch.com/www/assets/newImages/home/modulos/school.jpg" />
            <div id="featuresTitle">
                School
            </div>
        </div>
    </div>
</div>

这是我的css:

.features {
width: 100%;
height: 100%;
background-color: #1a1a1a;
margin-top: 10%;
margin-bottom: 10%;
}

#featuresTitle {
color: #ffffff;
background-color: #6000ff;
padding: 5px 5px 5px 5px;
position: absolute;
font-family: Montserrat;
font-size: 13px;
display: inline-block;
top: 0;
left: 0;
}

.firstFeatureLine { 
min-width: 20px;
min-height: 20px;
display: inline-block;
position: relative;
width: 100%;
height: 100%;
}

.firstFeatureLine .firstLeft {
width: 60%;
height: 100%;
display: inline-block;
position: relative;
}

.firstFeatureLine .firstLeft #cultureNews {}
.firstFeatureLine .firstLeft #cultureNews img { width: 100%; }

.firstFeatureLine .firstRight {
width: 35%;
height: 100%;
display: inline-block;
position: absolute;
}
.firstFeatureLine .firstRight #firstRightUp {
width: 100%;
height: 50%;
position: relative;
}
.firstFeatureLine .firstRight #firstRightUp #portfolio {}
.firstFeatureLine .firstRight #firstRightUp #portfolio img { width: 100%; }

.firstFeatureLine .firstRight #firstRightDown {
width: 100%;
height: 50%;
position: relative;
}
.firstFeatureLine .firstRight #firstRightDown #culturenews1 {}
.firstFeatureLine .firstRight #firstRightDown #culturenews1 img { width: 100%; }

.secondFeatureLine {
min-width: 20px;
min-height: 20px;
display: inline-block;
position: relative;
width: 100%;
height: 100%;
}

.secondFeatureLine .secondLeft {
width: 35%;
height: 100%;
display: inline-block;
position: relative;
}

.secondFeatureLine .secondLeft #portfolio1 {}
.secondFeatureLine .secondLeft #portfolio1 img { width: 100%; }

.secondFeatureLine .secondRight {
width: 60%;
height: 100%;
display: inline-block;
position: relative;
}

.secondFeatureLine .secondRight #school {}
.secondFeatureLine .secondRight #school img  { width: 100%; }

这就是我想要做的,但动态地使用图像尺寸(但主要div的高度需要为红色的div):

[image]()

错误在这里: [image]()

1 个答案:

答案 0 :(得分:0)

我对firstright和secondright的建议是做浮动:对; 宽度也为60%,40%

Updated Fiddler Here..

试试这个:

features {
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
    margin-top: 10%;
    margin-bottom: 10%;
}

div {
    border: 0px;
}

.outerbox {
    background-color: #FFFF00;
}

#featuresTitle {
    color: #ffffff;
    background-color: #6000ff;
    padding: 5px 5px 5px 5px;
    position: absolute;
    font-family: Montserrat;
    font-size: 13px;
    display: inline-block;
    top: 0;
    left: 0;
}

.firstFeatureLine {
    min-width: 20px;
    min-height: 20px;
    display: inline-block;
    position: relative;
    width: 100%;
    height: 100%;
    background-color: red;
}

    .firstFeatureLine .firstLeft {
        width: 60%;
        height: 100%;
        display: inline-block;
        position: relative;
    }

        .firstFeatureLine .firstLeft #cultureNews {
        }

            .firstFeatureLine .firstLeft #cultureNews img {
                width: 100%;
            }

    .firstFeatureLine .firstRight {
        width: 40%;
        height: 100%;
        display: inline-block;
        position: absolute;
        float: right;
    }

        .firstFeatureLine .firstRight #firstRightUp {
            width: 100%;
            height: 50%;
            position: relative;
        }

            .firstFeatureLine .firstRight #firstRightUp #portfolio {
            }

                .firstFeatureLine .firstRight #firstRightUp #portfolio img {
                    width: 100%;
                }

        .firstFeatureLine .firstRight #firstRightDown {
            width: 100%;
            height: 50%;
            position: relative;
        }

            .firstFeatureLine .firstRight #firstRightDown #culturenews1 {
            }

                .firstFeatureLine .firstRight #firstRightDown #culturenews1 img {
                    width: 100%;
                }

       .secondFeatureLine {
    min-width: 20px;
    min-height: 20px;
    display: inline-block;
    position: relative;
    width: 100%;
    height: 100%;
    background-color: green;
      }

    .secondFeatureLine .secondLeft {
        width: 40%;
        height: 100%;
        display: inline-block;
        position: relative;
    }

        .secondFeatureLine .secondLeft #portfolio1 {
        }

            .secondFeatureLine .secondLeft #portfolio1 img {
                width: 100%;
            }

    .secondFeatureLine .secondRight {
        width: 60%;
        height: 100%;
        display: inline-block;
        position: relative;
        float: right;
    }

        .secondFeatureLine .secondRight #school {
        }

            .secondFeatureLine .secondRight #school img {
                width: 100%;
            }