On 24 Aug, 03:31, pbd22 <dush...@gmail.comwrote:
I just want to know if it is possible to style a page
without using the class attribute?
Of course. Pages "get styled" pretty much by default, even if they
don't take any deliberate design action. Class just makes this more
flexible.
CSS can also be placed in style attributes on each element. It's
trivial to prove that:
* (Almost) any web page with a stylesheet can have it replaced by
style attributes.
* Any non-trivial page would require so much work to do this that it's
entirely impractical.
(Actually there's a couple of things you can't do without a
stylesheet, such as using selectors like :hover, or media-specific
CSS)
CSS in stylesheets attaches itself to the elements by the application
of "selectors". These can use various items to identify the relevant
HTML: element names, class values or id values being the most
obvious.
If you want all <pstyled the same, then just use the element name "p
{ }".
If you want one <p id="foo" to be different, you could use an id
"p#foo { }" (I'd still suggest class, but you certainly _could_ do
this).
If you want a recognisable set to be different, and the HTML structure
permits it, then you could use "div p { }" to identify only those <p>
that were inside a <div>.
If you want to address some set of <pthough, and none of the above
selectors are practical, then it's time to use a class. It's simple
to use and very flexible. You can even use it to hide the element type
such that ".warning {color: red;}" can be applied equally to <p
class="warning" or <h1 class="warning" >. It's a great tool for all
CSS use.
So why are you wondering if you can avoid it?