V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
tianzhen
V2EX  ›  CSS

是否可以直接通过 BEM 命名规则来定位元素(忽略 html tag 和 id)

  •  
  •   tianzhen · Mar 19, 2016 · 2945 views
    This topic created in 3691 days ago, the information mentioned may be changed or developed.

    刚接触 BEM ,还在尝试理解中,问题很小白,见笑了,还望高人指点一二。 如题,是否可以直接通过 BEM 命名规则来定位元素,那 html tag 和 id 定位都用不上咯?(当时不是适用于所有的情况)

    来个🌰吧

    <header>
        <h1 class="header__title">xxx</h1>
        <p class="header__description">xxx</p>
    </header>
    

    在没有 BEM 命名的时候,我可能需要通过 header h1 (html tag name) 来定位元素,或者给 h1 元素一个 header-title 的 id ,通过 id 对其进行定位,用了 BEM 命名后,貌似很多情况都可以通过 BEM 来精确描述元素,将其定位咯?

    1 replies    2016-03-20 00:33:29 +08:00
    emric
        1
    emric  
       Mar 20, 2016 via iPhone
    对的,这就是它的优势。
    不过该用还得用,命名的东西不用想太多。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   961 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 20:23 · PVG 04:23 · LAX 13:23 · JFK 16:23
    ♥ Do have faith in what you're doing.