简体   繁体   English

清除浮动列表项

[英]Clearing floated list items

Hi I'm having trouble clearing my list items that I've floated left As you can see from my jsFiddle the first list item is pushing the third item across messing up the layout.嗨,我在清除我向左浮动的列表项时遇到问题 正如您从我的 jsFiddle 中看到的,第一个列表项将第三个项推到了布局上。 See my jsFiddle看我的jsFiddle

<style>

.wrap {
    width:960px;
    margin:0 auto;
    overflow:hidden;
}

ul.team-members {
    overflow:hidden;
}

ul.team-members li {
    float:left;
    width:450px;
    margin-bottom:40px;
}

ul.team-members li img {
    float:left;
    width:120px;
    padding-right:20px;
}

ul.team-members li p {
    float:left;
    width:310px;
    margin:0;
}
</style>

    <section class="wrap">

        <h1>Our Team</h1>

        <div class="store">

            <h2>Monmouth</h2>

            <ul class="team-members">

                <li>
                    <img src="_/img/t-member.jpg">
                    <p><strong>Maureen</strong> - who is originally from Fife is our longest serving member of staff. Qualified to City & Guilds level in soft furnishings, Maureen is always keen to offer advice on projects, colour schemes, fabrics and trimmings. We have an 'Ask Maureen' option on our homepage where you can ask any soft furnishing or window treatment related question, the trickier the better as she loves a challenge!</p>
                </li>
                <li>
                    <img src="_/img/t-member.jpg">
                    <p><strong>Rosyln</strong> - is known for her bubbly welcoming approach to all customers and is always keen to help with advice on the selection of suitable fabrics for your curtains, blinds or upholstery.</p>
                </li>
                <li>
                    <img src="_/img/t-member.jpg">
                    <p><strong>Clare</strong> - has a background in interior design and is very experienced and knowledgeable on fabric choices, tracks, poles and the full spectrum of soft furnishing and upholstery options.</p>
                </li>
                <li>
                    <img src="_/img/t-member.jpg">
                    <p><strong>Ann</strong> - Manages our team, our workrooms and arranges installation in conjunction with our.</p>
                </li>

            </ul>

        </div>
</section>

Jeez I should know how to do this, mind has gone blank!天哪,我应该知道怎么做的,脑子里一片空白! Any Ideas?有任何想法吗?

Remove float:left and use display: inline-block; vertical-align: top;删除float:left并使用display: inline-block; vertical-align: top; display: inline-block; vertical-align: top;

ul.team-members li {
   display: inline-block; vertical-align: top;
    width:450px;
    margin-bottom:40px;
}

DEMO演示

Demo演示

Hi now used to :nth-of-type(odd)嗨,现在习惯了:nth-of-type(odd)

as like this像这样

ul.team-members li:nth-of-type(odd){
clear:both;
}

Live demo现场演示

Try this:尝试这个:

ul.team-members li {
float:left;
width:450px;
margin-bottom:40px;
clear: both;
}

Use display: inline-block;使用display: inline-block; instead of float: left;而不是float: left; . . Also don't forget to use vertical-align: top;也不要忘记使用vertical-align: top; to align the containers correctly.正确对齐容器。

Example: http://jsfiddle.net/EqHXP/3/示例: http : //jsfiddle.net/EqHXP/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM