Welcome to Dream.In.Code
Become an Expert!

Join 149,607 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,896 people online right now. Registration is fast and FREE... Join Now!




Making one div Vertical align middle relative to other div

 
Reply to this topicStart new topic

Making one div Vertical align middle relative to other div, How to make first div vertically align middle relative to other Div

shruti2007
29 Sep, 2007 - 04:03 AM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 2


My Contributions
CODE
<html>
<head>
<title>CSS 2 COLUMn LAYOUT TUTORIAL</title>
<style type="text/css">

#container {
width:600px;

}

#left {
width:200px;
float:left;
Vertical-align:middle;

}
#main {
width:400px;
float:left;

}
</style>
</head>
<body>
<div id="container">
  
  <div id="left" style="background:yellow;float:left;text-align:center; ">

    this is the left column

  </div>
  <div id="main" style="background:blue;float:left;">
    this is right column<br/>
hello
hello
  </div>
</div>

</body>
</html>

User is offlineProfile CardPM
+Quote Post

devangnegandhi
RE: Making One Div Vertical Align Middle Relative To Other Div
29 Sep, 2007 - 08:15 PM
Post #2

New D.I.C Head
Group Icon

Joined: 23 Jan, 2006
Posts: 39


Dream Kudos: 100
My Contributions
i dont clearly get your question!!.....are you trying to make a 'T' like structure or am i getting it wrong??
User is offlineProfile CardPM
+Quote Post

shruti2007
RE: Making One Div Vertical Align Middle Relative To Other Div
29 Sep, 2007 - 08:31 PM
Post #3

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 2


My Contributions
QUOTE(devangnegandhi @ 29 Sep, 2007 - 09:15 PM) *

i dont clearly get your question!!.....are you trying to make a 'T' like structure or am i getting it wrong??




No Actually I want label in one div and text box with error message in another div.
When data will be incorrect error message going to be displayed.
That time label should be vertically align middle to textbox and error message
User is offlineProfile CardPM
+Quote Post

serializer
RE: Making One Div Vertical Align Middle Relative To Other Div
10 Oct, 2007 - 08:26 PM
Post #4

D.I.C Head
**

Joined: 25 Jun, 2007
Posts: 108


My Contributions
It's a really tricky one ... an approach you could try would be inline-block -- this isn't supported in Firefox however you can use the -moz-inline-box value:

CODE
<html>
<head>
<title>CSS 2 COLUMn LAYOUT TUTORIAL</title>
<style type="text/css">
#container {
width:600px;
vertical-align:middle;
}
#left,#main {
display:-moz-inline-box;
_display:inline-block;
}
#left {
width:200px;
}
#main {
width:400px;
}
</style>
</head>
<body>
<div id="container">
  
  <div id="left" style="background:yellow;float:left;text-align:center; ">

    this is the left column

  </div>
  <div id="main" style="background:blue;float:left;">
    this is right column<br/>
hello
hello
  </div>
</div>

</body>
</html>

[/quote]

Note the inline blocks/boxes/whatever the browsers want to call them, are very unpredictable! If you had a lot of stuff in your columns they might go very strange.

Also note the vertical-align attribute has to be on the outer container; it specifies how items sit on the line inside it, in this case we want them to middle align with each other smile.gif vertical align is quite confusing in this regard, and may even seem a little backward...

I've also used an _ underscore for implementing an IE-only hack, however there are better hacks available. I would normally put IE rules in a separate file using conditional comments, so I don't know any better hacks offhand smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:03AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month