GithubHelp home page GithubHelp logo

task-stage3-practice's People

Contributors

clect avatar

Watchers

 avatar

task-stage3-practice's Issues

关于CSS封装的一个想法

目前的格式是这样的

<div class="fourPic">
  <img class="fir" />
  <img class="sec" />
  <img class="thi" />
  <img class="fou" />
</div>

个人觉得使用上需要遵守的约定太多。我一向是认为约定越少越好,也省去了查文档的麻烦。


所以我打算参考 http://stackoverflow.com/questions/8720931/can-css-detect-the-number-of-children-an-element-has ,想把CSS封装成这样的格式:

<div class="album">
  <img />
  <img />
  <img />
  <img />
</div>

图片数量不同的样式交给框架的CSS去自动实现,不是人为的规定哪个是fir,哪个是sec。
四张图片的样式可以这样实现:

.album > img:first-child:nth-last-child(4) {
  /* fir */
}
.album > img:first-child:nth-last-child(4) ~ img:nth-of-type(2) {
  /* sec */
}
.album > img:first-child:nth-last-child(4) ~ img:nth-of-type(3) {
  /* thi */
}
.album > img:first-child:nth-last-child(4) ~ img:nth-of-type(4) {
  /* fou */
}

这样对于div来说只需要设置上"album"作为className即可实现任务要求的布局。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.