{"id":237,"date":"2012-10-24T13:15:31","date_gmt":"2012-10-24T04:15:31","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=237"},"modified":"2018-11-14T16:33:59","modified_gmt":"2018-11-14T07:33:59","slug":"scss_mixin","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2012\/10\/24\/scss_mixin\/","title":{"rendered":"scss\u3067mixin\u3092\u4f5c\u3063\u3066\u307f\u305f"},"content":{"rendered":"
\u521d\u3081\u307e\u3057\u3066\u3002\u5bfa\u5ca1\u3067\u3059\u3002<\/p>\n
\u666e\u6bb5\u306fRails\u3068\u622f\u308c\u308b\u304a\u4ed5\u4e8b\u3092\u3057\u3066\u3044\u307e\u3059\u3002
\n\u4eca\u56de\u306fscss\u3067\u30bf\u30d6\u30d0\u30fc\u3092\u8868\u73fe\u3059\u308bmixin\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
scss\u306fRails3.1\u304b\u3089\u6a19\u6e96\u642d\u8f09\u3055\u308c\u305f\u6a5f\u80fd\u3067\u3001\u65e2\u5b58\u306ecss\u3068\u4e92\u63db\u6027\u304c\u9ad8\u3044\u6587\u6cd5\u3067\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002 \u307e\u305a\u306f\u3001rails-compass\u3068\u3044\u3046gem\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002 \u307e\u305a\u306f\u3001app\/assets\/stylesheets\/application.css\u3092app\/assets\/stylesheets\/application.css.scss\u306b\u30ea\u30cd\u30fc\u30e0\u3057\u307e\u3059\u3002 scss\u3092\u5229\u7528\u3059\u308b\u6e96\u5099\u304c\u6574\u3063\u305f\u3068\u3053\u308d\u3067\u3001\u672c\u984c\u306eapp\/assets\/stylesheets\/tab-bar.css.scss\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 html\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002 application.css.scss\u306b\u8a18\u8ff0\u3059\u308b\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u3067\u3059\u3002 \u3053\u308c\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30ab\u30e9\u30d5\u30eb\u306a\u30bf\u30d6\u30d0\u30fc\u306e\u51fa\u6765\u4e0a\u304c\u308a\u3067\u3059\uff01\uff01<\/p>\n scss\u3092\u5229\u7528\u3059\u308b\u3068\u3001\u518d\u5229\u7528\u53ef\u80fd\u306a\u30b9\u30bf\u30a4\u30eb\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3001 \u521d\u3081\u307e\u3057\u3066\u3002\u5bfa\u5ca1\u3067\u3059\u3002<\/p>\n \u666e\u6bb5\u306fRails\u3068\u622f\u308c\u308b\u304a\u4ed5\u4e8b\u3092\u3057\u3066\u3044\u307e\u3059\u3002 scss\u306fRails3.1\u304b\u3089\u6a19\u6e96\u642d\u8f09\u3055\u308c\u305f\u6a5f\u80fd\u3067\u3001\u65e2\u5b58\u306ecss\u3068\u4e92\u63db\u6027\u304c\u9ad8\u3044\u6587\u6cd5\u3067\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<\/a><\/p>\n
scss\u3063\u3066\u4f55\uff1f<\/h2>\n
\nscss\u306f\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3067\u89e3\u91c8\u3055\u308c\u3001\u30d6\u30e9\u30a6\u30b6\u306b\u9001\u4fe1\u3055\u308c\u308b\u969b\u306fcss\u3068\u3057\u3066\u51fa\u529b\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u5074\u3067\u65b0\u305f\u306b\u5bfe\u5fdc\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u3001\u306a\u3069\u306e\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002
\nscss\u3092\u5229\u7528\u3059\u308b\u3068\u3001\u5909\u6570\u3084mixin\u3068\u547c\u3070\u308c\u308b\u90e8\u5206\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u99c6\u4f7f\u3057\u305f\u518d\u5229\u7528\u6027\u306e\u9ad8\u3044\u30b9\u30bf\u30a4\u30eb\u3092\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<\/p>\nrails-compass\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n
\nCompass\u306fscss(sass)\u3092\u5229\u7528\u3059\u308b\u4e0a\u3067\u975e\u5e38\u306b\u4fbf\u5229\u3067\u6c4e\u7528\u7684\u306amixin\u7b49\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002
\nhttp:\/\/compass-style.org\/<\/a>
\n\u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001\u30af\u30ed\u30b9\u30d6\u30e9\u30a6\u30b6\u5bfe\u5fdc\u3057\u305f\u30b0\u30e9\u30c7\u30fc\u30b7\u30e7\u30f3\u3001box-shadow\u3001border-radius\u306a\u3069\u306b\u5229\u7528\u3057\u307e\u3057\u305f\u3002
\n\u975e\u5e38\u306b\u4fbf\u5229\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u306e\u3067\u3001scss\u3092\u5229\u7528\u3059\u308b\u5834\u5408\u306f\u662f\u975e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002
\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u306f\u3001Gemfile\u306bgem \"rails-compass\"\u3092\u8ffd\u8a18\u3057\u3001bundle install\u3092\u5b9f\u884c\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\napplication.css\u3067scss\u3092\u4f7f\u3046<\/h2>\n
\n\u3053\u308c\u3060\u3051\u3067scss\u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
\n\u4eca\u56de\u306fapplication.css.scss\u4ee5\u5916\u306e\u30d5\u30a1\u30a4\u30eb\u306fscss\u306e@import\u69cb\u6587\u3092\u5229\u7528\u3057\u3066\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u306e\u3067\u3001
\n*= require_self
\n*= require_tree .
\n\u306e\u6307\u5b9a\u306f\u524a\u9664\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\ntab-bar.css.scss\u306e\u4f5c\u6210<\/h2>\n
\n\u4ee5\u4e0b\u304ctab-bar.css.scss\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n@import \"compass\";\r\n\r\n%clearfix {\r\n *zoom: 1;\r\n :before,\r\n :after {\r\n display: block;\r\n height: 0;\r\n visibility: hidden;\r\n content: \"\\0020\";\r\n }\r\n\r\n :after {\r\n clear: both;\r\n }\r\n}\r\n\r\n$DEFAULT_RADIUS: 5px !default;\r\n@mixin row-top-radius($radius: $DEFAULT_RADIUS) {\r\n :first-child {\r\n @include border-top-left-radius($radius);\r\n }\r\n :last-child {\r\n @include border-top-right-radius($radius);\r\n }\r\n :only-child {\r\n @include border-top-radius($radius);\r\n }\r\n}\r\n\r\n@mixin tab-bar($color: #ccc, $radius: $DEFAULT_RADIUS) {\r\n $border_color: darken($color, 10);\r\n $highlight_color: lighten($color, 50);\r\n $contrast-color: contrast-color(darken($color, 30));\r\n @extend %cliearfix;\r\n display: table;\r\n border: 1px solid $border_color;\r\n @include border-top-radius($radius);\r\n @include box-shadow(0 1px 1px $border_color);\r\n a {\r\n @include link-colors($contrast-color);\r\n text-decoration: none;\r\n }\r\n > * {\r\n color: $contrast-color;\r\n padding: 0.2em;\r\n display: block;\r\n float: left;\r\n border-top: 1px solid $highlight_color;\r\n border-left: 1px solid $border_color;\r\n border-right: none;\r\n background-color: $color;\r\n @include background(linear-gradient(center top , lighten($color, 30), $color));\r\n }\r\n > *:hover {\r\n background-color: lighten($color, 50);\r\n @include background(linear-gradient(center top , lighten($color, 50), lighten($color, 20)));\r\n }\r\n > :first-child {\r\n border-left: none;\r\n }\r\n @include row-top-radius($radius);\r\n}<\/pre>\n
tab-bar mixin\u3092\u5229\u7528\u3057\u3066\u307f\u308b<\/h2>\n
\n\u30af\u30e9\u30b9\u540d\u3084\u30bf\u30b0\u306a\u3069\u304c\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u6210\u3067\u3059\u3002<\/p>\n<div class=\"tab-bar1\">\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc1<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc2<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc3<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc4<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc5<\/a>\r\n<\/div>\r\n\r\n<div class=\"tab-bar2\">\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc1<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc2<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc3<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc4<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc5<\/a>\r\n<\/div>\r\n\r\n<div class=\"tab-bar3\">\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc1<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc2<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc3<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc4<\/a>\r\n\u00a0 <a href=\"#\">\u30e1\u30cb\u30e5\u30fc5<\/a>\r\n<\/div>\r\n\r\n<navi>\r\n\u00a0 <ul>\r\n\u00a0\u00a0\u00a0 <li><a href=\"#\">\u30e1\u30cb\u30e5\u30fc1<\/a><\/li>\r\n\u00a0\u00a0\u00a0 <li><a href=\"#\">\u30e1\u30cb\u30e5\u30fc2<\/a><\/li>\r\n\u00a0\u00a0\u00a0 <li><a href=\"#\">\u30e1\u30cb\u30e5\u30fc3<\/a><\/li>\r\n\u00a0\u00a0\u00a0 <li><a href=\"#\">\u30e1\u30cb\u30e5\u30fc4<\/a><\/li>\r\n\u00a0\u00a0\u00a0 <li><a href=\"#\">\u30e1\u30cb\u30e5\u30fc5<\/a><\/li>\r\n\u00a0 <\/ul>\r\n<\/navi><\/pre>\n
\n@import \"tab-bar\"; \u3067\u4e0a\u8a18\u3067\u5b9a\u7fa9\u3057\u305fscss\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001
\n@include tab-bar; \u3067\u5b9a\u7fa9\u3057\u305f\u30df\u30c3\u30af\u30b9\u30a4\u30f3\u3092\u7d44\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\n@include tab-bar(#ccc);\u306e\u3088\u3046\u306b\u5f15\u6570\u3092\u6e21\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n@import \"tab-bar\";\r\n.tab-bar1 {\r\n margin: 10px;\r\n @include tab-bar;\r\n}\r\n\r\n.tab-bar2 {\r\n margin: 10px;\r\n @include tab-bar(#00f);\r\n}\r\n\r\n.tab-bar3 {\r\n margin: 10px;\r\n @include tab-bar(#f00);\r\n}\r\n\r\nnavi ul {\r\n margin: 10px;\r\n padding: 0;\r\n @include tab-bar(#000);\r\n}<\/pre>\n
<\/a><\/p>\n
\u307e\u3068\u3081<\/h2>\n
\nmixin\u3092\u4e00\u5ea6\u8a18\u8ff0\u3057\u3066\u3057\u307e\u3048\u3070\u3001\u4ed6\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u305d\u306e\u307e\u307e\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002
\n\u5c71\u306e\u3088\u3046\u306a\u30af\u30e9\u30b9\u5b9a\u7fa9\u3092\u66f8\u304f\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u306e\u3067\u3001scss\u3092\u4f7f\u3063\u3066\u3044\u308b\u3068\u81ea\u7136\u3068\u30b7\u30f3\u30d7\u30eb\u306aHTML\u306b\u306a\u3063\u3066\u3044\u304d\u307e\u3059\u3002
\n\u6c4e\u7528\u7684\u306amixin\u3092\u4f5c\u308b\u306e\u306f\u5927\u5909\u3067\u3059\u304c\u3001\u52b4\u529b\u4ee5\u4e0a\u306e\u52b9\u679c\u304c\u4f53\u611f\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u4e00\u5ea6\u304a\u8a66\u3057\u304f\u3060\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"
\n\u4eca\u56de\u306fscss\u3067\u30bf\u30d6\u30d0\u30fc\u3092\u8868\u73fe\u3059\u308bmixin\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
\nscss\u306f\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3067\u89e3\u91c8\u3055\u308c\u3001\u30d6\u30e9\u30a6\u30b6\u306b\u9001\u4fe1\u3055\u308c\u308b\u969b\u306fcss\u3068\u3057\u3066\u51fa\u529b\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u5074\u3067\u65b0\u305f\u306b\u5bfe\u5fdc\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u3001\u306a\u3069\u306e\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002
\nscss\u3092\u5229\u7528\u3059\u308b\u3068\u3001\u5909\u6570\u3084mixin\u3068\u547c\u3070\u308c\u308b\u90e8\u5206\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u99c6\u4f7f\u3057\u305f\u518d\u5229\u7528\u6027\u306e\u9ad8\u3044\u30b9\u30bf\u30a4\u30eb\u3092\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[30,22,31],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":18027,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions\/18027"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}