tags:

views:

81

answers:

3

I want to position this HTML snippet

<div id="D1">
  <div id="D1.1">HeaderText</div>
  <div id="D1.2"> From
    <input id="from" name="from" value=""/>
  </div>
  <div id="D1.3"> To
    <input id="To" name="To" value=""/>
  </div>
</div>

this way

+-(D1)-------------------------------------------------------------------------+
|+-(D1.1)---------------------------++-(D1.2)-------------++-(D1.3)-----------+|
||                                  ||    +-(from)-------+||  +-(to)---------+||
|| HeaderText                       ||From|              |||To|              |||
||                                  ||    +--------------+||  +--------------+||
|+----------------------------------++--------------------++------------------+|
+------------------------------------------------------------------------------+

using CSS

Things I need:

  • D1.1 must be left aligned and D1.2 y D1.3 must take only the space they need and must be right aligned.
  • Even though I represented here the width of D1.1 to take all the remaining horizontal space, it's not required to do that.
  • D1 should grow vertically to contain D1.1, D1.2, D1.3 completely. (No overflow, all divs completely visible)
  • The design must be fluid (i.e. if I change the font sizes of the text inside the divs, the layout adjust itself accordingly.

Is it possible to do all of this using only CSS and no tables? How?

+1  A: 

Layout Gala is a pretty good reference for CSS based layouts.

You might want to take a look at this layout, or possibly this layout since they both look roughly like what you're asking for.

Good luck, and hope this helps some.

Chris
Wow, nice one. Let me see it in detail.
Yanko Hernández Alvarez
+3  A: 

Yanko,

Your ID names have periods in them and that'll be a problem in CSS since period is reserved. Best thing is to not use reserved characters in names but if you must have them, then you have to escape the periods with a backward slash. Markup can stay as is.

Here is the CSS:

#D1 {
  background-color: gold;
  padding: 10px;
  overflow: auto;
}
#D1\.1 , #D1\.2 , #D1\.3 {
   float: left;
   padding: 10px; 
}

If you need help understanding overflow property, here's a tutorial that discusses it.

===

websea
It was pseudo-html. The periods was to make clear the hierarchical relation of the divs in the diagram.
Yanko Hernández Alvarez
I tested it and then it hit me!!! I'm so sorry. I meant D1.2 and D1.3 RIGHT aligned. Will fix it now! My bad
Yanko Hernández Alvarez
I did the obvious thing and separated the styling of D1.1 from the rest of the siblings, and right floated D1.2 and D1.3. but them switched places. How do I fix this without knowing the widths?
Yanko Hernández Alvarez
In that case, float d1.2 and d1.3 to the right but since order is important, modify your markup as shown below.
websea
A: 
#D1 {
  background-color: gold;
  padding: 10px;
  overflow: auto;
}
#D1\.1  {
   float: left;
   padding: 10px; 
}

#D1\.2 , #D1\.3 {
   float: right;
   padding: 10px; 
}

</style>

</head>
<body>


<div id="D1">
  <div id="D1.1">HeaderText</div>

  <div id="D1.3"> To
    <input id="To" name="To" value=""/>
  </div>
    <div id="D1.2"> From
    <input id="from" name="from" value=""/>
  </div>
</div>

</body>
</html>
websea