CSS元素在绝对div中的位置

时间:2015-02-03 23:18:15

标签: css twitter-bootstrap

我正在使用Bootstraps Carousel。我想从顶部褪色h1标签,从底部褪色三个h4标签。

我的问题是,当我调整浏览器大小时,所有元素都会相互叠加。

如何以正确的方式定位元素?

HTML:

<div id="carousel-example-captions" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-captions" data-slide-to="0" class=""></li>
        <li data-target="#carousel-example-captions" data-slide-to="1" class=""></li>
        <li data-target="#carousel-example-captions" data-slide-to="2" class="active"></li>
    </ol>
    <div class="carousel-inner">
        <div class="item">
            <img alt="900x500" src="http://placehold.it/2000x500">
            <div class="carousel-caption">
                <h3 class="title">Appartment</h3>
                <h4 class="meters">123 m<sup>2</sup></h4>
                <h4 class="rooms">3. Zimmer</h4>
                <h4 class="price">425,00 € pro Monat</h4>
            </div>
        </div>
        <div class="item">
            <img alt="900x500" src="http://placehold.it/2000x500">
            <div class="carousel-caption">
                <h3 class="title">Loft in Hamburg</h3>
                <h4 class="meters">123 m<sup>2</sup></h4>
                <h4 class="rooms">3. Zimmer</h4>
                <h4 class="price">425,00 € pro Monat</h4>
            </div>
        </div>
        <div class="item active">
            <img alt="900x500" src="http://placehold.it/2000x500">
            <div class="carousel-caption">
                <h3 class="title">Etagenwohnung</h3>
                <h4 class="meters">123 m<sup>2</sup></h4>
                <h4 class="rooms">3. Zimmer</h4>
                <h4 class="price">425,00 € pro Monat</h4>
            </div>
        </div>
    </div>
    <a class="left carousel-control" href="#carousel-example-captions" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#carousel-example-captions" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
</div>

CSS:

    .carousel {
    width: 100%;
}

.carousel-caption {
    text-shadow: 0 0 0;
    text-align: left;
    top: 5%;
    right: 0%;
}

.carousel-caption .title {
    position: absolute;
    display: block;
    top: 0;
    width: 250px;
    background-color: red;
    padding: 10px 10px;
    opacity: 0.0;
    transition: all 2s ease;
}

.active .carousel-caption .title {
    top: 10%;
    opacity: 1;
}

.carousel-caption .meters {
    position: absolute;
    display: block;
    bottom: 0;
    width: 150px;
    padding: 5px 5px;
    opacity: 0.0;
    transition-delay: 2s;
    transition: all 2s ease 1.5s;
}

.active .carousel-caption .meters {
    bottom: 30%;
    opacity: 1;
}

.carousel-caption .rooms {
    position: absolute;
    display: block;
    bottom: 0;
    width: 150px;
    padding: 5px 5px;
    opacity: 0.0;
    transition-delay: 4s;
    transition: all 2s ease 2s;
}

.active .carousel-caption .rooms {
    bottom: 20%;
    opacity: 1;
}

.carousel-caption .price {
    position: absolute;
    display: block;
    bottom: 0;
    width: 150px;
    padding: 5px 5px;
    opacity: 0.0;
    transition-delay: 6s;
    transition: all 2s ease 2.5s;
}

.active .carousel-caption .price {
    bottom: 1%;
    opacity: 1;
}

0 个答案:

没有答案