<?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 Basics Archives - Impressive Webs</title>
	<atom:link href="https://www.impressivewebs.com/css-basics/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.impressivewebs.com/css-basics/</link>
	<description>Articles on Front-end Web Development</description>
	<lastBuildDate>Tue, 28 Jan 2025 19:04:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>
	<item>
		<title>CSS Positioning Basics (Screencast)</title>
		<link>https://www.impressivewebs.com/css-positioning-basics-screencast/</link>
					<comments>https://www.impressivewebs.com/css-positioning-basics-screencast/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Thu, 23 Apr 2015 12:57:26 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Basics]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Web Design Tutorials]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=14650</guid>

					<description><![CDATA[<p><img src="https://s3.amazonaws.com/impressivewebs/2015-04/css-positioning-screencast.png" alt="CSS Positioning" width="184" height="184" class="article_image">A couple of years ago I wrote an article for a company called Thinkful on CSS positioning, which also included a screencast that I hosted on my ImpressiveWebs YouTube channel. The video was "unlisted" but I've now made it public, and since some time has passed I thought I would post the video here.</p>
<p>It's pretty basic stuff for most experienced CSS developers, but if anyone wants a quick primer on CSS positioning, this should be a good guide. The video is embedded below and I've summarized the content here in this post.</p>
<p>The post <a href="https://www.impressivewebs.com/css-positioning-basics-screencast/">CSS Positioning Basics (Screencast)</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A couple of years ago I wrote <a href="https://www.thinkful.com/learn/css-positioning-tutorial" rel="nofollow">an article for a company called Thinkful</a> on CSS positioning, which also included a screencast that I hosted on my <a href="https://www.youtube.com/user/ImpressiveWebs">ImpressiveWebs YouTube channel</a>. The video was &#8220;unlisted&#8221; but I&#8217;ve now made it public, and since some time has passed I thought I would post the video here.</p>
<p>It&#8217;s pretty basic stuff for most experienced CSS developers, but if anyone wants a quick primer on CSS positioning, this should be a good guide. The video is embedded below and I&#8217;ve summarized the content here in this post.</p>
<p><iframe width="1280" height="720" src="https://www.youtube.com/embed/6o-J6We3hkQ?rel=0&#038;vq=hd720" frameborder="0" allowfullscreen></iframe></p>
<p>Some main points from the screencast:</p>
<ul class="body_list">
<li>The <code>position</code> property in CSS takes 4 common values supported in all browsers. There are <a href="http://cssvalues.com/#position%20">other values</a>, but this video only deals with the well supported ones.</li>
<li>In order to position something with the <code>top</code>, <code>right</code>, <code>bottom</code>, and <code>left</code> values, you need to set the element to either &#8220;position: absolute&#8221; or &#8220;position: relative&#8221;.</li>
<li>If a child is absolutely positioned, it will be positioned relative to the viewport or the closest relatively positioned parent.</li>
<li>You can make an element automatically expand to fit its relative parent by using &#8220;0&#8221; values for all the offsets.</li>
<li>Static elements will ignore an absolutely positioned element, behaving <a href="http://www.impressivewebs.com/css-things-that-dont-occupy-space/">as if it&#8217;s not there</a>. Because of this, absolute positioning is not recommended for large layout features or other areas of your site that are dependent on the natural flow of elements.</li>
<li><a href="http://codepen.io/impressivewebs/pen/qvwdo">CodePen demo</a> used in the screencast.</li>
</ul>
<p>The post <a href="https://www.impressivewebs.com/css-positioning-basics-screencast/">CSS Positioning Basics (Screencast)</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/css-positioning-basics-screencast/feed/</wfw:commentRss>
			<slash:comments>19</slash:comments>
		
		
			</item>
		<item>
		<title>Clearing Floats: Why is it Necessary Even in &#8220;Modern&#8221; Browsers?</title>
		<link>https://www.impressivewebs.com/clearing-floats-why-necessary/</link>
					<comments>https://www.impressivewebs.com/clearing-floats-why-necessary/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Tue, 23 Oct 2012 10:00:24 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Basics]]></category>
		<category><![CDATA[Web Design Tutorials]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=8397</guid>

					<description><![CDATA[<p><img src="https://s3.amazonaws.com/impressivewebs/2012-10/root-beer-float.jpg" alt="Clearing Floats: Why is it Necessary Even in "Modern" Browsers?" title="Clearing Floats: Why is it Necessary Even in "Modern" Browsers?" width="184" height="184" class="article_image">The other day, someone asked me the following question: <i>"If I understand it right clear float is automatic in most modern browsers right?"</i></p>
<p>If you're new to CSS, then it would seem that the answer to this question should be "yes, of course -- modern browsers don't have these types of bugs!" But the necessity to clear floats is not a browser bug; it's actually, well, more of a CSS feature. And it's still needed in so-called "modern" browsers (assuming you're using floats for layout).</p>
<p>The post <a href="https://www.impressivewebs.com/clearing-floats-why-necessary/">Clearing Floats: Why is it Necessary Even in &#8220;Modern&#8221; Browsers?</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The other day, someone asked me the following question:</p>
<blockquote><p>If I understand it right clear float is automatic in most modern browsers right?</p></blockquote>
<p>If you&#8217;re new to CSS, then it would seem that the answer to this question should be &#8220;yes, of course &#8212; modern browsers don&#8217;t have these types of bugs!&#8221; But the necessity to clear floats is not a browser bug; it&#8217;s actually, well, more of a CSS feature. And it&#8217;s still needed in so-called &#8220;modern&#8221; browsers (assuming you&#8217;re using floats for layout).</p>
<p>This doesn&#8217;t mean, though, that clearing floats will always be necessary. The eventual goal of CSS layouts is to never need to use floats for layout. Instead, we want to be able to use <a href="http://www.netmagazine.com/features/future-css-layouts">a better method</a>.</p>
<p>But clearing floats are a fact of developer lives today, and so I thought I&#8217;d explain why clearing them is still necessary, even in &#8220;modern&#8221; browsers.</p>
<h2>What Does a Float Do?</h2>
<p>Here is, in part, how <a href="http://dev.w3.org/csswg/css3-box/#introduction-to-floats">the W3C spec explains</a> what floats do:</p>
<blockquote><p>Content flows down the right side of a left-floated box and down the left side of a right-floated box … Since a float is not in the flow, non-positioned block boxes created before and after the float box flow vertically as if the float didn&#8217;t exist.</p></blockquote>
<p>You can see this behaviour demonstrated in the JS Bin below:</p>
<p><a href="http://jsbin.com/azuwul/1/edit">http://jsbin.com/azuwul/1/edit</a></p>
<p>Notice that the green box is acting as if the red box is not even there, rather than &#8220;flowing&#8221; around it like the text does. This is what floats do: They cause other floated elements and inline content to flow around the float, but other block boxes ignore the float.</p>
<p>The only problem I have with the W3C definition is that it sounds like it&#8217;s talking about absolutely positioned elements. So it seems that floats should have a different wording ascribed to them. I prefer to say that floats are taken out of the normal flow <em>in relation to sibling block elements</em>.</p>
<p>Regardless of the explanation, you should be able to see that no matter how far browsers advance, they will never clear floats automatically (as the original question seemed to assume) &#8212; because the behaviour of floats is not a bug; it&#8217;s a feature.</p>
<div class="update-box">As Scott points out in the comments, it looks like there will indeed be an easy way to clear floats, using the <a href="http://dev.w3.org/csswg/css-sizing/#the-contain-floats-value">contain-floats</a> value for the <code>min-height</code> property. Interesting stuff. I believe this specification is only a month or two old, so I don&#8217;t expect browsers to have support for this any time soon. But good to know.</div>
<h2>Float Clearing Methods</h2>
<p>To round this post out, let&#8217;s cover the most popular methods for clearing floats.</p>
<p><strong>clear: both/left/right</strong><br />
The primary way to prevent an element from flowing alongside a floated sibling is to use the <a href="http://cssvalues.com/#clear%20">clear property</a>. Any value other than &#8220;none&#8221; will clear the element that you want to follow the float (rather than bump up against it).</p>
<p><strong>overflow: hidden/auto</strong><br />
The main problem with floats is what you might refer to as the collapsing container, which causes background elements to disappear. In this case, you don&#8217;t have a trailing element that you can &#8220;clear&#8221; to fix this. But instead, you want the parent element to fully contain all the floated children. In this case, at the very least you&#8217;ll need to use the <a href="http://cssvalues.com/#overflow%20">overflow property</a>. Using a value of &#8220;hidden&#8221; or &#8220;auto&#8221;, the parent will expand to contain all floated children. Although this is probably the easiest way to clear floats, it&#8217;s really not recommended, because of the problem of scrollbars appearing or child elements being cut off due to positioning, margins, or CSS3 transforms.</p>
<p>I think the only time I would consider using this one is for a small widget-like box in the page that has floated children (like a tab switcher or something like that), where I know that positioned elements and margins are not going to be a problem.</p>
<p><strong>clearfix</strong><br />
The best method to use to clear floats is the clearfix method. I can&#8217;t remember who originally came up with this, but the most updated and optimized syntax that works in all browsers is <a href="http://nicolasgallagher.com/micro-clearfix-hack/">the one proposed by Nicolas Gallagher</a> and used in HTML5 Boilerplate. Here&#8217;s the code:</p>
<pre name="code" class="css">
.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}
.clearfix:after {
    clear: both;
}
/* For IE 6/7 only */
.clearfix {
    *zoom: 1;
}
</pre>
<p>With that in your CSS, all you have to do is add a class of &#8220;clearfix&#8221; to any element that is &#8220;collapsed&#8221; due to floated child elements. Again, you could use the overflow method instead, but it&#8217;s not universally ideal. I&#8217;ve found it causes too many problems in complex layouts.</p>
<h2>To Sum Up</h2>
<p>Yes, float clearing is still necessary in modern browsers, and the best method is the clearfix method. But eventually, we want all in-use browsers to support an alternative, more intuitive method for doing CSS layouts, so we don&#8217;t have to worry about hacks and workarounds to fix these types of problems.</p>
<p class="metacredit">Post excerpt photo credit: <a href="http://www.bigstockphoto.com/image-25921427/stock-photo-root-beer-float-isolated-on-white">Root beer float</a> from Bigstock</p>
<p>The post <a href="https://www.impressivewebs.com/clearing-floats-why-necessary/">Clearing Floats: Why is it Necessary Even in &#8220;Modern&#8221; Browsers?</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/clearing-floats-why-necessary/feed/</wfw:commentRss>
			<slash:comments>26</slash:comments>
		
		
			</item>
		<item>
		<title>Web Development for Beginners (Resources)</title>
		<link>https://www.impressivewebs.com/web-development-for-beginners/</link>
					<comments>https://www.impressivewebs.com/web-development-for-beginners/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Tue, 18 Sep 2012 10:00:52 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<category><![CDATA[Roundups and Resources]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=7996</guid>

					<description><![CDATA[<p><img src="https://s3.amazonaws.com/impressivewebs/2012-09/web-development-beginners.jpg" alt="Web Development for Beginners (Resources)" title="Web Development for Beginners (Resources)" width="184" height="184" class="article_image">While I usually try to write stuff that's geared more to experienced developers, I don't want to neglect those who are just starting out.</p>
<p>I've been collecting links to <strong>beginners resources for web development</strong> for some time now, so I thought I'd share that list here. Feel free to add your own in the comments.</p>
<p>The post <a href="https://www.impressivewebs.com/web-development-for-beginners/">Web Development for Beginners (Resources)</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-09/web-development-beginners.jpg" alt="Web Development for Beginners (Resources)" title="Web Development for Beginners (Resources)" width="184" height="184" class="article_image">While I usually try to write stuff that&#8217;s geared more to experienced developers, I don&#8217;t want to neglect those who are just starting out.</p>
<p>I&#8217;ve been collecting links to <strong>beginners resources for web development</strong> for some time now, so I thought I&#8217;d share that list here. Feel free to add your own in the comments.</p>
<hr>
<p><a href="http://learn.shayhowe.com/html-css/">A Beginner&#8217;s Guide to HTML &amp; CSS</a> (website)<br />
A simple and comprehensive guide dedicated to helping beginners learn HTML and CSS. Outlining the fundamentals, this guide works through all common elements of front-end design and development.&#8221; This guide, led by front-end developer Shay Howe, looks quite comprehensive, covering everything from tag semantics to new CSS3 features like gradients.</p>
<hr>
<p><a href="http://www.htmlandcssbook.com/">HTML &amp; CSS: Design and Build Websites</a> (book)<br />
A beautifully designed book by Jon Duckett that has been the #1 selling web design book on Amazon for a number of months now. The website describes the book as &#8220;a book about code that doesn&#8217;t read like a 1980s VCR manual. It&#8217;s not just for programmers, it&#8217;s written and presented to make it easy for designers, bloggers, content and e-commerce managers, marketers to learn about the code used to write web pages.&#8221;</p>
<hr>
<p><a href="http://tutsplus.com/course/30-days-to-learn-html-and-css/">30 Days to Learn HTML and CSS</a> (screencast series)<br />
A video screencast series by Jeffrey Way of the Tuts+ Network that teaches viewers HTML and CSS from the ground up. All the lessons are in the Tuts+ Premium section, but unlike other courses on Tuts+ Premium, this one doesn&#8217;t require that you be a Premium member.</p>
<hr>
<p><a href="http://www.sitepoint.com/books/cssant4/">The CSS3 Anthology</a> (book)<br />
This book, by Rachel Andrews, is a great question-and-answer type book that can complement linear tutorial-style learning. It&#8217;s not the type of book you&#8217;ll read cover to cover (although you would definitely benefit from that), but instead works well as a problem-solving reference that you can go back to time again. Excellent for beginners and includes lots of new CSS3 techniques along with an introduction to responsive web design.</p>
<hr>
<p><a href="http://www.codeavengers.com/">Code Avengers</a> (interactive learning)<br />
A free interactive online tutorial that will teach you Javascript, HTML, and CSS, &#8220;the fun and effective way.&#8221; There are currently three courses to choose from: HTML/CSS, JavaScript level 1, and JavaScript level 2. The site aims to use beginner-friendly terminology and tries to make the lessons resemble real-world problem solving.</p>
<hr>
<p><a href="http://tutsplus.com/course/30-days-to-learn-jquery/">30 Days to Learn jQuery</a> (screencast series)<br />
Another free screencast series from the Tuts+ Network, this time covering how to use the jQuery JavaScript library. Definitely looks like a great option for those who want to learn jQuery from scratch.</p>
<hr>
<p><a href="http://www.dontfeartheinternet.com/">Don&#8217;t Fear The Internet</a> (screencast series)<br />
Video lessons created by Jessica Hische and Russ Maschmeyer. The site offers short tutorial videos that cover topics starting from an introduction to the internet as well as web browsers, HTML and CSS.</p>
<hr>
<p><a href="http://www.codecademy.com/">Codecademy</a> (interactive learning)<br />
A very popular interactive online learning website created by Zach Sims and Ryan Bubinski. It features beginner-level learning covering JavaScript, HTML, CSS, and jQuery, putting you &#8220;on the path to building great websites, games, and apps.&#8221;</p>
<hr>
<p><a href="https://teamtreehouse.com/">Treehouse</a> (screencast series / quizzes)<br />
An affordable option for high-quality learning of HTML, CSS, responsive design, and even iOS development for building iPhone and iPad apps. Using Treehouse, users watch videos, take quizzes, and unlock badges.</p>
<hr>
<p><a href="http://www.codeschool.com/courses/jquery-air-first-flight">jQuery Air: First Flight</a> (screencast series)<br />
A free course that&#8217;s one of the many programming courses available on Code School. This one covers JavaScript and jQuery fundamentals.</p>
<hr>
<p><a href="http://scrunchup.com/">Scrunchup</a> (website)<br />
&#8220;The aim of this site is to give decent advice to students who want a career in web design or development. Sure, there are lots of websites out there that give advice on writing really good code, but not many of them are aimed specifically at young people who are just starting out.&#8221;</p>
<hr>
<p><a href="http://www.w3.org/community/webed/wiki/Main_Page">W3C&#8217;s Web Education Community Group Wiki</a> (website)<br />
A wiki with articles and resources for teaching and learning web development. Includes a Web Standards Curriculum.</p>
<hr>
<p><a href="http://code.google.com/edu/submissions/html-css-javascript/">Google: HTML, CSS, and Javascript from the Ground Up</a> (screencast series)<br />
A Google Code resource comprising a series of videos totalling nearly 2 hours of playing time covering the basics of the big three in front-end development.</p>
<hr>
<p><a href="http://channel9.msdn.com/Series/HTML5-CSS3-Fundamentals-Development-for-Absolute-Beginners">HTML5 &amp; CSS3 Fundamentals: Development for Absolute Beginners</a> (screencast series)<br />
MSDN presents 21 episodes with Bob Tabor teaching the fundamentals of HTML5 &amp; CSS3 programming. Includes concepts about web pages, CSS3 styles and HTML5 features.</p>
<hr>
<p><a href="http://jqfundamentals.com/">jQuery Fundamentals</a> (website)<br />
Described as &#8220;a guide to the basics of jQuery&#8221;, this is a very good resource for jQuery and JavaScript beginners. As the intro page explains, it&#8217;s &#8220;designed to get you comfortable working through common problems you&#8217;ll be called upon to solve using jQuery&#8230; Each chapter will cover a concept and give you a chance to try example code related to the concept.&#8221;</p>
<hr>
<p><a href="http://jsforcats.com/">JavaScript For Cats</a> (website)<br />
This one-page resource, billed as &#8220;an introduction for new programmers&#8221; covers the basics of JavaScript starting with strings, variables, and functions.</p>
<hr>
<p><a href="http://channel9.msdn.com/Series/Javascript-Fundamentals-Development-for-Absolute-Beginners">Javascript Fundamentals: Development for Absolute Beginners</a> (screencast series)<br />
Another MSDN video series by Bob Tabor, this time covering JavaScript from the ground up. Includes 21 videos.</p>
<hr>
<p><a href="https://developer.mozilla.org/en-US/learn">MDN&#8217;s Learn How to Make Websites</a> (links to external sources)<br />
Mozilla Developer Network&#8217;s resource for learning HTML, CSS, and JavaScript from the ground up. These aren&#8217;t original articles, however. They&#8217;re basically just collections of links to articles on other sites (A List Apart, SitePoint, dev.opera, etc).</p>
<hr>
<p><a href="http://css-tricks.com/category/beginner/">Beginner Articles on CSS-Tricks</a> (blog articles)<br />
A collection of beginners articles by Chris Coyier.</p>
<hr>
<p><a href="http://www.impressivewebs.com/css-basics/">CSS Basics on Impressive Webs</a> (blog articles)<br />
The CSS Basics section on this site, which I&#8217;ve neglected lately, but has some good basic stuff for beginners or those who have been out of the CSS loop for some time.</p>
<hr>
<p><a href="http://learnlayout.com/">Learn CSS Layout</a> (info app)<br />
A simple info-app site that teaches CSS layout stuff from the ground up.</p>
<h2>Got More?</h2>
<p>If you know of any others, I&#8217;ll continue to update this list.</p>
<p>The post <a href="https://www.impressivewebs.com/web-development-for-beginners/">Web Development for Beginners (Resources)</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/web-development-for-beginners/feed/</wfw:commentRss>
			<slash:comments>44</slash:comments>
		
		
			</item>
		<item>
		<title>Setting Up Sass on Windows</title>
		<link>https://www.impressivewebs.com/sass-on-windows/</link>
					<comments>https://www.impressivewebs.com/sass-on-windows/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Mon, 13 Aug 2012 10:20:17 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<category><![CDATA[Web Design Tutorials]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=7703</guid>

					<description><![CDATA[<p><img src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-windows.jpg" alt="Setting Up Sass on Windows" title="Setting Up Sass on Windows" width="184" height="184" class="article_image">There's a ton of information floating around on preprocessors nowadays. Most of that info is geared towards Mac users, so in this post I'm providing a very simple guide to help Windows-based developers get up and running quickly with <cite>Sass</cite> (my preprocessor of choice).</p>
<p>Overall, Sass is not difficult at all to get set up, even if you're doing it on the command-line. But if you have no interest in going through all these steps, but still want to use Sass on Windows, well, just skip to the final heading in this post for a reference to an app that lets you start using Sass on Windows with minimal setup.</p>
<p>The post <a href="https://www.impressivewebs.com/sass-on-windows/">Setting Up Sass on Windows</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-windows.jpg" alt="Setting Up Sass on Windows" title="Setting Up Sass on Windows" width="184" height="184" class="article_image">There&#8217;s a ton of information floating around on preprocessors nowadays. Most of that info is geared towards Mac users, so in this post I&#8217;m providing a very simple guide to help Windows-based developers get up and running quickly with <a href="http://sass-lang.com/">Sass</a> (my preprocessor of choice).</p>
<p>This article is filed under the <a href="http://www.impressivewebs.com/css-basics">CSS Basics</a> category on this blog, but any developers who already use Sass on Windows can add their feedback, too.</p>
<p>Overall, Sass is not difficult at all to get set up, even if you&#8217;re doing it on the command-line. But if you have no interest in going through all these steps, but still want to use Sass on Windows, well, just <a href="#native">skip to the final heading</a> in this post for a list of apps that let you start using Sass on Windows with minimal setup.</p>
<h2>1. Install Ruby</h2>
<p>Because Sass is a Ruby gem, the first thing you need to do is install Ruby using <a href="http://rubyinstaller.org/">the Windows installer</a>. Unlike OS X, Ruby is not installed by default on Windows, so Windows users need to install it manually.</p>
<p>When you go through the installation wizard, you&#8217;ll come to this options screen:</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-step-1.jpg" alt="Install Ruby" title="Install Ruby" width="680" height="398" class="wide_image wi_new"></p>
<p>From what I can tell, the only option that you need to check on that one is the middle option, which helps your command-line instructions recognize where to find (as it says) &#8220;Ruby executables&#8221;. Otherwise, you&#8217;ll get the error message &#8220;ruby is not recognized as an internal or external command&#8221; when you try to install Sass in the command prompt (see next step).</p>
<p>If anyone has any other pertinent info on this particular aspect of the setup, then please comment and I&#8217;ll update accordingly. But that should be enough for the first step.</p>
<h2>2. Install Sass on Windows Using the Command Prompt</h2>
<p>Now that you have Ruby installed, you&#8217;ll be able to install Sass. To do this, open the command prompt by doing one of the following:</p>
<ul class="body_list">
<li>Start&#8211;&gt;Run, then type &#8220;cmd&#8221;; or</li>
<li>Start&#8211;&gt;All Programs&#8211;&gt;Accessories, then choose &#8220;Command Prompt&#8221;</li>
</ul>
<p>Once the command prompt is open, install Sass by typing the following in the prompt:</p>
<p><code>gem install sass</code></p>
<p>Then hit &#8220;enter&#8221;, and wait for Sass to be installed. It should look like this when done:</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-step-2.jpg" alt="Install Sass in the command prompt" title="Install Sass in the command prompt" width="680" height="354" class="wide_image wi_new"></p>
<p>If you want to have the added benefit of <a href="http://compass-style.org/">Compass</a>, which is an authoring framework that uses Sass, you can instead choose to do &#8220;gem install compass&#8221;, which will install both Compass and Sass at the same time. I won&#8217;t get into the details on Compass here, but you can Google around for some info on that once you&#8217;ve started using Sass.</p>
<h2>3. Set Up a Sass File</h2>
<p>Now that Ruby and Sass are installed, you want to tell Sass what file you&#8217;re working on and let it compile your CSS from your Sass file.</p>
<p>In the command prompt, navigate to the folder where you&#8217;re going to write your CSS using Sass syntax. This is not a tutorial on command-line syntax, so you&#8217;ll have to figure that out on your own if you&#8217;ve never done it. You can check out <a href="http://www.watchingthenet.com/how-to-navigate-through-folders-when-using-windows-command-prompt.html">this link</a> or just do a Google search for tutorials on simple command-line expressions.</p>
<p>Here&#8217;s how my prompt looked after I navigated to my folder:</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-step3.jpg" alt="Navigate in the prompt" title="Navigate in the prompt" width="680" height="354" class="wide_image wi_new"></p>
<p>Notice that I&#8217;ve navigated using the &#8220;cd&#8221; or &#8220;change directory&#8221; command to locate the folder I&#8217;m working in.</p>
<p>Now, using Windows Explorer, go into that folder and create a new CSS file with the extension &#8220;.scss&#8221;. So instead of the usual &#8220;.css&#8221; extension, you&#8217;re simply adding an &#8220;s&#8221; to the front of the extension. You can do this by either creating a regular CSS file and changing the extension, or by creating a blank text file and changing the .txt extension to .scss.</p>
<h2>4. Tell Sass to &#8220;watch&#8221; the File</h2>
<p>Once your file exists, you want to tell Sass to keep an eye on it for changes, so it can compile it into a regular CSS file with traditional CSS syntax.</p>
<p>In the command prompt, inside the folder where your .scss file exists, type the following then hit enter:</p>
<p><code>sass --watch styles.scss:styles.css</code></p>
<p>You can copy the above code and paste it into the prompt by right-clicking and choosing &#8220;paste&#8221; (ctrl-V won&#8217;t work there). Ensure that &#8220;styles.scss&#8221; matches the file name that you chose when you created your new .scss file, and the same for the resulting .css file. Don&#8217;t worry that the .css file doesn&#8217;t exist yet; Sass will create it automatically.</p>
<p>Once you&#8217;ve used the correct command as shown above, you should see this in the command prompt:</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-step4.jpg" alt="Tell Sass to watch your file" title="Tell Sass to watch your file" width="680" height="354" class="wide_image wi_new"></p>
<p>As you can see, Sass is now &#8216;watching&#8217; your .scss file for changes. To stop the watching, just hit ctrl-C in the prompt.</p>
<h2>5. Write Some Sass on Windows and Let it Compile</h2>
<p>Using any text editor, open your .scss file and throw some Sass in there. This article is not about Sass syntax (there&#8217;s tons of stuff online for that, and I&#8217;ll probably cover something in the future), but here&#8217;s an example you can copy and paste, taken from the Sass website (use the &#8220;view plain&#8221; link to get a clean copy of the code without line numbers):</p>
<pre name="code" class="css">$blue: #3bbfce;
$margin: 16px;

.content-navigation {
  border-color: $blue;
  color: darken($blue, 9%);
}

.border {
  padding: $margin / 2;
  margin: $margin / 2;
  border-color: $blue;
}
</pre>
<p>After pasting that into your text editor, just save your .scss file then go back to the command prompt. You should see something like the following:</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2012-08/sass-step4b.jpg" alt="Sass detects changes, compiles to CSS" title="Sass detects changes, compiles to CSS" width="680" height="354" class="wide_image wi_new"></p>
<p>Notice that Sass has automatically detected the changes to the file and has produced a new file in the same folder. In that folder, you&#8217;ll see that new file, called &#8220;styles.css&#8221; (or whatever you named your .scss file). Open that new file in your text editor to see the compiled CSS.</p>
<p>Using the example above, you should see the output appear as follows (there might be a slight variation in curly brace placement or spacing):</p>
<pre name="code" class="css">.content-navigation {
  border-color: #3bbfce;
  color: #2ca2af;
}

.border {
  padding: 8px;
  margin: 8px;
  border-color: #3bbfce;
}
</pre>
<p>Now you can continue to write Sass-based code in your .scss file and Sass will keep detecting those changes and overwriting your CSS file every time you save the original file.</p>
<p>Of course, keep in mind that in your HTML file, when you reference your CSS, you&#8217;ll point to your regular .css file. The .scss file is just for your editing, and doesn&#8217;t get used directly in any web pages.</p>
<h2 id="native">Skip Everything Above and Use an App!</h2>
<p>If using the command prompt still bothers you (and it really shouldn&#8217;t, as the above instructions are pretty simple), then you can try out one of the following apps:</p>
<ul class="body_list">
<li><a href="http://alphapixels.com/prepros/">Prepros App</a></li>
<li><a href="http://koala-app.com/">Koala</a></li>
<li><a href="http://compass.kkbox.com/">Compass.app</a></li>
<li><a href="https://scout-app.io/">Scout App</a></li>
</ul>
<p>The post <a href="https://www.impressivewebs.com/sass-on-windows/">Setting Up Sass on Windows</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/sass-on-windows/feed/</wfw:commentRss>
			<slash:comments>56</slash:comments>
		
		
			</item>
		<item>
		<title>Using Min/Max Width and Height in CSS</title>
		<link>https://www.impressivewebs.com/min-max-width-height-css/</link>
					<comments>https://www.impressivewebs.com/min-max-width-height-css/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Tue, 26 Jun 2012 10:00:39 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=7132</guid>

					<description><![CDATA[<p>Even if you're just getting started with CSS, you've likely used the <code>height</code> and <code>width</code> properties quite a bit already.</p>
<p>But you've probably noticed that those properties can put unnecessary constraints on your page elements. So you might benefit from knowing and using related properties that use the "min" and "max" prefixes.</p>
<p>The post <a href="https://www.impressivewebs.com/min-max-width-height-css/">Using Min/Max Width and Height in CSS</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Even if you&#8217;re just getting started with CSS, you&#8217;ve likely used the <code>height</code> and <code>width</code> properties quite a bit already.</p>
<p>But you&#8217;ve probably noticed that those properties can put unnecessary constraints on your page elements. So you might benefit from knowing and using related properties that use the &#8220;min&#8221; and &#8220;max&#8221; prefixes.</p>
<h2>min-width / min-height</h2>
<p>The <code>min-width</code> and <code>min-height</code> properties accept unit values the exact same way that the <code>height</code> and <code>width</code> properties do, so there&#8217;s no difference in the syntax. You can use any acceptable unit, including pixels, ems, and percentages.</p>
<p>These properties are used to tell the browser to render an element at a &#8220;minimum&#8221; size. Here&#8217;s an example with both:</p>
<pre name="code" class="css">
.element {
    min-height: 200px;
    min-width: 200px;
}
</pre>
<p>A block-level element with the above CSS would have, at the very least, dimensions of 200&#215;200 pixels &#8212; even if the element was empty. However, since block-level elements will, by default, naturally expand to fit the available space, only the <code>min-height</code> value would actually have any effect in many cases.</p>
<p>To see the effects of <code>min-width</code>, you could add a float to the element. <a href="http://jsbin.com/ubikid/edit#html,live">Here&#8217;s a demonstration</a>. Try removing the float in that example, and you&#8217;ll see the element expand to fit the page.</p>
<h2>max-width / max-height</h2>
<p>Like the &#8220;min&#8221; properties, <code>max-width</code> and <code>max-height</code> accept the usual unit values. But this time, instead of a <em>minimum</em> size for an element, these properties set the <em>maximum</em> size. Here&#8217;s another simple example:</p>
<pre name="code" class="css">
.element {
    width: 15%;
    height: 15%;
    max-height: 200px;
    max-width: 200px;
}
</pre>
<p>Notice that this time I&#8217;ve specified percentage values for the width and height, but I&#8217;ve constrained the maximum width and height values at 200px. The width of &#8220;15%&#8221; will be calculated based on the size of the parent element (that is, 15% of the parent). But even if the parent element is 5000px wide, the <code>.element</code> box won&#8217;t get any wider than 200px, which is the maximum width that we&#8217;ve set.</p>
<h2>Final Notes</h2>
<p>Min- and max- width and height values should become a regular part of your CSS toolbox. <code>min-height</code> is useful if you want to <a href="http://www.impressivewebs.com/new-haslayout-ie/">give an element layout in IE7</a>. Also, you could have a problem where you have <a href="http://www.impressivewebs.com/fluid-header-footer-problem/">a fluid header or footer that doesn&#8217;t expand properly</a>, which can be fixed with <code>min-width</code>.</p>
<p>And, of course, these properties are <strong>quite useful for responsive web design</strong>. Used in conjunction with CSS3 media queries, the max- properties can help you ensure that you don&#8217;t have overly-wide elements on any page, which can make content awkward and unreadable.</p>
<p>The post <a href="https://www.impressivewebs.com/min-max-width-height-css/">Using Min/Max Width and Height in CSS</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/min-max-width-height-css/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>CSS Selectors Defined</title>
		<link>https://www.impressivewebs.com/css-selectors/</link>
					<comments>https://www.impressivewebs.com/css-selectors/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Thu, 12 Apr 2012 10:00:36 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=6301</guid>

					<description><![CDATA[<p>If you're just getting started with CSS, it's good to have a fundamental understanding of what we mean when we refer to <strong>CSS selectors</strong>. In this post I'll briefly describe all the most well-known CSS selectors along with some examples.</p>
<p>The post <a href="https://www.impressivewebs.com/css-selectors/">CSS Selectors Defined</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you&#8217;re just getting started with CSS, it&#8217;s good to have a fundamental understanding of what we mean when we refer to <strong>CSS selectors</strong>. In this post I&#8217;ll briefly describe all the most well-known CSS selectors along with some examples.</p>
<p>A &#8220;selector&#8221; is the instruction in a CSS rule set that tells the browser what elements to &#8216;select&#8217; for styling. Look at the two examples below:</p>
<pre name="code" class="css">.box {
  background-color: red;
}

form textarea {
  background-color: blue;
}
</pre>
<p>In each of those examples, the selector is the part of the rule set that appears before the opening curly brace. &#8220;.box&#8221; is the first selector and &#8220;form textarea&#8221; is the second selector.</p>
<h2>Selectors Defined with Examples</h2>
<p>Here is a brief definition of each type of selector, with examples:</p>
<p><strong>Universal Selector</strong><br />
This selector consists of the asterisk character, like this:</p>
<pre name="code" class="css">* {
  background-color: red;
}
</pre>
<p>When used on its own like above, this selects every element on the page.</p>
<p><strong>Element Type Selector</strong><br />
Also called just the &#8220;type selector&#8221;, this selector matches HTML elements by tag name. Two examples:</p>
<pre name="code" class="css">h2 {
  background-color: red;
}

div {
  background-color: red;
}
</pre>
<p><strong>Class Selector</strong><br />
This selects an element that matches a class name defined in a class attribute in the HTML.</p>
<pre name="code" class="css">.element {
  background-color: red;
}
</pre>
<p>This is easily my favourite selector, and all good CSS developers should use it abundantly. You can put multiple classes separated by spaces on a single class attribute, which makes this selector quite powerful.</p>
<p><strong>ID Selector</strong><br />
This selects an element that matches an id defined in an id attribute in the HTML.</p>
<pre name="code" class="css">#element {
  background-color: red;
}
</pre>
<p><strong>Descendant Selector</strong><br />
This selector is defined with a space character separating two selectors, and represents a child element, but not just immediate children, further nested ones as well.</p>
<pre name="code" class="css">.parent .child {
  background-color: red;
}
</pre>
<p><strong>Attribute Selector</strong><br />
This selector targets an element based on an HTML attribute and/or attribute value. Both examples below are valid attribute selectors:</p>
<pre name="code" class="css">div[style] {
  background-color: red;
}

input[type="text"] {
  background-color: red;
}
</pre>
<p>The first example targets any <code>&lt;div&gt;</code> element that has a &#8220;style&#8221; attribute. The second example targets any <code>&lt;input&gt;</code> element that has a &#8220;type&#8221; attribute with a value of &#8220;text&#8221;.</p>
<p><strong>Child Selector</strong><br />
This selects an element based on it being an immediate child of another element:</p>
<pre name="code" class="css">.one &gt; .two {
  background-color: red;
}
</pre>
<p>So this will not style a &#8220;.two&#8221; element unless it is an immediate child of a &#8220;.one&#8221; element. It can&#8217;t be nested inside another element, it has to be an immediate child element. And only the child is styled, not the parent.</p>
<p><strong>Adjacent Sibling Selector</strong><br />
This selector, which uses the plus sign, targets elements that are &#8220;adjacent&#8221; to each other, or immediate siblings, and they must have the same parent element.</p>
<pre name="code" class="css">h2+p {
  background-color: red;
}
</pre>
<p><strong>General Sibling Selector</strong><br />
This uses the tilde character and is exactly the same as the adjacent sibling selector except the elements don&#8217;t have to be immediate siblings.</p>
<pre name="code" class="css">h2~p {
  background-color: red;
}
</pre>
<p><strong>Pseudo-class</strong><br />
While technically falling under the category of &#8220;selectors&#8221;, these are not normally referred to as &#8220;selectors&#8221;, but just pseudo-classes. These select an element based on a state the element is in. Here are a few examples:</p>
<pre name="code" class="css">a:visited {
  background-color: red;
}

input:focus {
  background-color: red;
}
</pre>
<p><strong>Pseudo-element</strong><br />
Again, not normally referred to as a selector, these actually represent elements in the HTML page that are not really part of the rendered HTML:</p>
<pre name="code" class="css">p:first-letter {
  background-color: red;
}

p:before {
  content: "";
  background-color: red;
}
</pre>
<p>The &#8220;:before&#8221; and &#8220;:after&#8221; pseudo-elements are unique from other pseudo-elements in that they must be used along with the <code>content</code> property. For more on these, see <a href="https://www.smashingmagazine.com/2011/07/learning-to-use-the-before-and-after-pseudo-elements-in-css/">my article on Smashing Magazine</a>.</p>
<p>If you enjoyed this article, you might also like a post I wrote defining a number of different <a href="https://www.impressivewebs.com/css-terms-definitions/">CSS Terms</a>.</p>
<p>The post <a href="https://www.impressivewebs.com/css-selectors/">CSS Selectors Defined</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/css-selectors/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding CSS Shorthand</title>
		<link>https://www.impressivewebs.com/understanding-css-shorthand/</link>
					<comments>https://www.impressivewebs.com/understanding-css-shorthand/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Thu, 16 Feb 2012 11:00:33 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=5624</guid>

					<description><![CDATA[<p>Shorthand declarations can be tricky to master. In this post, I go through the basics of shorthand, and offer some suggestions for avoiding certain gotchas.</p>
<p>The post <a href="https://www.impressivewebs.com/understanding-css-shorthand/">Understanding CSS Shorthand</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When declaring certain CSS properties, you have the option to use either the longhand, explicit declaration of a single CSS property, or a single-line shorthand declaration that combines a number of properties.</p>
<p>Let&#8217;s look at how shorthand works with some common examples, and I&#8217;ll try to explain some of the quirks associated with CSS shorthand.</p>
<h2>A Shorthand Example</h2>
<p>Declaring a background image is quite common in CSS. A <code>background</code> declaration in shorthand looks like this:</p>
<pre name="code" class="css">
.element {
  background: #fff url(../images/bg-image.png) no-repeat fixed 20px 20px;
}
</pre>
<p>To understand what&#8217;s happening in this shorthand declaration, here is the exact same CSS using longhand:</p>
<pre name="code" class="css">
.element {
  background-color: #fff;
  background-image: url(../images/bg-image.png);
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: 20px 20px;
}
</pre>
<p>You can see already why most CSS developers prefer shorthand notation over longhand &#8212; the first example condenses five lines of CSS into one.</p>
<h2>Simple Shorthand Declarations</h2>
<p>Some shorthand declarations work in a very simple way. The example I showed you above with the <code>background</code> property is one of the more complex types (more on that below). But other shorthand declarations are quite easy to understand and work with.</p>
<p>The <a href="http://www.impressivewebs.com/difference-between-margins-padding-css/">margin and padding</a> properties are good examples of properties you&#8217;ll use often in their shorthand notation. And they&#8217;re not difficult to understand:</p>
<pre name="code" class="css">
.element {
  padding: 20px;
}
</pre>
<p>In this example, although I&#8217;ve left out three other values, those values are assumed to be equal to the one value shown. So with this code, all four sides of the targeted element will have 20px of padding.</p>
<p>We can also do this:</p>
<pre name="code" class="css">
.element {
  padding: 20px 10px;
}
</pre>
<p>In this example, we are declaring the top and right padding explicitly. The bottom and left padding, although not declared explicitly, will assume the same values as top and right &#8212; in that order. So the box will have 20px of top and bottom padding, and 10px of right and left padding.</p>
<p>And again, the long-hand equivalent of the example above would look like this:</p>
<pre name="code" class="css">
.element {
  padding-top: 20px;
  padding-right: 10px;
  padding-bottom: 20px;
  padding-left: 10px;
}
</pre>
<p>Margins and CSS3&#8217;s <a href="http://css3clickchart.com/?prop=border-radius">border-radius</a> property work exactly the same way, except with <code>border-radius</code> we&#8217;re dealing with corners instead of sides.</p>
<h2>The More Complex Shorthand Declarations</h2>
<p>Other shorthand declarations are a little more complicated, but with a few small exceptions, shouldn&#8217;t really cause you too many problems once you get the hang of them. The <code>background</code> shorthand declaration I showed you earlier is one example of these.</p>
<p>Other shorthand properties that may trip you up at times include:</p>
<ul class="body_list">
<li><code>list-style</code></li>
<li><code>font</code></li>
<li><code>border</code></li>
<li><code>outline</code></li>
</ul>
<p><a href="http://css3clickchart.com">CSS3 features</a> that use shorthand using the more complex style of notation include:</p>
<ul class="body_list">
<li><code>animation</code></li>
<li><code>border-image</code></li>
</ul>
<p>So what is it that makes these other shorthand properties more difficult to understand? Well, because these properties accept different types of values (sometimes keywords, sometimes units, etc.), leaving out certain values in a shorthand declaration will often have unexpected results.</p>
<p>Here&#8217;s an example using <code>background</code>:</p>
<pre name="code" class="css">
.element {
  background-color: blue;
  background: url(../images/bg-image.png) no-repeat;
}
</pre>
<p>With the code above, you would expect that the targeted element would have a non-repeating background image set over a blue background. But that will not happen unless we reverse the order of the properties. Because we&#8217;ve used <code>background</code> shorthand, this causes all the values associated with the <code>background</code> property to be reset to their initial, or default, state. In this case, the background color becomes &#8220;transparent&#8221;, overwriting the &#8220;blue&#8221;.</p>
<h2>Avoid Getting Tripped Up</h2>
<p>So it&#8217;s important to understand that anytime you use one of these more convoluted shorthand declarations, all omitted values associated with that shorthand declaration will be reset to their defaults.</p>
<p>Normally this is not a problem, because with properties associated with backgrounds, lists, padding, etc, those properties aren&#8217;t inheriting their values from parent elements. The only place where I have found this can cause headaches is in association with the <a href="http://www.impressivewebs.com/a-primer-on-the-css-font-shorthand-property/">font shorthand</a> property.</p>
<p>That&#8217;s why I did <a href="http://www.impressivewebs.com/screencast-why-you-shouldnt-use-css-font-shorthand/">this old screencast</a> (which is a bit out of date now) and created <a href="http://www.impressivewebs.com/css-font-shorthand-property-cheat-sheet/">this cheatsheet</a> that discusses some of the problems you might run into when using the shorthand <code>font</code> property. Basically, we expect certain typographical properties to inherit from their parents. But when we use <code>font</code> in shorthand, all the properties associated with that declaration are reset to their initial state, thus losing that natural inheritance.</p>
<p>Another thing that can happen with <code>font</code> shorthand and some other shorthand declarations is that if you omit a mandatory value, the entire line will be ignored by the browser. This is another thing to keep in the back of your mind in case you&#8217;re scratching your head wondering why a certain CSS property isn&#8217;t having any effect.</p>
<h2>Conclusion</h2>
<p>Overall, I highly recommend using shorthand whenever you can. The only one that I avoid like the plague is <code>font</code>. I&#8217;m perfectly content to use longhand for those, and I think many feel the same way.</p>
<p>It does help to use longhand when you&#8217;re first starting out, to get to know each of the individual properties. But for the most part you&#8217;ll stick to shorthand once you&#8217;ve got a good handle on the syntax for the property you&#8217;re using.</p>
<p>The post <a href="https://www.impressivewebs.com/understanding-css-shorthand/">Understanding CSS Shorthand</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/understanding-css-shorthand/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>Current Page Link Styles</title>
		<link>https://www.impressivewebs.com/current-page-link-styles/</link>
					<comments>https://www.impressivewebs.com/current-page-link-styles/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Mon, 16 Jan 2012 11:00:22 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=5363</guid>

					<description><![CDATA[<p>A simple post describing a couple of ways to indicate "current page" in your navigation using CSS.</p>
<p>The post <a href="https://www.impressivewebs.com/current-page-link-styles/">Current Page Link Styles</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>One of the most common things you&#8217;ll see on any website is a navigation bar that has a different set of CSS styles applied to the <a href="https://www.impressivewebs.com/text-links-hover-states/">link</a> that represents the current page the user is on. (Maybe I&#8217;ll actually get around to doing this on my own site!) There are a few ways you can do this with HTML and CSS, which I&#8217;ll outline here.</p>
<h2>Using a Unique Link Class</h2>
<p>Probably the most common and easiest way to do this is by simply applying a different class with appropriate styles on the current page link. So in your HTML you would see something like this:</p>
<pre name="code" class="html">&lt;ul class="nav"&gt;
  &lt;li&gt;&lt;a href="index.html"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="about.html"&gt;About&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="services.html"&gt;Services&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="products.html" class="current"&gt;Products&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="contact.html"&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>The CSS would then require something like the following:</p>
<pre name="code" class="css">a:link, a:visited {
  color: blue;
}

a.current:link, a.current:visited {
  color: white;
  background-color: blue;
}
</pre>
<p>Now all links with a class of &#8220;current&#8221; will have white text on a blue background, while all other links will have just blue text.</p>
<p>The only thing you have to make sure of is that the location of the class gets changed depending on the page you&#8217;re on. For example, the HTML shown above would appear on the &#8220;Products&#8221; page, but on the &#8220;Contact&#8221; page the &#8220;current&#8221; class would be moved to the &#8220;Contact&#8221; link.</p>
<h2>Adding a Class to the &lt;body&gt;</h2>
<p>This next method is a lot messier, but is an option if you don&#8217;t mind more HTML. You can add a unique class to the <code>&lt;body&gt;</code> tag and then have a different class for each link. The body class would change depending on what page the user was viewing. So on the &#8220;About&#8221; page, your <code>&lt;body&gt;</code> tag would look like this:</p>
<pre name="code" class="html">&lt;body class="about"&gt;
</pre>
<p>The HTML for your links would look like this:</p>
<pre name="code" class="html">&lt;ul class="nav"&gt;
  &lt;li&gt;&lt;a href="index.html" class="home"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="about.html" class="about"&gt;About&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="services.html" class="services"&gt;Services&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="products.html" class="products"&gt;Products&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="contact.html" class="contact"&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Then in your CSS you would have the following:</p>
<pre name="code" class="css">a:link, a:visited {
  color: blue;
}

body.home a.home:link,
body.about a.about:link,
body.services a.services:link,
body.products a.services:link,
body.contact a.contact:link {
  color: white;
  background-color: blue;
}
</pre>
<p>This includes a separate selector for each nav item. So although the different unique link classes will appear in the HTML on every page, the unique &#8220;current page&#8221; styles will only take effect on the page that has the matching <code>&lt;body&gt;</code> class.</p>
<h2>Final Notes</h2>
<p>A few things can be noted about the technique outlined here:</p>
<ul class="body_list">
<li>If you are using PHP (or some other back-end language), you can generate the classes dynamically based on the current page</li>
<li>Although I&#8217;m applying the unique classes to the link elements, you can use the <code>&lt;li&gt;</code> elements if you want</li>
<li>I&#8217;ve seen people use a class of &#8220;active&#8221; instead of the class of &#8220;current&#8221; that I&#8217;m using here; I think &#8220;current&#8221; (or something else other than &#8220;active&#8221;) is better because CSS already has a pseudo-class called <code>:active</code> that means something completely different, so that might be confusing for beginners</li>
<li>I suppose you could use the <code>:nth-child()</code> pseudo-class to target the current link by number in the list, but that seems a little convoluted and not very convenient or maintainable</li>
<li>If you want to do this on a WordPress site, <a href="https://vanseodesign.com/wordpress/hightlight-current-page-wordpress/">this article</a> covers that topic</li>
</ul>
<p>The post <a href="https://www.impressivewebs.com/current-page-link-styles/">Current Page Link Styles</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/current-page-link-styles/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
			</item>
		<item>
		<title>What&#8217;s the Difference Between Classes and IDs in CSS?</title>
		<link>https://www.impressivewebs.com/difference-class-id-css/</link>
					<comments>https://www.impressivewebs.com/difference-class-id-css/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Fri, 16 Dec 2011 11:00:45 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=5108</guid>

					<description><![CDATA[<p>When applying CSS styles to an element in your HTML, you'll be using different CSS selectors to target your elements.</p>
<p>Two of the most common selectors used in CSS are the "class" selector and the "ID" selector. There are many others, but this post will focus on these two, and I'll describe the difference so you'll know the potential effects of using either of these selectors.</p>
<p>The post <a href="https://www.impressivewebs.com/difference-class-id-css/">What&#8217;s the Difference Between Classes and IDs in CSS?</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When applying CSS styles to an element in your HTML, you&#8217;ll be using different CSS selectors to target your elements.</p>
<p>Two of the most common selectors used in CSS are the &#8220;class&#8221; selector and the &#8220;ID&#8221; selector. There are many others, but this post will focus on these two, and I&#8217;ll describe the difference so you&#8217;ll know the potential effects of using either of these selectors.</p>
<h2>The ID Selector is Very Specific</h2>
<p>An ID is defined in your HTML like this:</p>
<pre name="code" class="html">
&lt;div id="element"&gt;
&lt;!-- stuff goes here... --&gt;
&lt;/div&gt;
</pre>
<p>And in your CSS you can target the element, and apply styles to it, like this:</p>
<pre name="code" class="css">
#element {
    background: blue;
}
</pre>
<p>CSS styles are applied based on rules relating to the cascade and specificity. Because this is a post aimed at CSS beginners, I&#8217;m not going to go into the gory details of those subjects. If you want to delve into this, there&#8217;s a nice article <a href="http://coding.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/">on Smashing Magazine</a> by Inayaili de Leon that might be worth a peek.</p>
<p>The specificity of a selector can have a profound effect on the future maintenance and debugging of your CSS code. So, with that in mind, do realize that if you choose to use the ID selector, you <strong>may end up causing specificity issues</strong> that will force you later in development to use even stronger selectors. This could easily get out of hand and cause your stylesheet to be less maintainable and bloated.</p>
<p>Styles in a CSS file are supposed to &#8220;cascade&#8221;. So, theoretically, this should allow styles declared later in your stylesheet to override styles that are declared earlier. But because of more specific selectors (like IDs), this doesn&#8217;t happen as often as we&#8217;d like.</p>
<p>For example, if you had the following HTML:</p>
<pre name="code" class="html">
&lt;div id="element" class="element"&gt;
&lt;!-- stuff goes here... --&gt;
&lt;/div&gt;
</pre>
<p>And CSS:</p>
<pre name="code" class="css">
#element {
    background: blue;
}

body div.element {
    background: green;
}
</pre>
<p>Even though the <code>body div.element</code> selector appears after the <code>#element</code> ID selector, and despite the fact that the &#8220;body&#8221; element is included as part of the selector, the background of the element will be blue &#8212; not green &#8212; because the ID selector is more specific than the second selector, and <strong>the natural cascade has been overridden</strong>.</p>
<p>It may seem at first glance to be an advantage to have a very specific selector. But in the long run, this is not a good thing. Also, because an ID has to be unique and must only appear once per HTML page, <strong>you can&#8217;t reuse the styles on an ID selector</strong>, so your stylesheet will be much larger if you end up using a lot of IDs.</p>
<h2>Class Selectors are Much Easier to Work With</h2>
<p>Classes are applied in HTML like this:</p>
<pre name="code" class="html">
&lt;div class="element"&gt;
&lt;!-- stuff goes here... --&gt;
&lt;/div&gt;
</pre>
<p>And you target the element in your CSS like this (which, I&#8217;ve already demonstrated in the previous section, really):</p>
<pre name="code" class="css">
.element {
    background: blue;
}
</pre>
<p>Class selectors are, in my opinion, highly underrated and a much cleaner and easier to use option for applying styles to elements. There are a number of reasons for this.</p>
<p><strong>Classes can be reused</strong> (you&#8217;re not limited to a single class per page, like IDs). This allows you to avoid repeating styles unnecessarily. You can also include multiple classes using a single attribute, like this:</p>
<pre name="code" class="html">
&lt;div class="element class2 class3"&gt;
&lt;!-- stuff goes here... --&gt;
&lt;/div&gt;
</pre>
<p>You also have the option to chain your classes using selectors like <code>.element.class2.class3</code> (notice no spaces between the classes). While this is possible, you should know that this method is buggy in IE6, which is why these types of chained class selectors have been largely avoided for so many years.</p>
<p>And best of all, <strong>class selectors are not extremely specific</strong>. So a class of <code>.element</code> will override the less specific element selector (e.g. a plain <code>span</code> or <code>div</code> selector), but it will not override other classes &#8212; unless it appears after those classes in the CSS.</p>
<p>This is great for maintenance and debugging of your CSS, because when you add new classes to your CSS, you won&#8217;t be scratching your head wondering why the styles don&#8217;t take effect right away.</p>
<h2>Final Notes</h2>
<p>So my advice is: Don&#8217;t use IDs as CSS selectors unless you have really good, practical reasons for doing so. <strong>Use classes abundantly</strong> and allow the natural cascade to work its magic.</p>
<p>This doesn&#8217;t mean you won&#8217;t use IDs. You will still need IDs for in-page links (i.e. fragment identifiers), and for JavaScript and jQuery hooks.</p>
<p>You might think: What if there&#8217;s an element on the page that already has an ID (for non-CSS reasons), and it&#8217;s an element that you absolutely know is going to be unique and won&#8217;t have repeated or reusable styles? Well, in my opinion, even in this case, there is no reason to use the ID selector in your CSS, and you should still use a class instead.</p>
<p>If you take each one as a stand-alone selector, regardless of all other styles and selectors, there is no difference between <code>#element</code> and <code>.element</code>. But when you factor in the negative effects of an ID selector (the non-reusability, the high specificity, the detriment to the cascade), I think the class selector is much more powerful and should be an overwhelming choice.</p>
<p>Finally, if you want to get into some more good reasons to use classes heavily, you can check out my recent Smashing Magazine article covering <a href="http://coding.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/">Object Oriented CSS</a>.</p>
<p>The post <a href="https://www.impressivewebs.com/difference-class-id-css/">What&#8217;s the Difference Between Classes and IDs in CSS?</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/difference-class-id-css/feed/</wfw:commentRss>
			<slash:comments>22</slash:comments>
		
		
			</item>
		<item>
		<title>The Difference Between &#8220;Block&#8221; and &#8220;Inline&#8221;</title>
		<link>https://www.impressivewebs.com/difference-block-inline-css/</link>
					<comments>https://www.impressivewebs.com/difference-block-inline-css/#comments</comments>
		
		<dc:creator><![CDATA[Louis Lazaris]]></dc:creator>
		<pubDate>Wed, 30 Nov 2011 11:10:47 +0000</pubDate>
				<category><![CDATA[CSS Basics]]></category>
		<guid isPermaLink="false">http://www.impressivewebs.com/?p=4944</guid>

					<description><![CDATA[<p>For the purpose of CSS styling, elements can be generally divided into a few different categories. Two of those categories are <em>block-level</em> elements and <em>inline</em> elements.</p>
<p>In my opinion, this is one of those areas that, once understood correctly, can help beginners to take their CSS skills to the next level.</p>
<p>The post <a href="https://www.impressivewebs.com/difference-block-inline-css/">The Difference Between &#8220;Block&#8221; and &#8220;Inline&#8221;</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>For the purpose of CSS styling, elements can be generally divided into a few different categories. Two of those categories are <em>block-level</em> elements and <em>inline</em> elements.</p>
<p>In my opinion, this is one of those areas that, once understood correctly, can help beginners to take their CSS skills to the next level.</p>
<h2>Block-level Elements</h2>
<p>A block element is an element that has, but may not be limited to, the following characteristics:</p>
<ul class="body_list">
<li>If no width is set, will expand naturally to fill its parent container</li>
<li>Can have margins and/or padding</li>
<li>If no height is set, will expand naturally to fit its child elements (assuming they are not floated or positioned)</li>
<li>By default, will be placed below previous elements in the markup (assuming no floats or positioning on surrounding elements)</li>
<li>Ignores the <code>vertical-align</code> property</li>
</ul>
<p>So, for a block element, it&#8217;s not necessary to give it a set width or to give it a <a href="http://www.impressivewebs.com/width-100-percent-css/">width of 100%</a> if you want it to fill its parent horizontally. In fact, doing either of those things may cause maintainability issues or other undesirable problems.</p>
<p>And, as the fourth item in the above list indicates, it&#8217;s also not necessary to &#8220;clear&#8221; a block element; assuming no floats are affecting the block element, it will be cleared automatically and will start on the next &#8220;line&#8221; in the page&#8217;s output.</p>
<p><strong>Examples of Block Elements:</strong><br />
<code>&lt;p&gt;</code>, <code>&lt;div&gt;</code>, <code>&lt;form&gt;</code>, <code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;ul&gt;</code>, <code>&lt;li&gt;</code>, and <code>&lt;h1&gt;</code>.</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2011-11/block.jpg" alt="Block-level Elements" title="Block-level Elements" width="680" height="383" class="wide_image wi_new"></p>
<h2>Inline Elements</h2>
<p>An inline element has, but may not be limited to, the following characteristics:</p>
<ul class="body_list">
<li>Flows along with text content, thus</li>
<li>Will not clear previous content to drop to the next line like block elements</li>
<li>Is subject to <a href="http://www.impressivewebs.com/css-white-space/">white-space</a> settings in CSS</li>
<li>Will ignore top and bottom margin settings, but will apply left and right margins, and any padding</li>
<li>Will ignore the <code>width</code> and <code>height</code> properties</li>
<li>If floated left or right, will automatically become a block-level element, subject to all block characteristics</li>
<li>Is subject to the <code>vertical-align</code> property</li>
</ul>
<p>The easiest way to picture an inline element is to think of it as <strong>a box that acts like text</strong>. What happens, for example, to text that&#8217;s not separated by other elements? It flows one letter after the other. If you put an inline element next to text, it will flow next to that text just like another piece of text.</p>
<p><strong>Examples of Inline Elements:</strong><br />
<code>&lt;a&gt;</code>, <code>&lt;span&gt;</code>, <code>&lt;b&gt;</code>, <code>&lt;em&gt;</code>, <code>&lt;i&gt;</code>, <code>&lt;cite&gt;</code>, <code>&lt;mark&gt;</code>, and <code>&lt;code&gt;</code>.</p>
<p><img loading="lazy" decoding="async" src="https://s3.amazonaws.com/impressivewebs/2011-11/inline.jpg" alt="Inline Element" title="Inline Element" width="680" height="383" class="wide_image wi_new"></p>
<h2>Other Notes</h2>
<p>You&#8217;ll notice that the examples of both block and inline elements are quite revealing: The block examples are structural elements, while the inline elements are text-based. This is an easy way to remember which is which, although at first you will sometimes be confused.</p>
<p>Generally speaking, you can put any block element inside another block element. You can also put any inline element inside a block element, as well as any inline element inside any other inline element. But you cannot put a block element inside an inline element &#8212; with (I believe) one exception: You can wrap an <code>&lt;a&gt;</code> element around any content, whether it be block elements, or inline elements, or a mixture of both.</p>
<p>You have the option to change any block-level element to an inline element, and vice-versa, using the <code>display</code> property. So keep that in mind if you need to do this. But don&#8217;t use the wrong element for the wrong purpose. An SEO guy once told me to put an <code>&lt;h2&gt;</code> element inside of a paragraph, and style it to look like regular text, because he wanted an SEO boost. Not a good idea, that&#8217;s what <code>&lt;em&gt;</code> is for.</p>
<p>One final thing to note is that, although from a CSS perspective block and inline do exist, from an HTML5 perspective, the different types of elements have been re-categorized, so that they&#8217;re more specific. You can read about these <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#content-models">content models</a> in the WHATWG HTML5 spec.</p>
<h2>Bonus Tip: Replaced Elements</h2>
<p>At the beginning, I said that block and inline were just two types of content. Generally speaking, those are the two primary kinds, and you won&#8217;t have to worry too much about any other kinds.</p>
<p>But there are what are referred to as <a href="http://reference.sitepoint.com/css/replacedelements">replaced elements</a>. Basically, these are neither block nor inline. But you might classify them as something closer to inline, but with block-like structure.</p>
<p>I won&#8217;t provide a detailed explanation here; you can check out the SitePoint article linked in the previous paragraph for full details. But some examples of replaced elements include:</p>
<p><code>&lt;img&gt;</code>, <code>&lt;object&gt;</code>, <code>&lt;input&gt;</code>, and <code>&lt;select&gt;</code>.</p>
<h2>Conclusion</h2>
<p>If you&#8217;re just starting out with CSS, understanding the behaviour of block vs. inline elements will go a long way to helping you code sites that are efficient and maintainable and don&#8217;t rely on overuse of floats or other undesirable methods.</p>
<p>The post <a href="https://www.impressivewebs.com/difference-block-inline-css/">The Difference Between &#8220;Block&#8221; and &#8220;Inline&#8221;</a> appeared first on <a href="https://www.impressivewebs.com">Impressive Webs</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.impressivewebs.com/difference-block-inline-css/feed/</wfw:commentRss>
			<slash:comments>35</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced (SSL caching disabled) 
Minified using Disk

Served from: www.impressivewebs.com @ 2026-04-23 14:41:55 by W3 Total Cache
-->