技术控

    今日:130| 主题:49332
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Custom Attributes for our Spacing Classes

[复制链接]
Smilingatme嫣然 发表于 2016-9-30 17:49:18
79 1

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
While using this method on our projects, we noticed our class attribute was getting extremely cluttered with a variety of spacing classes on a single element. Here’s an example:
  As you can see, there’s an overload of spacing-based class names littering the codebase. Scanning over this code with your text editor or devtools can become overwhelming. So how can we simplify this?Mark and I discussed a possible solution for this problem and came up with something like this:  
  We decided to use a custom attribute called `spacing` to separate our spacing classes from the stylistic classes. Our spacing classes only handle margin top while our stylistic classes set the background, borders, padding, etc. This ensures all the classes applied to an element are specifically for visual styling whereas any value in the spacing attribute is specifically for our vertical spacing throughout the project.
      SCSSFile  

  Here is a snippet of our    .spacing.scss. We are using    include-mediato handle our media queries.  
  In this snippet, we are defining our spacing variables as well as setting our default    CSSrulesets. we use a complex    CSSselector to provide two collaborative, abilities. First, the ‘begins with’ selector is used to allow a default spacing to be set. Then using a wildcard match we can override that spacing on specific breakpoints using our custom `large()` syntax”. In some cases the spacing can vary from screen size to screen size. Following our default classes, we have a    CSSruleset to target spacing at different screen sizes.  
  Following the default spacing classes, we’re using    CSSselectors to target any value in our attribute. If we don’t define `xsmall-xlarge` then it won’t be available. This is to keep the generated    CSSsize small and reduce extraneous code that we may never even use.  
  Putting it all together

  The browser reads the example like this:  
  
       
  • Give each direct child of the article element a margin-top of 14px on small screens and 20px on large screens.   
  • For small to medium screens, give the direct child elements a margin top of 10px   
  • On large screens give the direct child elements a margin-top of 60px  
  Some may ask, why aren’t you using “data-” to define your custom attribute? This is still up for discussion here on the development team. Sure, we might run into some issues further down the line, but that’s as easy as doing a `replace all` to fix our spacing attributes. We’re testing this method with one of our current projects and it’s going pretty smoothly. Does adding “data-” to our custom attribute really matter nowadays? I’d like to hear your opinions.
友荐云推荐




上一篇:Linux基础:文件权限
下一篇:Personalized Group Recommendations Are Here
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

MR._ZHAO 发表于 2016-11-1 03:11:30
顶起!
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表