Replace BootStrap with less JS [class*= "span"]

Source: Internet
Author: User

In the Bootstrap grid system (source code) There is this paragraph,

[class*= "Span"] {  float:left;  Margin-left: @gridGutterWidth;}

To run with recess, you'll see a hint: Universal selectors should be avoided。 This can be said to be a selector problem, but also can be said to be a recess problem, but can be run at the time of adding a parameter ignored.

When you write the extension yourself, you will write similar rules, such as the need to be compatible with a browser, if not, you will need to write like Bootstrap-ie6

. Span1,. span2,. Span3,. Span4,. Span5,. Span6,.span7,. Span8,. Span9,. Span10,. Span11,. span12 {  float:left;  Display:inline;}

But this is too ugly and inflexible, and can not stand the change, when I use 16 grid or other non-12 grid, it is very passive.

If [Attr*=val] is not used, it is not known if less has something ready to simplify. I'm assuming there will be similar ".span" + [[email protected]{gridColumns}] feature support. Well, it's a little too good.

But less support for running JavaScript, there is no too complicated operation, but the string iterative stitching, feel feasible, so there is the following.

Modify this for custom colors, font-sizes, etc@import "variables.less"; equals [class*= "span"] (function (pf,c) {var a=[];while (c>0) {A.push (pf+c); c--;} Return A.join (', ');}) ('. span ', parseint ("@{gridcolumns}")) {  float:left;  margin:0 @gridGutterWidth 0 0;}

JS as follows: (function (pf,c) {var a=[];    while (c>0) {A.push (pf+c);  c--; } return A.join (', ');}) ('. span ', parseint ("@{gridcolumns}"))

Because there is only one line, try to simplify it. pfis the meaning of the prefix prefix, c is the iteration, the entry parameter value is parseInt("@{gridColumns}") , so the change is controlled by variables.less. It doesn't look very intuitive, add a note to the statement.

Replace BootStrap with less JS [class*= "span"]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.