Kompx.com or Compmiscellanea.com

CSS for a range of elements

Windows : Internet Explorer 9.0+, Firefox 1.5+, Google Chrome, Opera 9.5+, Safari 3.1+, SeaMonkey 1.0+.

Linux : Firefox 1.5+, Google Chrome / Chromium, Opera 9.5+, SeaMonkey 1.0+.

Styling a range of elements. Here from the 1st to the 3rd one - changing background color. Example:

 
 
 
 

HTML / XHTML. Code:

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>&nbsp;</div>

CSS. Code:

div:nth-of-type(-n+3) {background: #f66;}

/* Extra CSS, just styling the look: */

div {width: 100%; margin-top: 5px; background: #066;}

Note: nth-child may also be used instead.


Aliosque subditos et thema

 

CSS centering image

 

CSS horizontal centering of an image. Example: HTML / XHTML. Code: <div class="example"> <img src="image.jpg" alt="Image" /> </div> CSS. Code: .example {position: relative; left: 0px; top: 0px; height: auto; width: 100%; float: left; padding: 10px; border: 1px #ccc solid; background: #fafafa;} .example img {display: block; margin: 0 auto;} CSS properties of a container (here it is example) may vary, image centering is achieved by styles applied to the image itself: .example img {display: block; margin: 0 auto;}. [ 1 ] As well as Opera 4.0+, if shorthand CSS is not used in styles. That is, if it is .example img {display: block; margin-left: auto; margin-right: auto;}. [ 2 ] As well as Netscape 6.01+, Mozilla 0.6+. [ 3 ] As well as Netscape 6.01+, Mozilla 0.6+.

Non-breaking space ( &nbsp; ) in :before and :after content

 

Non-breaking space ( &nbsp; ) in :before and :after pseudo-elements. Hex code ( \00a0 ) is used in the content property instead of the named character entity ( &nbsp; ). Example: ABC HTML / XHTML. Code: <div>ABC</div> CSS. Code: div:before {content:"\00a0";} div:after {content:"\00a0";} /* Extra CSS to make non-breaking spaces more obvious here: */ div:before {height: 1em; width: 1em; display: inline-block; background: #f00;} div:after {height: 1em; width: 1em; display: inline-block; background: #00f;} [ 1 ] As well as Netscape 6.01+, Mozilla 0.6+. [ 2 ] As well as Netscape 6.01+, Mozilla 0.6+.