Forum Moderators: not2easy

Message Too Old, No Replies

Having Trouble Changing Page Background Color

         

TonyS

8:35 pm on Nov 1, 2009 (gmt 0)

10+ Year Member



Hi Everyone,

I hope you all are having a good weekend. :-)
I am having a problem adding a page background color using the css folder file. I am by no means a coding exspert but I figure this should be a simple task. I need help. The code I added to my css only gave me a page border. Could someone please take a look at ths css and tell me what I need to do or code I need to add to change this page background color? It is the whole page bacground color I want to change not any cell within. Any and all help will be greatly appreciated.:-)
Thank You
Tony S.
[code]/* CSS Document */
body{
margin:0px;
}

.border{
border:#000000 1px solid;}

.naigation_text{
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #FFFFFF;
text-decoration:none;
}

.naigation_text:hover{
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #f7ae47;
text-decoration:none;
}

.latest_news{
background-image:url(../images/latest_news.jpg);
width:165px;
height:29px;
background-repeat:no-repeat;
padding-top:5px;
}

.left_simple_text{
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
color: #494646;
text-align:justify;
padding-left:14px;
padding-top:7px;
}

.copyright{
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
color: #000000;
}

.right_table2{
width:517px;
border-right:#000000 1px solid;
}

.right_simple_text{
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
color: #000000;
text-align:justify;
padding-right:13px;

padding-top:7px;
}

.more{
font-family: Arial, Helvetica, sans-serif;
color: #aa6626;
font-size: 11px;
font-weight: bold;
padding-left:5px;
text-decoration:underline;
}

.more :hover{
font-family: Arial, Helvetica, sans-serif;
color: #aa6626;
font-size: 11px;
font-weight: bold;
padding-left:5px;
text-decoration:none;
}

.right_middletable{

border-right:#000000 1px solid;
height:20px;

}

[code]

longen

8:40 pm on Nov 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try searching for "css background color" - the first result in Google has the code you need.

D_Blackwell

9:06 pm on Nov 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome TonyS.

.....a problem adding a page background color.....

1) This will provide the style requested.

html, body {
background-color: #fff;
}

2) .....only gave me a page border......
This indicates a likelihood of a 'wrapper' container that has the effect of 'seeming' to give a page border. No page border is directly declared. border: and background-color: are very different properties.

3) You can shorthand some color related declarations, such as #000000: to #000; and #ffffff to #fff - Lower case not required but 'best practice', IMO.

4) You can also shorthand the font: declarations. For example:

{font: bold 11px Arial, helvetica, sans-serif;}

Much more compact and easier to follow.

5) It is unlikely, unless there is a specificity issue to be over-ridden, that {text-decoration: none;} is needed in .naigation_text {

6) Is there a typ0 there? Did you intend .navigation_text ?

