Solved

Vertically centered element

Posted on 2006-06-26
6
299 Views
Last Modified: 2013-11-19
I am not sure if this is possible.

How do you position an element, lets say a table, vertically centered on a page?  No scrollbars.
0
Comment
Question by:rodmjay
  • 2
6 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 168 total points
ID: 16988601
Hi,

For the body element, add the "vertical-align" style..

<body style="vertical-align: middle">
...


---
Harish
0
 
LVL 7

Assisted Solution

by:maUru
maUru earned 166 total points
ID: 16988632
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16988652
maUru, good point !

rodmjay, refering to the link sent by maUru, the style should be

<body style="display:table-cell; vertical-align: middle">

0
 
LVL 10

Assisted Solution

by:jagadeesh_motamarri
jagadeesh_motamarri earned 166 total points
ID: 16989420
Well.......here is a post that i've answer earlier this month. It was accecpted.....Take a look at this ... http://www.experts-exchange.com/Web/Web_Languages/CSS/Q_21888464.html

......................Same thing copied here...............
Hi digitalpacman,

Here is a nice article on what you are looking for. Don;t forget to see the examples which contains your solutions

URL: http://www.badboy.ro/articles/2005-02-20/index.php

I wouldn't mind copying the code for you.

Here it goes:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Middle align test - multiple lines</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="Lucian Slatineanu, http://www.badboy.ro/" />
<style type="text/css" media="screen">
<!--
p {
     margin:0;
     padding:0;
}
#wrapper {
     width:550px;
     border:1px solid #666;
     padding:10px;
     height:300px;
}
#fixed {
     float:right;
     width:200px;
     height:300px;
     background:#666;
     display:block;
}
#wrapper>#floating { /*display:table for Mozilla & Opera*/
     display:table;
     position:static;
}
#floating { /*for IE*/
     width:300px;
     height:100%;
     background:#EAEAEA;
     position:relative;
}
#floating div { /*for IE*/
     position:absolute;
     top:50%;
}
#floating>div { /*for Mozilla and Opera*/
     display:table-cell;
     vertical-align:middle;
     position:static;
}
#floating div div {
     position:relative;
     top:-50%;
}
-->
</style>
</head>

<body>
<div id="wrapper">
     <img src="0.gif" alt="stuff" id="fixed" />
     <div id="floating"><div><div>

          <p>Middle aligned text goes right here and it does wrap nicely at the end of the line</p>
     </div></div></div>
</div>
</body>
</html>


______Jags.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now