Recently, I have built some of the websites from church and friends via Wordpress, a popular blogging/ CMS system. Being very impressed by the quality of the themes and rich plug-ins, I decide to take a step further to learn about the Wordpress programming model. I can do that via writing my simple Hello world plugin. However, it doesn't allow me to grasp the full power of Wordpress framework. So, I decide to study about a sophisticated Wordpress theme and find out how it integrated with Wordpress and leveraged its plug-ins. To do that, I need to ramp up CSS, PHP in few days. This article is the quick note that summarized what I have learnt about CSS. Hope it is helpful to you as well.
Class and ID Selector
/* The difference between an ID and a class is that an ID can be used to identify
one element, whereas a class can be used to identify more than one. */
/* class selector */
.intro
/* id selector*/
#top
/* built-in html element (no need to put symbol) */
p
/* locate specific element – paragraph with class=jam
(for example <p class=jam>xxx</p>) */
p.jam {xxxx}
/* apply grouping */
h2, .thisClass, .thatClass {…}
/* nested selector */
#top{…}
#top h1{…}
/* state of an element (ex. link) */
a.snowman:link
a.snowman:visited
a.snowman:active
a.snowman:hover
/* shorthand : margin, padding, border-width where th
p {
border-top-width: 1px;
border-right-width: 5px;
border-bottom-width: 10px;
border-left-width: 20px;
}
//can be
p {
border-width: 1px 5px 10px 20px;
}
//border-width, border-color and border-style shorthand
p {
border: 1px red solid;
}
margin: 1em 10em; // top/bottom = 1em, left/right = 10em
//background-color, background-image, background-repeat, background-position
body {
background: white url(http://www.htmldog.com/images/bg.gif) no-repeat top right;
}
Box Model
All html tags/ elements in html can be think of within its own box/ container. And it can be aligned on the screen in accordance with the CSS box model. Here is the box model in diagram:

I keep forgetting where is margin and padding. So, I use the word "MBP" to help me out where M=margin, B=border, P=padding.
At the first glance, it is all about spacing between an element and its neighbors. However, when I see how creative people leverage negative margin. I think it is good to write about it. For margin like "margin: 0px -30px 0px 0px;",
Display Flow
Once you understand how the spacing of an element, you need to under the display flow. Block element (div, p, h1) will display in an newline while Inline element (span, a, img) will display without open up an newline. You can take an element out from its flow via explicitly setting its display properties: inline, block and none. "none" here means not showing it at all. The difference between "display:none" and "visibility:hidden" is "display:none" will take the element out from the flow, so it will not leave an empty space on screen. For example when you want to print an article, you want to just print its content. So, you will do:
#navigation, #seeAlso, #comments, #standards {
display: none;
}
To take an element out from the display flow but still showing it, there are 2 common ways:
- Floating
- Positioning
I will cover these in the layout section.
Layout
margin: -30px 0 15px 0; (clockwise: top, right, bottom, left)
Imagine margin is like a photo white border that make your photo bigger in size and it is often enforced.
So, if a photo has margin inside a div like "right 50" and it is
floating right as well. Because external container doesn't moved by internal element, margin-right 50
will push the photo leftward by 50px instead. And -ve margin here will do the opposite.
When static element (ie. no float) is given a -ve margin on top, left, it pulls the element in that specified direction.
But for bottom and left, it doesn't move but move the content surrounding towards it (ie. overlap with it).
Possibility:
(1) use list to build a table
(2) Overlap to add emphasis
(3) Smashing 3D effect for Bevel text
(4) Layout – Flexible Document Structure
Using negative margins with floats sometimes pisses off older browsers. Some symptoms include:
* Making links unclickable
* Text becomes difficult to select
* Tabbing any links disappears when you lose focus
Solution: Just add position:relative and it works!
Layout
Positioning
position has 4 options: absolute, relative, static and fixed
- absolute will take the element out from the flow and use top, left, buttom and left coordinate to locate it
- fixed did the same as absolute but it will not move even u scroll the browser.
Floating
floating an element will shift it to the right or left of a line, with surrounding content flowing around it. If you don't want the next element to wrap around the floating object, you can apply the clear property like: clear:left, clear:right and clear:both
@ Rules
/* attach a set of css to another css file */
@import url(xyz.css);
/* apply its content to a specified media (ex. all, aural, handheld, print,
projection, screen): IE just takes all, screen, print */
@media print{
body {xxxx}
…
}
/* embedded external font (not all browser supports it) */
@font-face {
font-family: somerandomfontname;
src: url(somefont.eot);
font-weight: bold;
}
p {
font-family: somerandomfontname;
font-weight: bold;
}
Reference
ref: http://www.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/
ref: http://www.htmldog.com/guides/cssbeginner/
ref: http://www.htmldog.com/reference/cssproperties/
http://devzone.zend.com/article/627