I am new into CSS, HTML, PHP, ... Please explain me when exactly do we usually use CSS. I know exactly what CSS is, I just don't know how to combinate it with html. Do we use it to style every sentence or word which has different style or just bigger parts? 2. Do you usually provide alternative for those users who have browsers which don't support css or is this number of users to less to even care about it? Thanks
We use CSS to style the HTML elements. Its very useful and easy. If you don't have CSS always you have to write style rules for individual elements. When you write CSS rules you can write alternative rules for earlier browsers. Every modern browser supports CSS rules. Hope this helps you.
You use it as stated above but I think a simple example might help you more. If you have the .p-center defined as align =center, text font= whatever font-size= 11px along with all the other attributes you might add then when you construct your page you use <p class="p-center"> for your opening tag instead of using <p font= "veranda" align="center" size="11px" plus the rest>. The two greater values in my mind are the ability to define the divs and not using nested tables. Later after you have a hundred pages and want to change something like the text font you only need to change it in one file to change it on the 100 pages. I learned tables for layout and they are a bear to work with. Use tables for formatted data and divs for layout. Hope this helped.
Because CSS is supposed to be style, aka presentation, there are many good reasons for it's use: 1) Move all presenation OUT of your markup so your HTML can say what things are, NOT how they appear. This is called Semantic markup. Done properly it means there should be NO STYLE tags or attributes in your HTML. 2) Multiple elements that would have the same styling can all be grabbed from one declaration instead of multiple times - like a menu for example. This reduces the amount of code needed saving bandwidth and speeding render times. 3) When you move all presentation out of your markup you can make use of the caching model across multiple pages on the same site, saving bandwidth. 4) To allow a complete reskinning of any aspect of your site without having to go into your content - allowing changes of multiple lines to be done easily from one spot. Because one of the whole points of CSS is moving the presentation out of the markup, using presentational classnames also defeat the point. Colbyt's example of 'p-center' for example is IMHO a bad classname because it says how the element is going to appear, not what the element IS. What is it, what makes it special and worthy of having centering, a font change, etc, etc. You'll often see people doing code like this: <p class="center padTop big italic"> Completely misses the point of CSS. None of those say what the element is, it's just inlining presentation upon it. For all intents and purposes that's presentation in your markup, since if you decide to not center that element you have to go into the HTML and change it. If you have five paragraphs on the page you want to make that change to, you have to edit each one instead of changing one line in your CSS. In general both CSS and javascript are leveraged incorrectly by the majority of sites trying to use it. Pages are still chock full of presenational markup (those tags and attributes were deprecated in STRICT doctypes for a reason), inlined CSS (so no caching bonus), inlined Javascript (again not cached to the user), etc, etc. Markup is your content and what that content is. CSS is how it looks, and javascript on normal websites is for behaviors to ENHANCE (without replacing) functionality. Why so many people fail to grasp this churning out fat bloated rubbish is beyond me. Do a view source over at Yahoo some time if you want an example of this rubbish... 134k HTML file for 3k of page content? Also, check the three links in my signature - those are NOT adverts for products, but simply links to me ripping apart bad coding practices. Your second question plays to semantic markup. If you mark up your CONTENT paragraphs as paragraphs (don't just slap paragraphs around elements that are not content flow text), make proper use of heading tags (one h1 per page, if you drop priority is that lower title a subsection of the one before it? If not it should be the same or higher, not lower), make your lists as lists, you pretty much get for free what people with CSS turned off expect to get. It also makes it easier for search engines to index your page and for screen readers to deal with your content. Lowered bandwidth, faster page loads, easier to maintain, easier to reskin, and clarity of code - what's not to like?
Thank you for answers but I think you didn't read my questions. I said I know what is CSS, I just don't know if we used it for every single element. For example if you have all elements edited by CSS. Than you just need to add one single word on top the page. Do you edit that single word with CSS or not? Also what is about my second question? Thank you again
No CSS attribute assigned to an item it will inherit the page defaults set in the body portion or the browser default if no body declarations. Second question No I don't waste my time for 2% of the people using outdated software.
You use CSS to style whatever element you wish to style but you do not need to use it at all if you don't want or need to. Of course, the page will be plain and simple if you don't use it for anything but some people do, or use it in a minimalist way. So, one might set the font-family for a <p> but not change anything else at all. Others may have some styling for every element or only some of them. It's totally up to you.
Accidentally I do. Every page I create begins with HTML only. iow, I define the content first. So if you used a browser, such as Lynx, you could use my sites just fine. Styling/CSS is just coloring a color book, in a way. You know what the picture is without the colors but the colors can add something to it, but you don't need it.