Network: SGGuest
Password: GridSend0909
If you have not already downloaded the files for this workshop - please download them at gdiboulder.com/bootstrap
Media queries are designed to make your life easier by allowing you to control how your elements look on different devices.
Essentially, they are conditional statements that will apply certain style rules to your elements, depending on the device your site is being viewed on.
Using media queries, this desktop design:
Also looks great on a tablet:
And rad on a smartphone!
You can also use media queries to make sure your content looks great when it's printed out!
A media query consists of a media type and an optional combination of media features. CSS rules inside the query will be applied only if the query is true.
@media [media types] and [media features] { /* media-specific rules */ }
They can also be specified for a linked stylesheet:
<link rel="stylesheet" media="<media types> and <media features>" href="alternative.css" />
All modern browsers support the "print" media type for specifying print styles.
@media print { body { background: white; } #header, #footer { display: none; } .section { page-break-inside: avoid; page-break-after: always; } }
Modern mobile browsers support media queries which depend on the device-width and/or orientation.
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { img { width: 100%; } }
A more general approach is just to query on min-width and max-width, which are calculated based on window size, not device size.
@media screen and (max-width: 640px) { #sidebar { display: none; } }
@media (min-width: 768px) and (max-width: 979px) { #sidebar { width: 200px; } }
The experimental device-pixel-ratio feature can be used to detect pixel density:
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) { #logo { background-image:url(images/icon@2x.png); } }
Instead of testing on the actual devices or resizing the browser, you can use these tools:
Older browsers do not know about newer CSS selectors/properties.
Use these sites to check compatibility:
When the CSS parser doesn't understand a property or value, it ignores it. For fallback, specify older syntaxes first.
RGBA & older browsers:
body { background:url(cyan_transparent_50.png); background:rgba(0,255,255,.5); }
CSS Gradients & older browsers:
button.glossy { background: #ccc url(gloss.png) 50% 50% repeat-x; background: #ccc -webkit-gradient(linear, left top, left bottom, from(rgba(255,255,255, .4)), to(rgba(0,0,0, .1))); }
Opacity & older browsers:
.transparent { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; filter: alpha(opacity=50); opacity: .5; }
In case you do need to specify CSS just for a particular browsers, there are a few ways.
In IE, you can use conditional comments to specify IE stylesheets:
<!--[if IE7]><link rel="stylesheet" type="text/css" media="screen" href="css/ie7.css" /><![endif]-->
Or to conditionally add classes:
<!--[if IE7]> <html class="ie7"> <![endif]-->
Not all browsers render CSS the same, with the most number of issues in IE. The best defense is to be aware and to test.
Since not all browsers work on all operating systems (IE on Mac), you may need help from these tools for cross-browser testing:
CSS reset stylesheets are used to normalize the default CSS across browsers.
Reset.css removes every default style.
Normalize.css normalizes the default styles across browsers (and is the preferred approach).
A grids system lets you layout pages according to fractions of a grid (usually 12, 16, or 24 columns).
Using YUI CSS Grids:
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.5.1/build/cssgrids/grids-min.css"> <div class="yui3-g"> <div class="yui3-u-5-24"> </div> <div class="yui3-u-19-24"> </div> </div>
Usually include a reset, a grids system, styles for typography and forms. Some include support for mobile/print.
With Bootstrap:
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"> <div class="container"> <div class="row"> <div class="col-md-4 col-xs-6"> </div> <div class="col-md-8"> <div class="alert">Hello!</div> </div> </div> </div>
In your exercises/bootstrap folder, open up index.html in the browser and in your text editor.
There are various ways that webpage performance can suffer because of CSS:
Luckily, there are ways to avoid these issues...
Selector types, from fastest to slowest:
CSS engines evaluate selectors from right to left.
/* CSS engine starts evaluating with h3 */ #footer h3 {} /* CSS engine starts evaluating with a */ ul li a {}
You can read more on the Mozilla Developer Network or use a tool like CSSLint to warn you of inefficient selectors.
CSS compression tools reduce the size of CSS files by:
For example, this:
.sidebar { /* color it grey, no border */ border-color: rgb(123, 123, 123); border-width: 0px; }
becomes:
.sidebar{border-color:#7b7b7b;border-width:0}
Some CSS Compression Tools:
When a pages uses many img tags or background-url properties, it slows down load time. For smaller images, CSS spriting can help.
Spriting uses one image file with an unlimited number of images in it. To load a certain image, you request a coordinate within the image file.
This is an example of CSS without sprites:
#nav li a.item1 {background-image:url('../img/image1.gif')} #nav li a:hover.item1 {background-image:url('../img/image1_over.gif')}
This is an example of the same CSS using sprites:
#nav li a {background-image:url('../img/image_nav.gif')} #nav li a.item1 {background-position:0px 0px} #nav li a:hover.item1 {background-position:0px -72px}
Instead of linking to an external image, data URIs allow you to embed the image directly into the document.
In CSS, it looks like this:
li { background: url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7) no-repeat left center; padding: 5px 0 5px 25px; }
An icon font is a font with icons instead of characters. You can make your own with icomoon or Font Custom or use the popular FontAwesome.
With an icon font, you include classes to add certain icons to your page.A pre-processor lets you write in a special, more efficient language and then compiles into organized CSS.
Common features:
Sass stands for "Syntactically Awesome Style Sheets." It runs on Ruby, so it's processed server-side.
/*Variables*/ @brand-color: #F05B62; nav { ul { margin: 0; padding: 0; list-style: none; } li { display: inline-block; } a { display: block; color: @brand-color; padding: 6px 12px; text-decoration: none; } }
Less is similar to Sass, but has slightly different syntax, and is processed using JavaScript (client-side).
@color-base: #2d5e8b; .class1 { background-color: @color-base; } .class2 { background-color: #fff; color: @color-base; } .class3 { border: 1px solid @color-base; }
Many web developers use build tools to help them automate tasks.
Turing School of Software & Design
Wednesday, October 1, 2014 - 5:30 PM to 6:45 PM
Galvanize Boulder
October 9th 6pm - 8pm
Galvanize Boulder
October 15th 6pm - 8pm