Solved

have centered a page in html, but problems with background colour

Posted on 2013-01-22
4
233 Views
Last Modified: 2013-01-31
Hi,

Have an instance where I need to centre an html page on the screen, i.e. both horizontally and vertically. I have achieved this with the below container div. I know that my content is always 650px by 490px. #containerRTA is in my stylesheet and I apply it to a <div> that encapsulates everything in the <body> of my html page. Now with my content centred I want the whole html page to have a yellow background. I do not know how to achieve this. All I manage to do is set the actual background of just the content to yellow, not the margins. So my centred content is centred and the rest of the page is white.

Can anyone show me how to achieve this?



#containerRTA{
background-color: #FFFF00;
width: 650px;
height: 490px;
margin-left: -325px;
margin-top: -245px;
position: absolute;
top: 50%;
left: 50%;  
}
0
Comment
Question by:RupertA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
sivagnanam chandrakanth earned 250 total points
ID: 38805064
Try

body{
background-color: #FFFF00;
}
0
 

Author Comment

by:RupertA
ID: 38805135
that worked sivagnanam_c - will leave thread open in case anybody else wants to comment.
0
 
LVL 1

Assisted Solution

by:headshock
headshock earned 250 total points
ID: 38805384
<!DOCTYPE html>
<html>
<style>
#containerRTA{
width: 650px;
height: 490px;
border:solid 1px #000;
margin: 0 auto;

margin-top: 50%;

} 
body {background-color: #FFFF00;width:100%;height:100%;position:relative;}
</style>
<body>


<div id="containerRTA">
Your content goes here
</div>
</body>
</html>

Open in new window

adjust the margin-top till you have what you want!
0
 

Author Comment

by:RupertA
ID: 38838806
That also works. Thank you both very much. I will split points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question