tags:

views:

1064

answers:

9

I am reading an ASP.NET book and it refers to CSS files and talks about pixels. But I never understood it from a resolution, layout, etc. point of view. For example, what does the following mean in CSS file definition?

#header
{
    padding: 0px;
    margin: 0px;
}
+2  A: 

A pixel is a single dot on the screen. Your example sets the element named header with no padding or margin. To understand this you'll also need to understand the CSS box model for page layout.

tvanfosson
+6  A: 

It means a dimension, measured in pixels on-screen. E.g.

width: 200px;

means an element is 200 pixels wide.

A pixel is a "PICture ELement", meaning one coloured dot on the screen, probably much like the period at the end of this sentence.

Fritz H
A: 

For more info: What is a pixel?

Adnan
+20  A: 
CMS
+1  A: 

A pixel is a unit of measurement, at least, in regards to CSS. There is also pt, em, percentage... there are a few others. Each have their strengths.

W3schools is chock full of references, check the one on CSS.

I recommend downloading Firebug and experiment with changing the pixel width/height.

Chuck Conway
A: 

I named my cat Pixel

Kris
Pix or it didn't happen.
Patrick McElhaney
A: 

As stated by others, a pixel is simply a measurable unit that relates directly to the electronic display of data - a single pixel is the smallest an object on screen can be. The greater the screen resolution, the more pixels it can represent.

A note on the example given - a value of 0px is actually unnecessary as a zero value, and is better represented in CSS as just a 0 (it could equally be 0% or 0em, they all mean the same).

BrynJ
+5  A: 

"A pixel is not a little square" is a good discussion on what a pixel is.

It might not be relevant to your specific question, but if anyone else finds this thread for a computer graphics related problem, this is great reading.

Laserallan
Loved the link. Thanks. :-)
Tomek Szpakowicz
Great that someone enjoyed it!When the topic of the post was changed it was even more off topic than when I wrote it :)
Laserallan
That link is broken, but it is here now: http://alvyray.com/memos/6_pixel.pdf [Summary: A pixel is not a little square, nor a little rectangle; it's a *point* sample.]
ShreevatsaR
Thanks for pointing it out. Corrected the link in the post too.
Laserallan
+6  A: 

This is a little beyond where you might be at the moment, but a CSS pixel is not necessarily exactly the same size as a single pixel on your display. According to the spec:

If the pixel density of the output device is very different from that of a typical computer display, the user agent should rescale pixel values. It is recommended that the reference pixel be the visual angle of one pixel on a device with a pixel density of 96dpi and a distance from the reader of an arm's length.

So if you have one of those incredibly expensive extra-high-resolution displays that doesn't count as “typical”, the browser and/or OS may choose to redefine what a “pixel” is.

The useful definition for a ‘px’ as far as CSS authoring is concerned is: a ‘px’ is the quantity of length equal to the pixel in an unscaled HTML <img> or CSS ‘background-image’.

bobince
Thanks bobince. This question needs two answers: the basic explanation (provided by CMS and others) that most readers are interested in, and the technical answer explaining that a pixel is a relative (not absolute) unit, and that CSS pixels are not necessarily the same as device pixels.
David Kolar