{"id":765,"date":"2019-11-20T07:05:20","date_gmt":"2019-11-20T07:05:20","guid":{"rendered":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/?p=765"},"modified":"2019-11-20T08:04:36","modified_gmt":"2019-11-20T08:04:36","slug":"sass-link-styling","status":"publish","type":"post","link":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/2019\/11\/20\/sass-link-styling\/","title":{"rendered":"Sass Link Styling"},"content":{"rendered":"\n<p>Every website uses anchor tags to style links. This is an example of a way that you can use Sass to quickly style links. You can define the link color with your other colors for your site and then by changing the Sass $link-color variable you&#8217;ll change the color for all of your links. <\/p>\n\n\n\n<p>This code below is intended for your main site links. You will most likely style your navigation links a bit differently with some separate CSS. <\/p>\n\n\n\n<p>Here is the snippet of code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror cm-s-monokai\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/x-scss&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;SCSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;scss&quot;}\">\/\/Sass color variables\n$link-color: #4478A6;\n$hover-color: darken($link-color, 20%);\n$visited-color: lighten($link-color, 20%);\n\n\/\/link styling\na{\n  color: $link-color;\n  text-decoration: none;\n  \n  &amp;:hover{\n    color: $hover-color;\n    border-bottom: 1px solid $hover-color;\n  }\n  \n  &amp;:visited{\n    color: $visited-color;\n    border-color: $visited-color;\n  }\n}\n  <\/pre><\/div>\n\n\n\n<p>You can change $link-color in line 2 to a different color and your links will change. <\/p>\n\n\n\n<p>If you want to set each color for the link, hover and visited states then also replace the <strong>darken(&#8230;)<\/strong> and <strong>lighten(&#8230;)<\/strong> values for $hover-color and $visited color with your own colors. For example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror cm-s-monokai\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/x-scss&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;SCSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;scss&quot;}\">$link-color: #4478A6;\n$hover-color: #bf8822;\n$visited-color: #ffaa66;<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Using Transitions for Animation<\/h4>\n\n\n\n<p>CSS transitions allow you to add some movement when people hover. Here are two examples. The first one adds a background color and the second one adds an animated bottom border.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Animated Background Color<\/h5>\n\n\n\n<p>This example is relatively simple, adding a background color on hover and adding a transition to the background and padding (the padding on top and bottom gives the highlight a little breathing room).<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror cm-s-monokai\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/x-scss&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;SCSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;scss&quot;}\">\/\/Sass color variables\n$link-color: #4478A6;\n$hover-color: darken($link-color, 20%);\n$visited-color: lighten($link-color, 20%);\n\n\/\/link styling\na{\n    color: $link-color;\n    text-decoration: none;\n    background: transparent;\n    transition: background 1s ease, padding 1s ease;\n\n    &amp;:hover{\n      color: $hover-color;\n      background: lighten($hover-color, 65%);\n      padding: 4px 0;\n    }\n\n    &amp;:visited{\n      color: $visited-color;\n    }\n  }<\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">Animated Bottom Border<\/h5>\n\n\n\n<p>This transition is a bit more complex because we are using Scale to animate the border changing width. Because we can&#8217;t apply scale directly to the link element or the entire link will scale we&#8217;re using the :before pseudo element.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror cm-s-monokai\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/x-scss&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;SCSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;scss&quot;}\">\/\/Sass color variables\n$link-color: #4478A6;\n$hover-color: darken($link-color, 20%);\n$visited-color: lighten($link-color, 20%);\n\na{\n    color: $link-color;\n    text-decoration: none;\n    position: relative;\n    \n    \/\/this creates a 1px border at the bottom of the link. It's make invisible by setting scaleX to 0\n    &amp;:before{\n      content: '';\n      position: absolute;\n      left: 0;\n      bottom: 0;\n      width: 100%;\n      border-bottom: 1px solid $hover-color;\n      transform:  scaleX(0); \/\/hides link initially\n      transition: transform .5s ease;\n    }\n    \/\/this makes the line visible by setting the scaleX to 1. It animates because a transition has been set.\n    &amp;:hover:before {\n      transform:  scaleX(1);\n    }\n   \n    \/\/changes the color of text on hover\n    &amp;:hover{\n      color: $hover-color;\n    }\n  \n    \/\/changes the color of text for visited\n    &amp;:visited{\n      color: $visited-color;\n    }\n}\/\/end link styling<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Every website uses anchor tags to style links. This is an example of a way that you can use Sass to quickly style links. You can define the link color with your other colors for your site and then by changing the Sass $link-color variable you&#8217;ll change the color for all of your links. This [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"portfolio_post_id":0,"portfolio_citation":"","portfolio_annotation":"","openlab_post_visibility":"","footnotes":""},"categories":[8,7],"tags":[122,121,115,119],"class_list":{"0":"post-765","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-code","8":"category-resource","9":"tag-anchor","10":"tag-link","11":"tag-sass","12":"tag-snippet","13":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/posts\/765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/comments?post=765"}],"version-history":[{"count":22,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/posts\/765\/revisions"}],"predecessor-version":[{"id":789,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/posts\/765\/revisions\/789"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/media\/794"}],"wp:attachment":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/media?parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/categories?post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-240-fall-19-stein\/wp-json\/wp\/v2\/tags?post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}