在960网格中浮动问题css

时间:2013-12-02 17:00:57

标签: css css-float 960.gs

这是我不想创造的:http://i.imgur.com/9KdL0UW.jpg,这就是我所拥有的:http://i.imgur.com/mRDWoRo.jpg。我的问题是新闻的布局,正如你所看到的,它不能正常工作。我正在使用960网格,并且不知道如何在小提琴中引用它,所以我发布的是图像而不是。

html:

<div class="highlightednews grid_3">
            <h4>News Preview</h4>
            <h2><a href="#">Under The Dome: “Big Jim is just too fat, we have to fire him!”</a></h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor pellentesque.</p>
        </div>
        <div class="highlightednews grid_3">
            <h4>News Preview</h4>
            <h2><a href="#">Under The Dome: “Big Jim is just too fat, we have to fire him!”</a></h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor pellentesque.</p>
        </div>
        <div class="highlightednews grid_3">
            <h4>News Preview</h4>
            <h2><a href="#">Under The Dome: “Big Jim is just too fat, we have to fire him!”</a></h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor pellentesque.</p>
        </div>

        <!--FEATURED NEWS-->
        <div class="featurednews grid_3 ">
            <h3>How am I gonna be an optimist about this? </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor. </p>
            <p>posted 15th November </p>
        </div>

        <div class="featurednews grid_3 ">
            <h3>How am I gonna be an optimist about this? </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor. </p>
            <p>posted 15th November </p>
        </div>  

        <div class="featurednews grid_3 ">
            <h3>How am I gonna be an optimist about this? </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor. </p>
            <p>posted 15th November </p>
        </div>  

        <div class="featurednews grid_3 ">
            <h3>How am I gonna be an optimist about this? </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor. </p>
            <p>posted 15th November </p>
        </div>  

        <div class="featurednews grid_3 ">
            <h3>How am I gonna be an optimist about this? </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor. </p>
            <p>posted 15th November </p>
        </div>  

        <!--NEWEST-->

        <div class="newest grid_9">
            <h1><a href="#">Almost Human starting in one week!</a></h1>
            <p>posted 15th November by <a href="#">Andrew</a></p>
            <p>News Preview</p>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus suscipit metus non pellentesque. Aliquam erat volutpat. Suspendisse nec posuere erat. Cras in sem sed erat hendrerit tempus ac a sem. Fusce laoreet nulla in dolor feugiat, non adipiscing ante pharetra. Nunc pretium dui quis augue pretium, elementum varius odio interdum. Duis sit amet</p>
            <p>Social Buttons</p>
            <ul>
                <li><a href="#">255 COMMENTS</a></li>
                <li><a href="#">READ MORE</a></li>
            </ul>
        </div>

            <div class="newest grid_9">
            <h1><a href="#">Almost Human starting in one week!</a></h1>
            <p>posted 15th November by <a href="#">Andrew</a></p>
            <p>News Preview</p>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus suscipit metus non pellentesque. Aliquam erat volutpat. Suspendisse nec posuere erat. Cras in sem sed erat hendrerit tempus ac a sem. Fusce laoreet nulla in dolor feugiat, non adipiscing ante pharetra. Nunc pretium dui quis augue pretium, elementum varius odio interdum. Duis sit amet</p>
            <p>Social Buttons</p>
            <ul>
                <li><a href="#">255 COMMENTS</a></li>
                <li><a href="#">READ MORE</a></li>
            </ul>
        </div>

            <div class="newest grid_9">
            <h1><a href="#">Almost Human starting in one week!</a></h1>
            <p>posted 15th November by <a href="#">Andrew</a></p>
            <p>News Preview</p>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus suscipit metus non pellentesque. Aliquam erat volutpat. Suspendisse nec posuere erat. Cras in sem sed erat hendrerit tempus ac a sem. Fusce laoreet nulla in dolor feugiat, non adipiscing ante pharetra. Nunc pretium dui quis augue pretium, elementum varius odio interdum. Duis sit amet</p>
            <p>Social Buttons</p>
            <ul>
                <li><a href="#">255 COMMENTS</a></li>
                <li><a href="#">READ MORE</a></li>
            </ul>
        </div>

的CSS:

.grid_3{
background-color: orange;
margin-bottom:10px;}

.grid_9 {
background-color: pink;}

.highlightednews{
float:left;}

.featurednews{
float:right;
background-color:green;
clear:both;}

1 个答案:

答案 0 :(得分:0)

这里的问题与嵌套元素的方式有关。你需要有两个父div来保存你的内容

<!-- THIS IS THE LEFT COLUMN -->
<div class="grid_9">
    <div class="grid_3">
        NEWS ITEM
    </div>
    <div class="grid_3">
        NEWS ITEM
    </div>
    <div class="grid_3">
        NEWS ITEM
    </div>
    <div class="grid_9">
        Full width item
    </div>
</div>

<!-- THIS IS THE RIGHT COLUMN -->
<div class="grid_3">
    <div>FEATURED NEWS ITEM</div>
    <div>FEATURED NEWS ITEM</div>
</div>