HTML5 Boilerplate & WordPress: Day 2 – CSS

::selection

[code lang=”css” highlight=”2,3,8,9″]
::-moz-selection {
color:#fff;
background: #00b6f2;
text-shadow: none;
}

::selection {
color:#fff;
background: #00b6f2;
text-shadow: none;
}
[/code]

  • Hex color value #00b6f2 is a nice shade of cyan
  • Font color is white

Image replacement

[code lang=”css” highlight=”6″]
/*
* Image replacement
*/

.ir {
display:block;
background-color: transparent;
border: 0;
overflow: hidden;
/* IE 6/7 fallback */
*text-indent: -9999px;
}

.ir:before {
content: "";
display: block;
width: 0;
height: 100%;
}
[/code]

  • Moved up above the /* Author’s custom styles */ – so that styles of the main selector will be cascaded
  • Added display:block since most of my selectors are intentionally diplayed as a block element

Set and reset

[code lang=”css”]
/*=========================Reset=========================*/
h1, h2, h3, h4, h5, h6, p, ul, ol, li {margin:0; padding:0;}

ul {list-style:none;}

/*=========================Set=========================*/
p {margin-bottom:1em;}
p:last-child {margin-bottom:0;}
[/code]

Resetting all basic text tags and setting the margin for <p> to bottom.

Clearfix inside a wide viewport media query

[code lang=”css” highlight=”1,17-34″]
@media only screen and (min-width: 1024px) {
/* Style adjustments for viewports that meet the condition */

/*
* Clearfix: contain floats
*
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* `contenteditable` attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that receive the `clearfix` class.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/

.clearfix:before,
.clearfix:after {
content: " "; /* 1 */
display: table; /* 2 */
}

.clearfix:after {
clear: both;
}

/*
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/

.clearfix {
*zoom: 1;
}
}
[/code]

I changed the media query from em to px because I am targeting viewports with exact dimensions.

Clearfix which solves floating problems are placed inside this media query because for narrow viewports, I don’t plan to use floats.

Show .assistive-text only to screenreaders

[code lang=”css”]
/*
* Hide only visually, but have it available for screenreaders: h5bp.com/v
*/

.visuallyhidden,
legend,
.assistive-text {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

/*
* Extends the .visuallyhidden class to allow the element to be focusable
* when navigated to via the keyboard: h5bp.com/p
*/

.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus,
.assistive-text:active,
.assistive-text:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
}
[/code]

Update – Nov 13, 2012:

  • I added legend to .visuallyhidden class selector since I don’t need that label much

Update – Nov 14, 2012:

  • Removed list-style of <ul>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *