{"id":1336,"date":"2012-06-02T16:41:08","date_gmt":"2012-06-02T08:41:08","guid":{"rendered":"http:\/\/leegorous.net\/blog\/?p=1336"},"modified":"2012-06-02T16:48:07","modified_gmt":"2012-06-02T08:48:07","slug":"replace-beginning-matching-attribute-selector-in-less","status":"publish","type":"post","link":"http:\/\/leegorous.net\/blog\/2012\/06\/02\/replace-beginning-matching-attribute-selector-in-less\/","title":{"rendered":"Replace [class*=&#8221;span&#8221;] in LESS"},"content":{"rendered":"<p><a href=\"http:\/\/twitter.github.com\/bootstrap\/\">Bootstrap<\/a> \u91cc\u7684 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Grid_%28page_layout%29#Grid_use_in_web_design\">grid system<\/a> \u91cc\u9762 (<a href=\"https:\/\/github.com\/twitter\/bootstrap\/blob\/master\/less\/mixins.less\">\u6e90\u4ee3\u7801<\/a>) \u6709\u8fd9\u4e48\u4e00\u6bb5\uff0c<\/p>\n<pre class=\"brush: css\">\r\n[class*=&quot;span&quot;] {\r\n  float: left;\r\n  margin-left: @gridGutterWidth;\r\n}\r\n<\/pre>\n<p>\u7528 <a href=\"https:\/\/github.com\/twitter\/recess\">RECESS<\/a> \u53bb\u8dd1\u4f1a\u770b\u5230\u63d0\u793a\uff1a<code>Universal selectors should be avoided<\/code>\u3002\u8fd9\u4e2a\u65e2\u53ef\u4ee5\u8bf4<a href=\"https:\/\/github.com\/twitter\/recess\/issues\/15\">\u662f selector \u7684\u95ee\u9898\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u662f RECESS \u7684\u95ee\u9898<\/a>\uff0c\u4f46\u53ef\u4ee5\u5728\u8fd0\u884c\u7684\u65f6\u5019\u52a0\u4e2a\u53c2\u6570\u5ffd\u7565\u6389\u3002<\/p>\n<p>\u81ea\u5df1\u53bb\u5199\u6269\u5c55\u65f6\u4e5f\u4f1a\u5199\u5230\u7c7b\u4f3c\u7684\u89c4\u5219\uff0c\u6bd4\u5982\u9700\u8981\u517c\u5bb9\u67d0\u6d4f\u89c8\u5668\uff0c\u5982\u679c\u4e0d\u8fd9\u6837\u5199\uff0c\u5c31\u4f1a\u9700\u8981\u50cf <a href=\"https:\/\/github.com\/empowering-communities\/Bootstrap-IE6\">Bootstrap-IE6<\/a> \u90a3\u6837\u5199<!--more--><\/p>\n<pre class=\"brush: css\">\r\n.span1, .span2, .span3, .span4, .span5, .span6, \r\n.span7, .span8, .span9, .span10, .span11, .span12 {\r\n  float: left;\r\n  display: inline;\r\n}\r\n<\/pre>\n<p>\u4f46\u8fd9\u6837\u592a\u4e11\u964b\u50f5\u5316\u4e86\uff0c\u800c\u4e14\u7ecf\u4e0d\u8d77\u53d8\u5316\uff0c\u5f53\u6211\u4f7f\u7528 16 \u6805\u683c\u6216\u8005\u5176\u5b83\u975e 12 \u6805\u683c\u65f6\uff0c\u5c31\u975e\u5e38\u88ab\u52a8\u3002<\/p>\n<p><a href=\"http:\/\/leegorous.net\/blog\/2012\/06\/02\/replace-beginning-matching-attribute-selector-in-less\">\u5982\u679c\u4e0d\u4f7f\u7528 [attr*=val]<\/a>\uff0c\u4e0d\u77e5\u9053 LESS \u662f\u5426\u6709\u73b0\u6210\u7684\u4e1c\u897f\u6765\u7b80\u5316\u3002\u6211\u8bbe\u60f3\u4f1a\u4e0d\u4f1a\u6709\u7c7b\u4f3c\u4e8e <code>\".span\" + [1..@{gridColumns}]<\/code> \u7684\u7279\u6027\u652f\u6301\u3002\u55ef\uff0c\u662f\u6709\u70b9\u8fc7\u4e8e\u7f8e\u597d\u4e86\u3002<\/p>\n<p>\u4f46\u662f LESS \u652f\u6301\u8fd0\u884c JavaScript\uff0c\u8fd9\u91cc\u6ca1\u6709\u592a\u590d\u6742\u7684\u8fd0\u7b97\uff0c\u53ea\u662f\u5b57\u7b26\u4e32\u8fed\u4ee3\u62fc\u63a5\uff0c\u611f\u89c9\u53ef\u884c\uff0c\u4e8e\u662f\u6709\u4e86\u4e0b\u9762\u8fd9\u4e2a\u3002<\/p>\n<pre class=\"brush: css\">\r\n\/\/ Modify this for custom colors, font-sizes, etc\r\n@import &quot;variables.less&quot;; \r\n\r\n\/\/ equals [class*=&quot;span&quot;]\r\n(~`(function(pf,c){var a=[];while(c&gt;0){a.push(pf+c);c--;}return a.join(&#039;,&#039;);})(&#039;.span&#039;,parseInt(&quot;@{gridColumns}&quot;))`) {\r\n  float: left;\r\n  margin: 0 @gridGutterWidth 0 0;\r\n}\r\n<\/pre>\n<p>\u7531\u4e8e\u53ea\u6709\u4e00\u884c\uff0c\u5c3d\u91cf\u7b80\u5316\u4e86\u3002<code>pf<\/code> \u662f\u524d\u7f00 prefix \u7684\u610f\u601d\uff0c<code>c<\/code> \u662f\u8fed\u4ee3\u9879\uff0c\u5165\u53c2\u503c\u4e3a <code>parseInt(\"@{gridColumns}\")<\/code>\uff0c\u8fd9\u6837\u53d8\u5316\u5c31\u7531 variables.less \u63a7\u5236\u4e86\u3002\u770b\u8d77\u6765\u4e0d\u662f\u5f88\u76f4\u89c2\uff0c\u52a0\u4e2a\u6ce8\u91ca\u58f0\u660e\u4e86\u4e00\u4e0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bootstrap \u91cc\u7684 grid system \u91cc\u9762 (\u6e90\u4ee3\u7801) \u6709\u8fd9\u4e48\u4e00\u6bb5\uff0c [class*=&quot; &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/leegorous.net\/blog\/2012\/06\/02\/replace-beginning-matching-attribute-selector-in-less\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cReplace [class*=&#8221;span&#8221;] in LESS\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[102,3],"tags":[7,9,84],"_links":{"self":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/1336"}],"collection":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/comments?post=1336"}],"version-history":[{"count":7,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/1336\/revisions"}],"predecessor-version":[{"id":1343,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/1336\/revisions\/1343"}],"wp:attachment":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/media?parent=1336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/categories?post=1336"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/tags?post=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}