473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Trying to make a background

67
As you may know from the title, I'm trying to make a background for my webpage. Problem is, I only want it to be in a certain area, not the whole thing, and the elements I have inside that area don't cover all the space I need backgrounded. How can I just create a little colored box in the middle of the page? I'm using javascript for the web page, but I assumed this was a more CSS-oriented problem.
Jul 24 '07 #1
1 1039
tburger
58
I would place a <div> with an id immediately inside the "body" tag of your HTML. Make sure that the <div> closes AFTER the last element you want included inside the box. From there, it's a simple matter of styling to your needs.

Example:

Your general HTML would look like this, with any more content place between the div tags.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.     <div id=box>
  4.           <p>Here is where you would fill in the content you want inside the box.</p>
  5.           ............
  6.     </div>
  7. </body>
  8. </html
  9.  
The necessary CSS looks something like this:

Expand|Select|Wrap|Line Numbers
  1. #box{
  2.     position: absolute;
  3.     height: xx;
  4.     width: xx;
  5.     background-color: xx;
  6.     border: xx (optional);
  7. }
  8.  
You can center a box using this general method:

1. Position the box absolutely.
2. Set the left: attribute to 50% (i.e left:50%;)
3. Make the left margin of the box the negative value of half it's width.

Let's say we have a box that is 100px wide. If we position it using left:50%, the left edge of the box will be in the middle of the browser window. This is obviously not centered because we want the middle of the box to be in the middle of the viewing area. To achieve this, we now take half of the box's width (50px;) , and set the box's left-margin to the negative of this value.

#thenameofyourid{
position:absolute;
left: 50%;
margin-left: -50px;
}

That should take care of you horizontally.

You can do the same thing vertically by setting top:50% and making the the top margin the negative value of half the box's height.

Hope this is clear, let me know about any questions

Tom
Jul 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul Schnitter | last post by:
Update: My custom control is based on the article "Creating Visual Basic .NET controls from scratch" in "Adventures in .NET" on MSDN. It is designed to be a replacement for the VB6 shape...
7
by: Paul Schnitter | last post by:
Update: My custom control is based on the article "Creating Visual Basic .NET controls from scratch" in "Adventures in .NET" on MSDN. It is designed to be a replacement for the VB6 shape...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: shady | last post by:
I am trying to create a a three column page with fixed size left and right columns and sretching middle one that uses left and right margins to give space to the left and right columns. It worked...
1
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.