Jump to content

how do i center everything on the page and inside the divs ?


jasonc

Recommended Posts

I have been playing around with the code and just can not get this image to be in the center of the page.

 

How do I do this correctly?

 

<!DOCTYPE HTML>
<html>
<head>

<title>.........</title>

</head>

<body bgcolor="641416" link="#000000" vlink="#000000" alink="#000000" onload="switchAd(this);">

<div style="width: 760px; align: center;"><img src="images/header4.jpg" alt=""></div>



</body>
</html>

Link to comment
Share on other sites

There is no need to declare a width and a margin:auto for the div. Just text-align:center will do. See How to Center in CSS

 

there is a need to declare a margin:0 auto; because he wants the div to be at the center of the website. where the width is consent, its probably something to do with the rest of the code, you can predict he don't need it unless you read the whole code.

Link to comment
Share on other sites

now this is strange i can not get the image to be in the style, the image does not show up.

 

re the rest of my code, there is no other code yet i am redoing a tabled page from scratch so adding in the parts bit by bit.

 

 

<!DOCTYPE HTML>
<html>
<head>

<title>.........</title>

</head>

<body bgcolor="641416" link="#000000" vlink="#000000" alink="#000000" onload="switchAd(this);">

<div style="width: 100%; text-align:center; margin:0 auto; background-image: url("images/header4.jpg"); background-repeat: no-repeat;"></div>








</body>
</html>

Link to comment
Share on other sites

you must have some contents in the div for the background image to show up.

<div style="width: 100%; text-align:center; margin:0 auto; background-image: url(images/header4.jpg); background-repeat: no-repeat;"></div>

 

or you can set a minimum height to the same height as the image

 

<div style="width: 100%; text-align:center; margin:0 auto; background-image: url(images/header4.jpg); background-repeat: no-repeat;min-height:100px;"></div>

Link to comment
Share on other sites

there is currently no parent div, probably won't be.

 

the code i have given is the complete code to date and will be adding in the rest of the backgound images top to bottom and then having the text added over the top of the images.

 

this code send the image to the left of the page, not to the center?

 

<!DOCTYPE HTML>
<html>
<head>

<title>.........</title>

</head>

<body bgcolor="641416" link="#000000" vlink="#000000" alink="#000000" onload="switchAd(this);">

<div style="width: 100%; height: 192px; text-align:center; margin:0 auto; background-image: url("images/header4.jpg"); background-repeat: no-repeat;"> </div>

</body>
</html>

Link to comment
Share on other sites

ok added in the backgound image to be centered code and now the page is starting to look good apart from the gap between the top and bottom of all the images

<!DOCTYPE HTML>
<html>
<head>

<title>.........</title>

</head>

<body bgcolor="641416" link="#000000" vlink="#000000" alink="#000000" onload="switchAd(this);">

<div style="width: 100%; height: 100%; text-align:center; margin:0 auto;">
<div style="width: 100%; height: 192px; text-align:center; margin:0 auto; background-image: url("images/header4.jpg"); background-repeat: no-repeat; background-position:center;"></div>
<div style="width: 100%; height: 100px; text-align:center; margin:0 auto; background-image: url("images/navi.jpg"); background-repeat: no-repeat; background-position:center;">nav</div>
<div style="width: 100%; height: 100%; text-align:center; margin:0 auto; background-image: url("images/pgbackgrd.jpg"); background-repeat: repeat-y; background-position:center;">MAIN CONTENT, IMAGE NEEDS TO REPEAT DOWN PAGE.</div>
<div style="width: 100%; height: 100px; text-align:center; margin:0 auto; background-image: url("images/bottombanner.jpg"); background-repeat: no-repeat; background-position:center;"></div>
</div>


</body>
</html>

Link to comment
Share on other sites

there is a need to declare a margin:0 auto; because he wants the div to be at the center of the website.

I don't think so. This is all he asked:

I have been playing around with the code and just can not get this image to be in the center of the page.

How do I do this correctly?

Link to comment
Share on other sites

I don't think so. This is all he asked:

I have been playing around with the code and just can not get this image to be in the center of the page.

How do I do this correctly?

yes, but bear in mind, he is using a div with a static width from the code given. margin:0 auto; is thus required. he didn't state that he only wants it to be in the center of the div but instead, he wants it center of the page. debate is over bro.

Link to comment
Share on other sites

what my problem is now is that the text is jumping outside the divs.

 

<!DOCTYPE HTML>
<html>
<head>

<title>.........</title>
<style>
<!--
.header	{	width: 100%; height: 192px;		text-align: center; margin: 0; background: url(header4.jpg)			center top no-repeat; }
.nav	{	width: 100%; height: 100%;		text-align: center; margin: 0; background: url(navi.jpg)			center top no-repeat; }
.main	{	width: 100%; min-height: 100px;	text-align: center; margin: 0; background: url(pgbackgrd.jpg)		center top repeat-y; }
.footer	{	width: 100%; height: 100px;		text-align: center; margin: 0; background: url(bottombanner.jpg)	center top no-repeat; }
-->
</style>
</head>

<body bgcolor="641416" link="#000000" vlink="#000000" alink="#000000" onload="switchAd(this);">

<div style="width: 100%; height: 100%; text-align: center; margin: 0 auto;">
<div class="header"></div>
<div class="nav">nav</div>
<div class="main">MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT MAIN CONTENT v</div>
<div class="footer">f</div>
</div>


</body>
</html>

 

 

Link to comment
Share on other sites

re the debate....

 

I do want the div to be in the center.

I do want the images to be centered in the div and have the site container also centered.

The code I provided in the first post was the full code and I then added to it to ensure that the other images in the next set of divs also showed correctly.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.