Hi I have a simple question about css when i design a wesbite i never use css unless i want to use a dynamic script however i see some site use css for everything! for example the background of the page, font text and size, etc is all done with css (by attaching a css file with that info) i usually just add that info right in the body section by putting this for example: <body background="pics/bckgrnd.gif"> some sites use a styles.css file listed in it: body { background-image:url(pics/bckgrnd.gif); my question is why use css when you can just place that info in the body directly?
Whene you do this, if you want to edit for example the background image, you must edit all pages on your website, but if you have an external css file, you will edit just one time .
Because presentation has NO BUSINESS in HTML! What do dynamic scripts have to do with CSS? You don't seem to have grasped the point of HTML and internet. I suggest you to format the part of the brain that memorized all about it, and start fresh.
CSS is what styles HTML, they go hand in hand. While you could add the background image directly into the body, what if you want to float something left or right? position it relatively or absolute? move it around? that's where CSS comes in.
1) I think I'm rubbing off on wiicker95 too much.... 2) Both responses so far are sane and correct... I'm shocked. The reasons are pretty simple -- 1) As mentioned you can edit multiple pages background from one file. 2) If multiple pages are sharing that one CSS file, you are using less bandwidth since you'd have less markup and only be declaring it in one place -- one of the entire reasons for using CSS in the first place! 3) If you are using CSS properly by having multiple media targets through the LINK tag -- possibly with media queries, you can save yourself and visitors the aggravation of having things like backgrounds that have no business wasting bandwidth (or even ink) on those targets. Sending your screen background (or even your background+text colors) to print for example is just going to piss people off. You might have a massively idiotic background image that doesn't work right on mobile or small screens. Think about it -- if you have five pages on a site ALL using that same background, which way is going to use less bandwidth, load faster, and be easier to maintain? The one where it's declared on BODY inside every single page, or the one where it's declared once and loaded once in a file that's cached across pages? This is why presentation has no business in the HTML after 1997, this is why good developers advocate development techniques like separation of presentation from content and progressive enhancement, and is a significant portion of sane rational site development. It's also why presentational markup and tags have been invalid since 1998 unless like many lemmings you've been sleazing out HTML 3.2 (which it sounds like you are) and until recently were just slapping 4 tranny on it. (and now slap 5's lip service around the same outdated/half-assed coding methodologies)... going hand in hand with all the other sleazy half-assed web development techniques like fixed width layout, px metric fonts on content, color contrasts that ignore accessibility norms, and thinking "what it looks like on my screen" when writing the markup instead of asking yourself "what IS this structurally?" Because if you are thinking "what it's going to look like" when choosing your markup, you are choosing your tags and attributes for ALL the wrong reasons. This is why the design and development methodology REAL professionals advocate does not involve pissing out some goofy scam artist PSD to start with, and instead involves semantically marking up the content or a reasonable facsimile, designing the layoutS (yes, plural -- there should be more than one thanks to media targets and responsive design) with CSS, then and only then bringing in the PSD jockey to spank it on the display to make it 'pretty' -- and with the increases in what can be done thanks to CSS3, the need for the "artists" sleazing out pictures as layouts or even part of a layout is rapidly coming to an end. ... all in all, being why if you've been using the REAL HTML 4 instead of being 'in transition from 1997 to 1998 practices", the BACKGROUND, COLOR and BGCOLOR attributes have been invalid markup/deprecated just like the idiotic FONT and CENTER tags. (and why I think HTML 5's "ASIDE" is 100% grade A farm fresh prairie pies) Honestly if you've been writing websites for less than fifteen years at this point, you probably shouldn't even know there IS a background attribute for BODY, unless you've been learning from really bad sources how to do things. Unfortunately there are a LOT of really bad sources out there.
ok i understand the difference now be nice guys im no pro, design sites just for fun the first time i learned to design was using microsoft frontpage about 12 years ago, and frontpage just places that info right in the body so i just learned it that way instead of using css for that
Hideathshadow, yes your thought is correct and i like your explanation. It is help to learn what is the use of css. Thanks,