7) .more :hover { - is not valid and should not work. It does pass the W3C validator with a 'green' result - but it should not work. If the validation is correct, I would like further details, and appropriate usage.

swa66

10:01 pm on Nov 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Regarding
7) .more :hover { - is not valid and should not work
it is valid CSS! And if the elements that have the class "more" have any children, it should work when those children are hovered.

":hover" select all elements that are hovered, regardless of the elements, any class or any id applied to the element.
There is some language in the standards to not write it like ".foo :hover" in order to not confuse people reading the code (it suggests to use ".foo *:hover" which means exactly the same).

D_Blackwell

10:53 pm on Nov 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it is valid CSS!

I stand corrected regarding validity. What browsers/versions support this without hacking? FF 3.5.1 does not seem to. Opera does support for children.

Another option:
.more > :hover{

TonyS

11:01 pm on Nov 1, 2009 (gmt 0)

10+ Year Member



Hi I really want to thank you all for your response. As I said before I am just beginning to try to understand basic coding. I appreciate any and all help I can get from the more experienced coders in this forum. I thank you for your time, patience and willingness to help. I will use the info given here. Hopefully it will serve as a lesson that i may pass on. ;-)
One more question. Will it make a difference where I enter the above given code? I should ask where should I enter the code? Also should "#fff" be the hex code for the color
I want my background to be?

Thank You,
Tony S.

TonyS

11:40 pm on Nov 1, 2009 (gmt 0)

10+ Year Member



Hi,
I have added the code sugessted above to my page CSS. I also added the Hex code# for the color of my background. The thing is my background color remains "white" the oroginal color. Is ther something that would cause my backgroubng color uable to be changed? Here is alook at the code after I added the suggested code.
/* CSS Document */
html, body {
background-color: #7fffe7;
}
margin:0px;
}
.border{
border:#000000 1px solid;}

.naigation_text{
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #FFFFFF;
text-decoration:none;
}

.naigation_text:hover{
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #f7ae47;
text-decoration:none;
}

.latest_news{
background-image:url(../images/latest_news.jpg);
width:165px;
height:29px;
background-repeat:no-repeat;
padding-top:5px;
}

.left_simple_text{
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: normal;
color: #494646;
text-align:justify;
padding-left:14px;
padding-top:7px;
}

.copyright{
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
color: #000000;
}

.right_table2{
width:517px;
border-right:#000000 1px solid;
}

.right_simple_text{
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: normal;
color: #000000;
text-align:justify;
padding-right:13px;

padding-top:7px;
}

.more{
font-family: Arial, Helvetica, sans-serif;
color: #aa6626;
font-size: 13px;
font-weight: bold;
padding-left:5px;
text-decoration:underline;
}

.more :hover{
font-family: Arial, Helvetica, sans-serif;
color: #aa6626;
font-size: 13px;
font-weight: bold;
padding-left:5px;
text-decoration:none;
}

.right_middletable{

border-right:#000000 1px solid;
height:20px;

}

D_Blackwell

12:00 am on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most of the credit should go to swa66 who rightly jumped on my providing bad information.
............................

Will it make a difference where I enter the above given code? I should ask where should I enter the code?

Option 1: External style sheet. Advantage - It can be called from any page on your website and used on hundreds, or thousands, of pages - served from one file, one time. Link to the .css file in the head of each page that needs access to the declarations. The following link uses a relative path. You may well get advice that that is a stupid thing to do and that an absolute file path is far superior. Both have their place, IMO, and I use both.

<link rel="stylesheet" type="text/css" href="../../css/gallery.css" />

Option 2: Embedded in the page <head>
<style type="text/css" media="all">
body {
background-color: #faebd7;
}
</style>

Advantage - Some CSS is never going to be used anywhere but on a very specific page. Don't bog down your primary external stylesheet with declarations that rarely get used. Multiple stylesheets are a wise idea - a 'global' sheet that every page on the website uses, and 'template' stylesheets that different sections of the websites will use, e.g., one for gallery pages, one for article pages. Disadvantage - Embedded styles are only used on that one page. Need to use them in the future on another page? Oops! Thus, the advantage of using multiple external stylesheets.

Option 3: Declared 'inline', right in the HTMl.
<body style="background-color: red;"> Disadvantage - Extra markup on page. Advantage - Power.

External stylesheets are the most useful. Embedded stylesheets are more powerful and will take priority if there is a conflict. inline declarations are the most powerful of all and will over-ride any embedded and external conflicts.
............................

One has to be aware of the definition of 'power' for stylesheets. External .css files are incredibly powerful, but can be over-ridden. inline styles trump all, but the scope of the power is minimal.
............................

Also should "#fff" be the hex code for the color
I want my background to be?

No, not necessarily. That is a question only the designer can answer. There isn't a right or wrong answer. Most websites benefit from black text on a fairly light background. White is optional.

If you want white, there are numerous correct ways of making the declaration. White is one of the CSS official color names. You can also use hex codes and rgb codes,

For starters:

white (CSS 'official' color)
#ffffff
#fff (shorthand for above)
{
background-color: rgb(255, 255, 255);
}

Also - SVG named colors, rgba, hsl, hsla..... Some partly usable now; most CSS3, some who-knows-when, CSS3 or not.

TonyS

3:17 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



Thank you D_Blackwell, you have again came through giving me plenty of information to consider. it is not ony informitive but it will be helpful in my current project. As I posted just above I still have not managed to change the background color of my site page. :-( I am still open for any help you or anyone else here can offer. I thank you again for your response.

Thank You,
Tony S.

TonyS

10:09 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



Thank You all for all of your help I have with your help fixed my problem and now can change my page background color. I decided to use option 3 given to me by D_Blackwell: Option 3: Declared 'inline', right in the HTMl.
<body style="background-color: red;"> Disadvantage - Extra markup on page. Advantage - Power.

It worked like a champ. :-)

Thank you all again,
Tony S.