[CSS] Div-Tag and Vertical Align

G

Guest

Hello,

I´ve a problem with a simple DIV Tag.

It looks like this:

div#border{
height: 600px;
left: 188px;
width: 410px;
vertical-align: middle;
border: solid 1px #526e86;
}



and the HTML-Page:

<html>
<head>
<link type="text/css" href="./css/styles2.css" rel="stylesheet">

</head>

<body>
<div id="border">bla</a>
</body>
</html>



I want the DIV Tag vertically centered, but it does not work.

What do I do wrong?



Regards,

Martin
 
D

dorayme

Martin Pöpping said:
I want the DIV Tag vertically centered, but it does not work.

Divs are 100% wide in relation to their containers (eg. body) by
default. So if you want one centred, you need to give it a width
smaller than the container in which you want it to appear but big
enough to hold the content that is inside it (this needs careful
though often). Then you need to instruct it to centre. This
usually works:

margin-left: auto;
margin-right: auto
 
D

dorayme

Martin Pöpping said:
I want the DIV Tag vertically centered, but it does not work.

oops... I misread... my last was about side to side centering. I
don't know anything about vertical anything, I never ever think
about vertical anything... it frightens me.
 
G

Guest

dorayme said:
Divs are 100% wide in relation to their containers (eg. body) by
default. So if you want one centred, you need to give it a width
smaller than the container in which you want it to appear but big
enough to hold the content that is inside it (this needs careful
though often). Then you need to instruct it to centre. This
usually works:

margin-left: auto;
margin-right: auto

Thanks for your hint!
I´m half ready now ;)

My code as smallest example looks like this:

<html>
<head>

<title>TEST</title>

<style type="text/css">
<!--
div#border{

height: 600px;
width: 410px;
vertical-align: middle;
text-align: center;
border: solid 1px #526e86;
margin: 0 auto;
}
-->
</style>

</head>

<body>
<div id="content">&nbsp;</a>
</body>

</html>



How can I center it horizontally?

E.g. I want it centered in the middle of the page like this:


--------------------------------------
| |
| |
| |---------| |
| | DIV | |
| |---------| |
| |
| |
|-------------------------------------|





Regards,

Martin
 
?

=?ISO-8859-15?Q?Martin_P=F6pping?=

dorayme said:
Divs are 100% wide in relation to their containers (eg. body) by
default. So if you want one centred, you need to give it a width
smaller than the container in which you want it to appear but big
enough to hold the content that is inside it (this needs careful
though often). Then you need to instruct it to centre. This
usually works:

margin-left: auto;
margin-right: auto


Thanks for your help!

I have combined working example now but it uses the table-tag.

Does anybody know a solution taking the same effects only with using div
and without using a table tag?


Regards,

Martin



<html>
<head>

<title>TEST</title>

<style type="text/css">

<!--

html,body {
margin: 0;
padding: 0;
}

table {
width: 100%;
height: 100%;
}

td {
vertical-align: middle;
text-align: center;
}

div#border{

height: 600px;
width: 410px;
vertical-align: middle;
text-align: center;
border: solid 1px #526e86;
margin: 0 auto;
}

div#container {
position: relative;
text-align: left;
margin-left: auto;
margin-right: auto;
width: 780px;
height: 432px;
border: solid 1px #526e86;
}
-->
</style>

</head>

<body>
<table>
<tr>
<td>
<div id="container">&nbsp;</a>
</td>
</tr>
</table>
</body>

</html>
 
D

dorayme

Martin Pöpping said:
Thanks for your hint!
I´m half ready now ;)

Will be able to look tomorrow... but have you tried applying the
above advice to height too?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top