<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CSS Snippets</title>
	<atom:link href="http://css-snippets.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://css-snippets.com</link>
	<description>/* Code to cut and paste into web sites */</description>
	<lastBuildDate>Sat, 30 Mar 2013 17:04:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Web Fonts &#8211; &#8216;Faux&#8217; Bold and Italic</title>
		<link>http://css-snippets.com/web-fonts-faux-bold-and-italic/</link>
		<comments>http://css-snippets.com/web-fonts-faux-bold-and-italic/#comments</comments>
		<pubDate>Sat, 30 Mar 2013 17:04:13 +0000</pubDate>
		<dc:creator>sniplisad</dc:creator>
				<category><![CDATA[CSS3]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=391</guid>
		<description><![CDATA[I have talked about web fonts before, but I ran into a new issue that made me revisit the topic. The problem came from using a @font-font kit from Font Squirrel. What happened was that I ended up getting &#8220;Faux&#8221; bold and italics on my web-page. The solution suggested from the Demo.html page that comes [...]]]></description>
				<content:encoded><![CDATA[<p>I have talked about <a href="http://css-snippets.com/web-fonts/">web fonts before</a>, but I ran into a new issue that made me revisit the topic.</p>
<p>The problem came from using a <a href="http://www.fontsquirrel.com/fonts/open-sans">@font-font kit from Font Squirrel</a>. What happened was that I ended up getting &#8220;Faux&#8221; bold and italics on my web-page. The solution suggested from the Demo.html page that comes from the kit is truly unacceptable if you want your CSS to be sanely maintainable. </p>
<p>What it comes down to is you would need to specify unique font-family anywhere you want bold or italics. You lose the ability for &#8220;cascading&#8221; and inheritance &#8211; some of the things that make CSS nice. </p>
<p>See the screen cast for more information. Here is a Table of Contents in case you don&#8217;t need the intro to web fonts that I provide in the beginning: </p>
<p>0:00 to 2:55 <em>Using Google Web Fonts</em><br />
2:55 to 4:55 <em>Getting fonts from FontSquirrel</em><br />
4:55 to 6:15 <em>Adding fonts to CSS and showing the &#8216;Faux&#8217; problem  </em><br />
6:15 to end <em>Solving the &#8216;Faux&#8217; problem and setting up different weights of your font</em></p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/h95yOJA5UJc" frameborder="0" allowfullscreen></iframe></p>
<p>See my <a href="https://github.com/lisacatalano/webfonts" target="_blank">Github repository</a> for the solution and demo code. </p>
<p>Here is the important snippet of the CSS defining the fonts. </p>
<p><script src="https://gist.github.com/lisacatalano/5228820.js"></script></p>
<p>The trick is to call all the definitions the <strong>same name</strong>. Then specify with &#8220;font-weight&#8221; or &#8220;font-style&#8221; the weight and style you want it to represent. </p>
<p>It is quite simple once you &#8220;get&#8221; it. I would never have thought to do this if I hadn&#8217;t found <a href="http://www.metaltoad.com/blog/how-use-font-face-avoid-faux-italic-and-bold-browser-styles">this article</a> to explain the solution. </p>
<p>By the way, on this website I use Myriad Pro hosted by TypeKit. When you use a service like this, just like with Google, they handle the bold and italics better, so you don&#8217;t need to worry about this issue. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/web-fonts-faux-bold-and-italic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outline on Focus</title>
		<link>http://css-snippets.com/outline-on-focus/</link>
		<comments>http://css-snippets.com/outline-on-focus/#comments</comments>
		<pubDate>Sun, 10 Mar 2013 16:00:06 +0000</pubDate>
		<dc:creator>sniplisad</dc:creator>
				<category><![CDATA[CSS3]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=385</guid>
		<description><![CDATA[I recently made a small change to this site to try to make it a little more accessible. I haven&#8217;t spent enough time thinking about that aspect of my websites. Not because I don&#8217;t care, but just because I am always so rushed, I sometimes forget. I was reading a blog post on The Accessibility [...]]]></description>
				<content:encoded><![CDATA[<p>I recently made a small change to this site to try to make it a little more accessible. I haven&#8217;t spent enough time thinking about that aspect of my websites. Not because I don&#8217;t care, but just because I am always so rushed, I sometimes forget. </p>
<p>I was reading a <a href="http://a11yproject.com/posts/never-remove-css-outlines/">blog post</a> on <a href="http://a11yproject.com/">The Accessibility Project</a> which reminded me that I wasn&#8217;t paying attention to users who like to navigate with the keyboard. That is silly, because I am sometimes one of those people.</p>
<p>Because I spend so much time on the computers, sometimes my hands hurt and I have found the mouse to part of the problem – at least the switching back and forth between keyboard and mouse. So sometimes just using the keyboard to choose a link or menu item is better than the mouse. I am trying to use more keyboard shortcuts in everything I do and use the mouse less.</p>
<p>So I realized this website didn&#8217;t handle keyboard navigation very well. If you tabbed through the top menu, you couldn&#8217;t see which menu item was &#8220;active&#8221;. That was simply because I had forgotten to style my <span class="code">a:focus</span> links.</p>
<p>So, I changed all my references to <span class="code">something:hover</span> to include <span class="code">something:focus</span> as well. </p>
<pre><code>.menu a:hover, .menu a:focus { 
  color: #317572; 
} </code></pre>
<p>I also noticed that Chrome was using an orange glow to outline elements, which doesn&#8217;t look all that nice on this color scheme. So I changed the outline on focus to <span class="code">thin dotted</span> which is the default in other browsers, and it is more subtle. </p>
<p>This then made the focus just a little less obvious, so I decided to add a light background color to things that have focus. I had to be fairly specific when determining what got the background color, however, because I didn&#8217;t want everything that was an &#8220;a&#8221; tag to get that color. </p>
<p>So my final code is: </p>
<pre><code>a:hover, a:focus { 
  color: #317572; 
  outline: thin dotted;
} 

/* specific links that should get a background color */
p a:hover, p a:focus, etc. ... { 
  background-color: #EEF7F2;
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/outline-on-focus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transform</title>
		<link>http://css-snippets.com/transform/</link>
		<comments>http://css-snippets.com/transform/#comments</comments>
		<pubDate>Sun, 30 Sep 2012 21:04:48 +0000</pubDate>
		<dc:creator>sniplisad</dc:creator>
				<category><![CDATA[CSS3]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=379</guid>
		<description><![CDATA[It has been a while! My new job this past year has kept me very busy. I&#8217;ve used so many interesting CSS techniques in my job, that I want to start posting again to document them. I&#8217;m starting with CSS3 Transformations, which I&#8217;ve been wanting to write about for over a year. The transform property [...]]]></description>
				<content:encoded><![CDATA[<p>It has been a while! My new job this past year has kept me very busy. I&#8217;ve used so many interesting CSS techniques in my job, that I want to start posting again to document them. I&#8217;m starting with CSS3 Transformations, which I&#8217;ve been wanting to write about for over a year. </p>
<p>The <a href="http://www.w3.org/TR/2012/WD-css3-transforms-20120911/" title="CSS3 Tranformations">transform </a>property allows you to apply transformations to objects on your page in the 2D space or 3D space. </p>
<p>You can change the scale of an object, rotate it flip it, for example. When combined with Transitions, you can create some very nice effects with CSS only. </p>
<pre><code>    
    /* make something larger */
    -webkit-transform: scale(1.5);
    -moz-transform: scale(1.5);
    -o-transform: scale(1.5);
    -ms-transform: scale(1.5);
    transform: scale(1.5);

    /* make something rotate */
    -webkit-transform: rotate(5deg);
    -moz-transform: rotate(5deg);
    -o-transform: rotate(5deg);
    -ms-transform: rotate(5deg);
    transform: rotate(5deg);    
</code></pre>
<p>The W3 documentation says that </p>
<blockquote><p>A transformable element is an element in the HTML namespace which is either a block-level or atomic inline-level element, or whose ‘display’ property computes to ‘table-row’, ‘table-row-group’, ‘table-header-group’, ‘table-footer-group’, ‘table-cell’, or ‘table-caption’; or an element in the SVG namespace (see [SVG11]) which has the attributes ‘transform’, ‘patternTransform’ or ‘gradientTransform’.</p></blockquote>
<p>I&#8217;ve tried to decipher this exactly, and the simple answer is that you can transform elements with are block-level, but not all inline elements. I&#8217;m not exactly sure what &#8220;atomic inline-level&#8221; means. An inline element like <strong>span</strong> does not take the transform property. However, if you change it to <em>display: inline-block</em>, it will transform. Images are inline, and they will transform. That is enough information for me to use this property. </p>
<p>The demo shows some simple transforms. I will be exploring this property in more depth when I have more time. </p>
<div class="demoButton"><a href="http://css-snippets.com/demos/transform.html">See Demo</a></div>
<h3>Browser Support</h3>
<p>This is supported by all modern browsers, including IE9. IE8 and below do not support this property. Since transformations usually fall into the nice-to-have-but-not-necessary category, I generally don&#8217;t worry about earlier IE browsers. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/transform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Different Colors Based on Position in List</title>
		<link>http://css-snippets.com/different-colors-based-on-position-in-list/</link>
		<comments>http://css-snippets.com/different-colors-based-on-position-in-list/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 00:31:26 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Navigation]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=346</guid>
		<description><![CDATA[The final change I want to make to the navigation menu, which was previously discussed in the last two posts, is to add a different color to each menu item. On a static website which doesn&#8217;t change, this is easy. You can add a class (or an id would work also) to each item, then [...]]]></description>
				<content:encoded><![CDATA[<p>The final change I want to make to the navigation menu, which was previously discussed in the last two posts, is to add a different color to each menu item. </p>
<div id="attachment_362" class="wp-caption alignnone" style="width: 188px"><img src="http://css-snippets.com/blogfile/wp-content/uploads/2011/10/menu3.jpg" alt="Menu with different colors for border" title="Menu with color" width="178" height="242" class="size-full wp-image-362" /><p class="wp-caption-text">Menu with different colors for border</p></div>
<p>On a static website which doesn&#8217;t change, this is easy. You can add a class (or an id would work also) to each item, then style each one independently. </p>
<h4>HTML</h4>
<pre><code>    &lt;ul id="nav"&gt;
      &lt;li class="home"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
      &lt;li class="tutorials"&gt;&lt;a href="#"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
      &lt;li class="about"&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt;
      &lt;li class="news"&gt;&lt;a href="#"&gt;Newsletter&lt;/a&gt;&lt;/li&gt;
      &lt;li class="contact"&gt;&lt;a href="#"&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
</code></pre>
<h4>CSS</h4>
<pre><code>.home a { border-color: #636393; } 
.tutorials a { border-color: #B5222D; } 
.news a { border-color: #D4953C; } 
.about a { border-color: #609491; } 
.contact a { border-color: #87A248; } </code></pre>
<p>But on a dynamic site where the menus can change, such as a WordPress site, that does not work. You need a way to make the first item to be purple, the 2nd item to be red, the third item to be teal, etc. </p>
<p>With CSS3, there is a simple way to do this. If you use the <em>pseudo-selector</em>  <a href="http://reference.sitepoint.com/css/pseudoclass-nthchild">nth-child</a>, you can specify each li item individually, then target the anchor tag inside. </p>
<p><code>	li:nth-child(1) a { border-color: #636393; }<br />
	li:nth-child(2) a { border-color: #B5222D; }<br />
	li:nth-child(3) a { border-color: #D4953C; }<br />
	li:nth-child(4) a { border-color: #609491; }<br />
	li:nth-child(5) a { border-color: #87A248; } 	</code></p>
<p>Basically, this is saying the anchor (a) tag inside of the first li in a list, should be #636393, and then the 2nd, 3rd, 4th and 5th are also specified. </p>
<p>This is simple and works in the latest version of all modern browsers, including IE9! Unfortunately it does not work in IE8 and below. Many times, I am willing to let that slide, because I don&#8217;t consider the CSS3 enhancement crucial to the design. In this case, however, the color of the menu items is very important to the design and I wanted a solution that would work everywhere. </p>
<p>This problem can be solved by using javascript, but I wanted to see if there was a CSS only solution to my problem. I discovered a clever trick while I was searching for the answer. I really would like to credit the person who inspired this solution, but I lost the link to the blog post, so I can&#8217;t do that unfortunately. </p>
<p><code>	li a { border-color: #636393; }<br />
	li+li a { border-color: #B5222D; }<br />
	li+li+li a { border-color: #D4953C; }<br />
	li+li+li+li a { border-color: #609491; }<br />
	li+li+li+li+li a{ border-color: #87A248; } </code></p>
<p>See all three solutions in the demo. (They all look the same, you need to view source to see the code differences.) </p>
<div class="demoButton"><a href="http://css-snippets.com/demos/menu-color.html">See Demo</a></div>
<h3>Explanation</h3>
<p>This solution is using the <a href="http://reference.sitepoint.com/css/adjacentsiblingselector">Adjacent Sibling Selector.</a> Supposedly this selector only works in IE8, but I found this solution to work just fine in IE7 also. It does not work in IE6.  </p>
<p>The first line of the CSS will style all of the borders to the first color (#636393). The second line of CSS will take every list item is adjacent to a list item (follows it) and make them all the 2nd color. It will skip the first one, because it is not adjacent to a previous list item. </p>
<p>The third line will take every list item that is adjacent to a previous list item, which is also adjacent to a previous list item. This will prevent the 1st and 2nd list items from getting targeted. </p>
<p>Etc. </p>
<p>The order of the CSS is very important. In reality, the 5th list item has it&#8217;s border-color set 5 different times. Because of the cascade, the last line is the one that sets the 5th color. </p>
<h3>Browser Support</h3>
<p>Solution 1 will work in all browsers, but doesn&#8217;t work with a dynamic site where you are not able to specifically create class names. </p>
<p>Solution 2 will work in the latest version of all modern browsers, but not in earlier versions of IE. </p>
<p>Solution 3 works in all browsers, including IE7 and IE8. The transitions, presented in the last post, do not work in IE. </p>
<p>The entire navigation I&#8217;ve presented here will work horribly in IE6, so if you want to make it work there, you will need a special IE6 style sheet. I may try to do a post on that later. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/different-colors-based-on-position-in-list/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Menu with Transition</title>
		<link>http://css-snippets.com/menu-with-transition/</link>
		<comments>http://css-snippets.com/menu-with-transition/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 17:30:00 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Navigation]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=325</guid>
		<description><![CDATA[In this post I am continuing the discussion of how I styled a navigation menu with transitions. The first post in the discussion is here: Vertical Navigation with a Border. The problem I want to discuss next is how the transition caused some moving of the text, and the menu to look just a bit [...]]]></description>
				<content:encoded><![CDATA[<p>In this post I am continuing the discussion of how I styled a navigation menu with transitions. The first post in the discussion is here: <a href="http://css-snippets.com/vertical-navigation-with-a-border">Vertical Navigation with a Border</a>. </p>
<p>The problem I want to discuss next is how the transition caused some moving of the text, and the menu to look just a bit jumpy. I also want to demonstrate the reason you will normally add the transition properties to your normal state and not the hover state. </p>
<pre><code>ul li { 
	list-style: none; 
	height: 44px; 
} 
ul li a { 
	width: 100px; 
	height: 40px; 
	line-height: 53px; 
	border-bottom: 4px solid #999;  
	padding-left: 5px; 
	color: #333; 
	text-decoration: none; 
 	display: block;
	-webkit-transition: .2s all linear;
	-moz-transition: .2s all linear;
	-o-transition: .2s all linear;
	transition: .2s all linear;			
} 
ul li a:hover { 
	border-bottom: 35px solid #999;
	height: 9px; 
}	</code></pre>
<div class="demoButton"><a href="http://css-snippets.com/demos/menu-transition.html">See Demo</a></div>
<h3>Explanation</h3>
<p>The transition is added with this part of the code:<br />
<code>	-webkit-transition: .2s all linear;<br />
	-moz-transition: .2s all linear;<br />
	-o-transition: .2s all linear;<br />
	transition: .2s all linear;	</code></p>
<p>The sliding up and down of the border will take place over .2 seconds. The transition will occur on all properties that change (at least all properties that take a transition.) The easing is &#8220;linear&#8221;. Any of these values can be adjusted to personal design. </p>
<p>If you look at the first two menus in the demo, both have a slight shift vertically when you hover over a menu item. It appears that the transition of the border-size is not happening at exactly the same rate as the transition of the height. So the box size of the anchor tag (height + border, in this case) is not a static number. </p>
<p>This problem is easily solved by giving a height to the parent of the anchor tags, which in this case is the &#8220;li&#8221; tag. By setting the height to 44px, the problem is solved. </p>
<p>You will also notice on the demo page, on the first menu, what happens when you put your transitions on the hover state &#8211; the transition only occurs in one direction. </p>
<h3>Browser Support</h3>
<p>The transition will work in all of the latest versions of modern browsers, except Internet Explorer. I consider this &#8220;icing&#8221; and not necessary to the design, so I am okay with that difference. However, if you really wanted it to work in every browser, you could use javascript to make this work. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/menu-with-transition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vertical Navigation with a Border</title>
		<link>http://css-snippets.com/vertical-navigation-with-a-border/</link>
		<comments>http://css-snippets.com/vertical-navigation-with-a-border/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 18:59:03 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=315</guid>
		<description><![CDATA[I have been working a website with vertical navigation with some transitions and different colors on each item. The menu brought up some interesting CSS issues. I am breaking it down into smaller chunks and tackling each issue in separate posts. I&#8217;m starting with the simplest issue and that is setting up the navigation with [...]]]></description>
				<content:encoded><![CDATA[<p>I have been working a website with vertical navigation with some transitions and different colors on each item. The menu brought up some interesting CSS issues. I am breaking it down into smaller chunks and tackling each issue in separate posts. </p>
<p>I&#8217;m starting with the simplest issue and that is setting up the navigation with a small border on the bottom. The goal is to have the border grow behind the text when the user hovers. </p>
<div id="attachment_321" class="wp-caption alignnone" style="width: 346px"><img src="http://css-snippets.com/blogfile/wp-content/uploads/2011/10/menu.png" alt="" title="Menus " width="336" height="280" class="size-full wp-image-321" /><p class="wp-caption-text">Menu on the right showing the hover state. The border on the bottom grows to show which item user is hovering over.<br />
 </p></div>
<pre><code>ul li { 
	list-style: none; 
} 
ul li a { 
	width: 100px; 
	height: 40px; 
	line-height: 53px; 
	border-bottom: 4px solid #999;  
	padding-left: 5px; 
	color: #333; 
	text-decoration: none; 
 	display: block;
} 
ul li a:hover { 
	border-bottom: 35px solid #999;
	height: 9px; 
}	</code></pre>
<div class="demoButton"><a href="http://css-snippets.com/demos/menu-border.html">See Demo</a></div>
<h3>Explanation</h3>
<p>The code is similar to Horizontal Navigation, except you don&#8217;t need to float the individual list items, so it is even more simple. </p>
<p>The important part of the code is:<br />
<code>	height: 40px;<br />
	line-height: 53px;<br />
	border-bottom: 4px solid #999;<br />
	padding-left: 5px;<br />
 	display: block;</code></p>
<p><strong>display: block</strong> changes the anchor tag to a block level element allowing you to give it a height. (Normally anchor tags are inline elements with no height.) The full height of the element is 44px. 40px from the height, and 4px from the border. </p>
<p>If I wanted the text centered in it&#8217;s box, I could have used a line-height of 40px, which is a standard technique for centering text vertically. However, I wanted the text close to the border. So I set the <strong>line-height</strong> to 53px and that centers the text on a 53px box, which ultimately places it closer to the border as I wanted. It isn&#8217;t the only solution, I could have messed around with marigns/padding, but this seemed the quickest. </p>
<p>The real issue is the hover state. </p>
<pre><code>ul li a:hover { 
	border-bottom: 35px solid #999;
	height: 9px; 
}</code></pre>
<p>I wanted the border to be a full 35px when hovering, so it comes up behind the text. If I didn&#8217;t change the height to be smaller, it causes a problem, similar to what I discussed in <a href="http://css-snippets.com/adding-a-border-to-an-image-on-hover/">this post</a>. However, in this case, the outline solution won&#8217;t work because I only have a border on the bottom, and outline goes on all 4 sides. <a href="http://css-snippets.com/demos/menu-border.html">See the demo, first column,</a> for a display of the problem. </p>
<p>Changing the height of the box in the hover state fixes the problem. If I want to grow the border to be 35px, I need to make the height 9px, to make sure the total height remains at 44px. 9px + 35px = 44px. In the regular state: 4px + 40px = 44px. The individual numbers are not important. The important part is the TOTAL box height which = height + border + margin + padding. In my case I have no margin or padding. </p>
<p>In my next post, I will show how adding a transition to the border changing caused a problem and how I fixed it. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/vertical-navigation-with-a-border/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transitions</title>
		<link>http://css-snippets.com/transitions/</link>
		<comments>http://css-snippets.com/transitions/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 15:38:40 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS3]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=305</guid>
		<description><![CDATA[There are two transitions happening on this site (at the moment anyway). One is in the header. When you hover over the text &#8220;CSS Snippets&#8221;, it rotates up. The rotation is actually done with the &#8220;transform&#8221; property, not &#8220;transition&#8221;. The transition part is that you can see it rotate up from the starting position to [...]]]></description>
				<content:encoded><![CDATA[<p>There are two <a href="http://www.w3.org/TR/css3-transitions/">transitions</a> happening on this site (at the moment anyway). One is in the header. When you hover over the text &#8220;CSS Snippets&#8221;, it rotates up. The rotation is actually done with the &#8220;transform&#8221; property, not &#8220;transition&#8221;. The transition part is that you can see it rotate up from the starting position to the ending position, instead of just jumping. </p>
<p>The other transition is when you hover over an item in the main menu. The color fades to the hover state, it doesn&#8217;t just change colors automatically.</p>
<p>Like many things in CSS you can specify the different parts of the transition individually, or with shorthand. I will be using shorthand unless I have a reason to not use it. </p>
<pre><code>-webkit-transition: .2s all linear;
-moz-transition: .2s all linear;
-o-transition: .2s all linear;
transition: .2s all linear;		</code></pre>
<h3>Explanation</h3>
<p>This is a very simple starting point for transitions. Add this snippet of code to your regular state (for example add it to the css for #navigation li a), not the hover state. If you declare your transition on the regular state, it will perform the transition in both directions, and you won&#8217;t have to account for other states like focus or active. When this code is added to the regular state of something on your page, when the hover state is activated (or your return to regular state), the changes in properties will be transitioned over .2 seconds. </p>
<p>The first value is the duration or the transition. The second value is what do you want to transition. &#8220;All&#8221; will make sure any property that is changed between regular state and hover state gets transitioned.  You don&#8217;t need to transition all of them, however. Many different properties can use a transition, <a href="http://www.w3.org/TR/css3-transitions/#animatable-properties-">see this for a list of properties</a>. </p>
<p>The last value is the timing function. For simple transitions, I find &#8220;linear&#8221; to be fine, however, there are <a href="http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag">other choices</a> that may work better in some situations. </p>
<p>You can also add a delay, but it can feel weird to the user delay the transition, on simple hovers. There are interesting things you can do with it, however. </p>
<p>The <a href="http://www.w3.org/TR/css3-transitions">W3C documentation</a> can explain this property in more detail. I will have more specific examples of transitions in the future. </p>
<h3>Browser Support</h3>
<p>All the latest versions of the major browsers, except of course Internet Explorer, support this property. I have heard it will be supported in IE10. You do need to use the browser prefixes to make it work. If the transition must work in IE, you will have to use Javascript. Usually transitions are nice enhancements, but not necessary, so I don&#8217;t mind just using CSS. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/transitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a Border to an Image on Hover</title>
		<link>http://css-snippets.com/adding-a-border-to-an-image-on-hover/</link>
		<comments>http://css-snippets.com/adding-a-border-to-an-image-on-hover/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 20:21:27 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[hover]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=292</guid>
		<description><![CDATA[This next issue I want to cover is fairly simple, but I ran into a situation last week where I needed to find a solution to this problem, and I wasn&#8217;t sure of the best answer. I wanted to add a border on the hover state of an image. The problem is that when you [...]]]></description>
				<content:encoded><![CDATA[<p>This next issue I want to cover is fairly simple, but I ran into a situation last week where I needed to find a solution to this problem, and I wasn&#8217;t sure of the best answer. I wanted to add a border on the hover state of an image. The problem is that when you add a border it adds to the width. The size of the box according to the box model is made up of width+padding+border+margin. So if you only have the border when hovering, the width of the object changes. When you have images in a grid, the problem is very obvious and actually almost nauseating to look at! </p>
<p>To see the problem, it will be clearest if you go to Demo page to see it in action. </p>
<div class="demoButton"><a href="http://css-snippets.com/demos/hover-border.html">See Demo</a></div>
<p>A simple solution is to add a border on your image, div, etc. (wherever it is you want the border) that is the same color of your background. Obviously, this will only work if you have a solid color background. In my demo, I do, so I will add a white border initially, and change it to black on hover. That way the size never changes, but things look different on hover. </p>
<pre><code>img { 
  border: 3px solid white; 
} 
img:hover { 
  border: 3px solid black; 
} 
</code></pre>
<p>To solve the problem mentioned above, you can instead use <a href="http://reference.sitepoint.com/css/outline" title="Outline Reference" target="_blank">outline</a> property. This will work when you have an image or gradient in your background. It will also work when your initial image has a border, but you want to make it larger on hover. The outline property uses the same syntax as the border shorthand. </p>
<pre><code>/* Solve problem on a non-solid background */
img:hover { 
  outline: 3px solid black; 
} 

/* Solve problem where border size changes on hover */
img { 
  border: 1px solid black; 
} 
img:hover { 
  outline: 2px solid black; 
} 
</code></pre>
<div class="demoButton"><a href="http://css-snippets.com/demos/hover-border.html #ex3">See Demo</a></div>
<h3>Explanation</h3>
<p>The reason this works is that outlines do not add width to your objects. They are not really in the flow of your document, so things don&#8217;t change when you hover over something. Outlines are uniform on each side. You cannot set top, right, bottom, left to be different, as you can with borders. </p>
<p>Notice in the second solution, where the border-size is changing, I made the outline 2px. This is so the final size of border is 3px (1+2). </p>
<h3>Browser Support</h3>
<p>When I first came upon this solution, I read that it did not work in IE. However, I tested in IE8 and it worked fine. It does not work in IE7. So, if hovering in IE7, the border will remain the same. It depends on the importance of the that visual effect to your design if you want to find another solution to work in IE7 or not. Another solution would be to have a 2nd image for the hover state, but that comes at a price because you are downloading more images. In most cases, I&#8217;m fine with leaving IE7 hover-borderless, but it would depend on the site and audience of course. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/adding-a-border-to-an-image-on-hover/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Text Selection Color</title>
		<link>http://css-snippets.com/text-selection-color/</link>
		<comments>http://css-snippets.com/text-selection-color/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 17:29:09 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS3]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=276</guid>
		<description><![CDATA[I have so many topics I want to cover, but very little time right now. So here is a short one on how to change the color of your selection text (when you drag your cursor over text to copy, as you would on this website!) Normally this color is a blue, but it can [...]]]></description>
				<content:encoded><![CDATA[<p>I have so many topics I want to cover, but very little time right now. So here is a short one on how to change the color of your selection text (when you drag your cursor over text to copy, as you would on this website!)  Normally this color is a blue, but it can be changed to match your design if you want. This is not a super important detail to any web design, but it adds a nice touch. </p>
<pre><code>::-moz-selection {
   background-color: #317572;
   color: #fff;
}
::selection {
    background-color: #317572;
    color: #fff;
}</code></pre>
<h3>Explanation</h3>
<p>The <strong>background-color</strong> property will change your selection color, if you use <strong>::-moz-selection</strong> for firefox, or <strong>::selection</strong> for other browsers. It is important to also change the <strong>color </strong>property if your chosen background color won&#8217;t contrast enough. I made the color white, to contrast with my dark background color. </p>
<p>The idea for this came from the <a href="http://html5boilerplate.com/">HTML5 Boilerplate</a> website by Paul Irish, who chose to use a hot pink color for selecting. So if you see a website with hot pink when you drag your mouse across text, it was likely started from that boilerplate. </p>
<h3>Browser Support</h3>
<p>This works in all the latest versions of every browser. Even in IE9 (yeah!) It does not work in IE8 or earlier, but since this is just a nice extra design detail, and not crucial to making a website work, it is fine to add to any site. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/text-selection-color/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drop-Down Navigation with CSS only</title>
		<link>http://css-snippets.com/drop-down-navigation/</link>
		<comments>http://css-snippets.com/drop-down-navigation/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 22:23:38 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://css-snippets.com/?p=194</guid>
		<description><![CDATA[Many drop-down navigation solutions out there rely on javascript, but it is possible to set this up with CSS only, and this is the method I prefer. This works in all browsers, with a minor change in the way things look in IE7 and below. HTML &#60;body id="about"&#62; &#60;div id="header"&#62; &#60;ul id="nav"&#62; &#60;li class="home"&#62;&#60;a href="#"&#62;Home&#60;/a&#62;&#60;/li&#62; [...]]]></description>
				<content:encoded><![CDATA[<p>Many drop-down navigation solutions out there rely on javascript, but it is possible to set this up with CSS only, and this is the method I prefer. This works in all browsers, with a minor change in the way things look in IE7 and below. </p>
<h3>HTML</h3>
<pre><code>&lt;body id="about"&gt;
  &lt;div id="header"&gt;
    &lt;ul id="nav"&gt;
      &lt;li class="home"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
      &lt;li class="tutorials"&gt;&lt;a href="#"&gt;Tutorials&lt;/a&gt;
<strong>        &lt;ul&gt;
          &lt;li&gt;&lt;a href="#"&gt;Sub Menu 1&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Sub Menu 2&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Sub Menu 3&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;</strong>
      &lt;/li&gt;
      &lt;li class="about"&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt;
      &lt;li class="news"&gt;&lt;a href="#"&gt;Newsletter&lt;/a&gt;
<strong>        &lt;ul&gt;
          &lt;li&gt;&lt;a href="#"&gt;Issue 1&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Issue 2&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Issue 3&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;</strong>
      &lt;/li&gt;
      &lt;li class="contact"&gt;&lt;a href="#"&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;&lt;!-- nav --&gt; 
  &lt;/div&gt;&lt;!-- header --&gt;     
&lt;/body&gt;</code></pre>
<h3>CSS</h3>
<pre><code>#header { 
	min-width: 800px; 
	height: 150px; 
} 
#nav {  
	width: 100%; 
	background-color: #333; 
	font-family:"Century Gothic", "HelveticaNeueLT Pro 45 Lt", sans-serif; 
	float: left; 
}
#nav li { 
	list-style: none; 
	float: left; 
	width: 120px; 
	height: 30px; 
	line-height: 30px; 
	text-align: center;
} 
#nav li a { 
	color: white; 
	text-decoration: none; 
	display: block; 
} 
#nav li a:hover { 
	background-color: #066; 
} 
#home .home a, #home .home a:hover,
#tutorials .tutorials a, #tutorials .tutorials a:hover,
#about .about a, #about .about a:hover,
#contact .contact a, #contact .contact a:hover,
#news .news a, #news .news a:hover {
 	background-color: #FFF; 
	color: #000;
	cursor: default;  
} 		
<strong>#nav li ul { 
	position: absolute;  
	display: none; 
} 
#nav li:hover ul { 
	display: block; 
} 
#nav li ul li { 
	float: none; 
	display: inline; 
}
#nav li ul li a { 
	width: 118px; 
	position: relative; 
	border-left: 1px solid black; 
	border-right: 1px solid black; 
	border-bottom: 1px solid black; 
	background: #333; 
	color: #fff; 
}
#nav li ul li a:hover { 
	background: #066; 
	color: #000; 
}</strong></code></pre>
<div class="demoButton"><a href="http://css-snippets.com/demos/drop-down-menu.html">See Demo</a></div>
<h3>Explanation</h3>
<p>The HTML/CSS code is built upon the <a href="http://css-snippets.com/simple-horizontal-navigation/" title="Simple Horizontal Navigation">Simple Horizontal Menu Navigation</a> post. See that post for details on the basics of the navigation. This explanation will only focus on the drop-down portion of the code. The new code is in <strong>bold </strong>above. </p>
<h4>HTML</h4>
<pre><code>      &lt;li class="tutorials"&gt;&lt;a href="#"&gt;Tutorials&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href="#"&gt;Sub Menu 1&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Sub Menu 2&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Sub Menu 3&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;</code></pre>
<p>To set up the Drop Down portions of navigation in the menus, nest a second UL tag inside of the menu item&#8217;s LI tag. The code above shows this done for the Tutorials section. Nested unordered lists can be added for all the menu items if appropriate. </p>
<h4>CSS</h4>
<pre><code>#nav li ul {
	position: absolute;
	display: none;
}</code></pre>
<p>This hides the display of the nested navigation, so it will only show when the user hovers over the parent link. The absolute positioning allows us to determine where the drop-down menu is displayed. </p>
<pre><code>#nav li:hover ul {
	display: block;
}</code></pre>
<p>When the user hovers over the parent LI tag, the nested menu will now display. </p>
<p>The rest of the CSS is mostly for styling the menus. </p>
<h3>Browser Support</h3>
<p>This will work in all browsers, even Internet Explorer 6. In IE6 and IE7, however, the drop-down menus are shifted over to the right a bit. If you want the menus to look exactly the same, you will need to add some additional styling for IE7 and lower with a browser specific style sheet. </p>
]]></content:encoded>
			<wfw:commentRss>http://css-snippets.com/drop-down-navigation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
