luckylion
V2EX  ›  CSS

css 中的一个参数忘记了

  •  
  •   luckylion · May 6, 2015 · 4855 views
    This topic created in 4219 days ago, the information mentioned may be changed or developed.

    <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 replies  •  2015-05-06 18:40:28 +08:00
    January
    January
    PRO
    May 6, 2015❤️1
    1
    在ul上设置一个等值的负margin?
    luckylion
    luckylion
    OP
    May 6, 2015
    2
    @January 不是
    li{float:left;margin-right:20px; 在这儿直接定义的 }
    bunorte
    bunorte
    May 6, 2015❤️1
    3
    li:nth-child(3n){margin-right:0}
    kingwrcy
    kingwrcy
    May 6, 2015❤️1
    4
    li:nth-child(3n){
    margin-right:0;
    }
    luckylion
    luckylion
    OP
    May 6, 2015
    5
    是 nth-child
    感谢
    Gonster
    Gonster
    May 6, 2015 via iPhone
    6
    楼主你问的这个叫css的伪类(Pseudo-classes)
    jankan
    jankan
    May 6, 2015
    7
    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%;}
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2500 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 12:00 · PVG 20:00 · LAX 04:00 · JFK 07:00
    ♥ Do have faith in what you're doing.