CSS图像浮动左侧错误

时间:2014-09-06 06:27:16

标签: html css

我是一名UI设计师。我希望每个图像浮动到另一个下面的左边。但它看起来像。 http://delhiwebdesigner.com/images/Capture.png请检查问题所在。下面是我的HTML和CSS代码:

<div class="books-container">
<article class="entry">
                        <img src="images/books/1.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/2.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/4.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/3.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/5.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/6.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/7.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/8.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/9.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/10.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/11.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/12.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<article class="entry">
                        <img src="images/books/13.jpg" alt="" title="" />
                        <a href="#">
                            <div class="text">
                                <p class="head">LeMans</p>
                                <p class="title">LeMans</p>
                            </div>
                        </a>
                    </article>

<div class="clear"></div>

CSS代码如下: -

 .books-container {
        width: 1200px;
        margin: 100px auto 0;
    }

    .entry {
        width: 25%;
        float: left;
        height: auto;
        padding: 10px;
        position: relative;
    }

        .entry img {
            width: 100%;
            display: block;
        }

        .entry .text {
            position: absolute;
            display: none;
            top: 0;
            vertical-align: middle;
            height: 100%;
            background: red;
            opacity: 0.5;
            text-align: center;
            width: 100%;
            padding: 10px;
        }

1 个答案:

答案 0 :(得分:1)

http://jsfiddle.net/6deqxyk4/4/

.books-container {max-width: 1200px;width:100%; margin: 100px auto 0;}
.entry {width:400px; float: left; height: auto; padding: 10px; position: relative;}
.entry img {width: 100%; display: block;}
.entry .text {position: absolute; display: none; top: 0; vertical-align: middle; height: 100%; background: red; opacity: 0.5; text-align: center; width: 100%; padding: 10px;}