V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Can I use?
http://caniuse.com/
Less
http://lesscss.org
Cool Libraries
Bootstrap from Twitter
Jetstrap
luckylion
V2EX  ›  CSS

css 中的一个参数忘记了

  •  
  •   luckylion · 2015-05-06 17:59:26 +08:00 · 3694 次点击
    这是一个创建于 3279 天前的主题,其中的信息可能已经有所发展或是发生改变。

    <ul>
    <li>....<li>
    <li>....<li>
    <li>....<li>
    <li>....<li>
    ......
    </ul>

    li{float:left;margin-right:20px;}

    记得css有个参数可以把固定间隔li中margin属性消掉
    比如一横排显示3个,那个参数就把3 6 9...li中margin-right:20px覆盖成0

    这个参数是什么

    7 条回复    2015-05-06 18:40:28 +08:00
    January
        1
    January  
       2015-05-06 18:05:54 +08:00   ❤️ 1
    在ul上设置一个等值的负margin?
    luckylion
        2
    luckylion  
    OP
       2015-05-06 18:08:30 +08:00
    @January 不是
    li{float:left;margin-right:20px; 在这儿直接定义的 }
    bunorte
        3
    bunorte  
       2015-05-06 18:08:31 +08:00   ❤️ 1
    li:nth-child(3n){margin-right:0}
    kingwrcy
        4
    kingwrcy  
       2015-05-06 18:09:59 +08:00   ❤️ 1
    li:nth-child(3n){
    margin-right:0;
    }
    luckylion
        5
    luckylion  
    OP
       2015-05-06 18:11:02 +08:00
    是 nth-child
    感谢
    Gonster
        6
    Gonster  
       2015-05-06 18:17:25 +08:00 via iPhone
    楼主你问的这个叫css的伪类(Pseudo-classes)
    jankan
        7
    jankan  
       2015-05-06 18:40:28 +08:00
    lz这么写是不好的

    应该学习bootstrap的写法, margin改为padding来解决
    不过要把box-size改一下
    *,
    *:before,
    *:after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    }
    ul {margin:0 -20px}
    li {float:left;padding:0 20px;width:33.333333%;}
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1691 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:32 · PVG 00:32 · LAX 09:32 · JFK 12:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.