HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 28. STYLING WITH CSS 258


Acceptable Answer:no


Exam Question 374(p.359):If you draw a box around some content, what
CSS attribute puts space between the box and neighboring content?
Acceptable Answer:margin:


Exam Question 375(p.359): In CSS, can margin be negative?
Acceptable Answer:yes


Where To Specify Styling


Styling can be done on a per-element basis, a per-page basis, or a multi-page
basis. Appendix 34 (page 288) talks more about this.


The best practice is to do the styling at the level that matches how broadly
the style happens. Is it everywhere or just in exactly one spot?


If you want certain styles to apply across your whole website, or several
similar pages, they you should create anexternal style sheetand link to
it from each webpage. This is the most-recommended approach.


If your webpage is more personalized than the whole website, you would
use aninternal style sheet(or, stylesheet, written without the space)
specified in the head of your webpage. This would take precedence over
anything stated in the external style sheet.


For small areas of a webpage that need special styling, it is normal to do
in-line styling, using thestyle=attribute of HTML. But be careful. If you
are styling many things the same way, you should move the styling to your
style sheet, either the internal one or an external one, and then useclass=
to apply your styling.


28.1 In-line Style


When you use style= as an HTML parameter, it is called in-line styling,
and in case of conflict, it takes precedence over all other styling that might
have been requested.


If we want a particular h1 to use red text, we could do it like this:


This is a heading


Every HTML tag allows style= as a parameter.

Free download pdf