views:

869

answers:

3
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        #t2
        {
            width: 87px;
            top: 49px;
            left: -566px;
        }
        #t1
        {
            width: 87px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 171px; width: 391px">
    <div id="Div2" style="position:absolute; top: 65px; left: 14px;">

        sdsdf<br />
        asfaesrestret<br />
        asf<br />
        asdfas<br />
        asdfaasdfasfsad<br />
        hhb<br />
        jh</div>
    <div id="t1" style="position:absolute; top: 65px; left: 111px;">
        yyyyyyyyyyyyy
    </div>
    <div id="Div1" 
        style="position: absolute; width: 87px;position:absolute; top: 168px; left: 12px;">
    xxxxxxxxxxxxxxx
    </div>
    </div>
   </form>
</body>
</html>

Hi, Im new to css, Please help me on how to increase the height dynamically on giving more data in Div2 ?? The height of main div also need to increased. I have set position to absolute, am not sure wat to give there to move the div as per increase in data on Div2. please suggest ?? Thanks in advance.

-Srini

A: 

I would suggest you to use a div wrapper for your two divs and to use percentages instead of fixed values for the height.

EDIT:

Do the following then:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        #t2
        {
            width: 87px;
            top: 49px;
            left: -566px;
        }
        #t1
        {
            width: 87px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 171px; width: 391px">
      <div id="wrapper" style="position:absolute;">
        <div id="Div2" style="top: 65px; left: 14px; background: red;">

          sdsdf<br />
          asfaesrestret<br />
          asf<br />
          asdfas<br />
          asdfaasdfasfsad<br />
          hhb<br />
          jh</div>
        <div id="t1" style="position:absolute; top: 65px; left: 111px;">
          yyyyyyyyyyyyy
        </div>
        <div id="Div1" 
             style="width: 87px;position:relative; top: 0px; left: 12px; background: green;">
          xxxxxxxxxxxxxxx
        </div>
      </div>
    </div>
   </form>
</body>
</html>

I set the background colors to the divs so you will see what I mean. Essentially, I added a wrapping div with position absolute. The Div1 and Div2 are now relative. The Div1 has a top:0 attribute, not to leave any gap with Div2.

Roberto Aloi
I want to move down the Div1 if data in given more on Div2. It should not override the Div1 content...as of now its overridding the Div1..Copy the above code and give more data inside div2, it will override the Div1..
Srinivasan K
A: 

You can use JavaScript to change Element properties dinamiclly For example document.getElementById("Div1").style.width= "900";

svlada
I want to move down the Div1 if data in given more on Div2. It should not override the Div1 content...as of now its overridding the Div1..Copy the above code and give more data inside div2, it will override the Div1..
Srinivasan K
So basically you want to change div position based on div content ?
svlada
A: 

Works crossbrowser replace the 100 for what you want to be the default height

min-height: 100px; height: auto !important; height: 100px;
Wieringen