Colorizing with CSS

You have seen how CSS can set the color of text, but did you know that you can set background colors and images, too?  With CSS, you can place an image behind any element on the page. This page has a background image.  This is the rule:

body

{ background-image: url(images/flwr.jpg); background-repeat: no-repeat; }

When setting a background image, you have four options;

  • repeat:  The image is repeated both horizontally and vertically.
  • repeat-x:  The image is repeated horizontally only.
  • repeat-y:  The image is repeated vertically only.
  • no-repeat:  The image is not repeated: only one copy of the image is drawn.
You can also center it, however it will be centered as the  background of the entire document, not centered on the screenful:

BODY {background: #FFFFFF url(images/flwr.jpg) no-repeat center} 

Here we have chosen no-repeat, so the image will only be shown once.  When you specify a background image, it's a good idea to also specify a background color using the background-color property. This solid color will appear while the image loads, and will show through any transparent regions of the image. It will also be the color shown in the background of browsers such as IE3 that do not support the background image STYLE.  You can also specify a background image for just a paragraph or a table, but Netscape and IE4 for Macs doesn't support this well. 

How do you put a color behind a paragraph?  Using an inline STYLE.  You can use any of the values shown below: color names, hex numbers, or RGB values.  Here we have used both #ffff66 and yellow.  

You don't have to color the background of an entire paragraph. You can put color behind just one word if you want.  Here is what the code looks like:

<p style="BACKGROUND-COLOR: #ffff66">How do you put a color behind a paragraph?&nbsp; Using an inline STYLE. &nbsp;&nbsp;You can use any of the values shown below: color names, hex numbers, or RGB values. &nbsp;&nbsp;Here we have used both #ffff66 and yellow.</p>

<p>You don't have to color the background of an entire paragraph. You can put color behind just one <span style="BACKGROUND-COLOR: yellow">word</span> if you want.&nbsp; Here is what the HTML code looks like:

What's with the dog?  That's Daisy!  She is taking the place of a round bullet on this page because of this line in the css:

ul {list-style-image: url("images/daisy.gif")}

What is SPAN?  SPAN is used to identify a group of text so you can apply an inline STYLE.  

Notice the color definitions we used this time.  The standard 16 colors defined in HTML 3.2 and 4.01 and correspond to the basic VGA set on PCs.   Decimal R,G,B sets the value for Red, Green and Blue in each color.  (Need more colors?  Click here for a really pretty chart.)  They are: 

Color HEX HTML Decimal RGB   Color HEX HTML Decimal RGB
black #000000 0,0,0   yellow #FFFF00" 255,255,0
white #FFFFFF 225,255,255   lime #00FF00 0,255,0
green #008000 0, 128, 0   aqua #00FFFF 0,255,255
maroon #800000 128,0,0   fuchia #FF00FF 255,0,255
olive #808000 128,128,0   silver #C0C0C0 192,192,192
navy #000080 0, 0, 128   red #FF0000 255,0,0
purple #800080 128,0,128   blue #0000FF 0,0,255
gray #808080 128,128,128   teal #008080 0,128,128

There are more than 16 named colors.  Here are some others:

Snow
#FFFAFA
GhostWhite
#F8F8FF
WhiteSmoke
#F5F5F5
Gainsboro
#DCDCDC
FloralWhite
#FFFAF0
OldLace
#FDF5E6
Linen
#FAF0E6
AntiqueWhite
#FAEBD7
PapayaWhip
#FFEFD5
BlanchedAlmond
#FFEBCD
Bisque
#FFFAF0
PeachPuff
#FFDAB9
NavajoWhite
#FFDEAD
Moccasin
#FFE4B5
Cornsilk
#FFF8DC
Ivory
#FFFFF0
LemonChiffon
#FFFACD
Seashell
#FFF5EE
Honeydew
#F0FFF0
MintCream
#F5FFFA
Azure
#F0FFFF
AliceBlue
#F0F8FF
lavender
#E6E6FA
LavenderBlush
#FFF0F5
MistyRose
#FFE4E1
White
#FFFFFF
Black
#000000
DarkSlateGray
#2F4F4F
LightSlateGray
#778899
Grey
#BEBEBE
LightGray
#D3D3D3
MidnightBlue
#191970
CornflowerBlue
#6495ED
DarkSlateBlue
#483D8B
SlateBlue
#6A5ACD
MediumSlateBlue
#7B68EE
LightSlateBlue
#8470FF
NavyBlue
#000080
DimGrey
#696969
SlateGrey
#708090
MediumBlue
#0000CD
RoyalBlue
#4169E1
Blue
#0000FF
DodgerBlue
#1E90FF
DeepSkyBlue
#00BFFF
SkyBlue
#87CEEB
LightSkyBlue
#87CEFA
SteelBlue
#4682B4
LightSteelBlue
#B0C4DE
LightBlue
#ADD8E6
PowderBlue
#B0E0E6
PaleTurquoise
#AFEEEE
DarkTurquoise
#00CED1
MediumTurquoise
#48D1CC
Turquoise
#40E0D0
Cyan
#00FFFF
LightCyan
#E0FFFF
CadetBlue
#5F9EA0
MediumAquamarine
#66CDAA
Aquamarine
#7FFFD4
DarkGreen
#006400
DarkOliveGreen
#556B2F
DarkSeaGreen
#8FBC8F
SeaGreen
#2E8B57
MediumSeaGreen
#3CB371
LightSeaGreen
#20B2AA
PaleGreen
#98FB98
SpringGreen
#00FF7F
LawnGreen
#7CFC00
Green
#00FF00
Chartreuse
#7FFF00
MedSpringGreen
#00FA9A
GreenYellow
#ADFF2F
LimeGreen
#32CD32
YellowGreen
#9ACD32
ForestGreen
#228B22
OliveDrab
#6B8E23
DarkKhaki
#BDB76B
PaleGoldenrod
#EEE8AA
LtGoldenrodYello
#FAFAD2
LightYellow
#FFFFE0
Yellow
#FFFF00
Gold
#FFD700
LightGoldenrod
#EEDD82
Goldenrod
#DAA520
DarkGoldenrod
#B8860B
RosyBrown
#BC8F8F
IndianRed
#CD5C5C
SaddleBrown
#8B4513
Sienna
#A0522D
Peru
#CD853F
Burlywood
#DEB887
Beige
#F5F5DC
Wheat
#F5DEB3
SandyBrown
#F4A460
Tan
#D2B48C
Chocolate
#D2691E
Firebrick
#B22222
Brown
#A52A2A
DarkSalmon
#E9967A
Salmon
#FA8072
LightSalmon
#FFA07A
Orange
#FFA500
DarkOrange
#FF8C00
Coral
#FF7F50
LightCoral
#F08080
Tomato
#FF6347
OrangeRed
#FF4500
Red
#FF0000
HotPink
#FF69B4
DeepPink
#FF1493
Pink
#FFC0CB
MediumVioletRed
#C71585
VioletRed
#D02090
Magenta
#FF00FF
Violet
#EE82EE
Plum
#DDA0DD
LightPink
#FFB6C1
PaleVioletRed
#DB7093
Maroon
#B03060
Orchid
#DA70D6
MediumOrchid
#BA55D3
DarkOrchid
#9932CC
DarkViolet
#9400D3
BlueViolet
#8A2BE2
Purple
#A020F0
MediumPurple
#9370DB
Thistle
#D8BFD8

To convert your color choice to RGB, use this chart.

Style Conflicts

Stylesheet rules are inherited from "parent" to "child." Let's say you have established this rule:

B { color: blue }

This rule tells the browser that all text within <B> should be blue. But what does the browser do in the following situation?

<B>text<I>text</I>text</B>

Since you have not established a rule for the <I> tag, it inherits the <B> tags rule as it is enclosed within the <B> tags. Therefore, it displays in blue.  But what if you had established this rule: 

B { color: blue }

I { font-weight: bold }

Since the <I> tag is within the <B> tags, the text will inherit the { color: blue} rule.  You might think the I { font-weight: bold } rule would conflict with the inherited <B> rule, but most browsers will attempt to accommodate the style rule by making the italic text even more bold. 

If you are using percentages for text sizes, keep in mind that they are inherited. For example, if you have set the rule

{ p class="60%font"}

A { font-size : 60%;}

and you include a hyperlink within <p></p> tags, your hyperlink will be 60% of 60%!  Therefore, it is best to set hyperlink font -size as 100%.  

More Style Stuff

 

Copyright ©PhoebeMoon Web Design Solutions