Home  >  Article  >  Web Front-end  >  Child div height adapts to fixed parent div_html/css_WEB-ITnose

Child div height adapts to fixed parent div_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:26:011260browse

This post was last edited by linshigong2013 on 2013-12-25 16:30:31

aaaa076402276aae5dbec7f672f8f4e5cc81aaaa076402276aae5dbec7f672f8f4e5cc81 is dynamically changing div id=aaa height and width are fixed
I want to achieve that no matter how many aaaa076402276aae5dbec7f672f8f4e5cc81aaaa076402276aae5dbec7f672f8f4e5cc81 the height and width of the div id=bbb are automatically adapted
the excess part of the div id=bbb will have horizontal and vertical scroll bars
Currently I The scroll bar appearing in the parent div is not what I want. Heroes, please help me adjust it
<div id="aaa" style="height: 150px;width: 300px;border: 1px solid #b4c9c6;margin: 4px 0 0 3px;background-color: #ffffff;	overflow: auto;">aaaa<br/>aaaa<br/>aaaa<br/>aaaa<br/><div id="bbb" style="SCROLLBAR-FACE-COLOR: #D5DEDB; SCROLLBAR-HIGHLIGHT-COLOR: #e9f5f8; OVERFLOW: auto; SCROLLBAR-SHADOW-COLOR: #ffffff; SCROLLBAR-3DLIGHT-COLOR: #deeb9f; SCROLLBAR-ARROW-COLOR: #123456; SCROLLBAR-TRACK-COLOR: #fcfdfd; SCROLLBAR-DARKSHADOW-COLOR: #deeb9f;width:100%;height:100%"><table cellspacing="0" rules="all" border="1" style="border-color:#D8E4F8;width:787px;border-collapse:collapse;">		<tr align="center" style="color:#404040;background-color:#E0E0E0;font-weight:normal;height:28px;">			<th scope="col" style="font-weight:normal;width:180px;"></th><th align="center" scope="col" style="font-weight:normal;"></th><th align="center" scope="col" style="font-weight:normal;width:60px;"><a href="javascript:__doPostBack('dg','Sort$pen03')" style="color:#404040;"></a></th><th align="center" scope="col" style="font-weight:normal;width:140px;"><a href="javascript:__doPostBack('dg','Sort$pen04')" style="color:#404040;"></a></th><th align="center" scope="col" style="font-weight:normal;width:60px;"></th><th align="center" scope="col" style="font-weight:normal;width:140px;"></th>		</tr><tr style="height:24px;">			<td align="left" style="width:180px;">                 </td><td align="left"></td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td>		</tr><tr style="height:24px;">			<td align="left" style="width:180px;">                 </td><td align="left"></td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td><td align="center" style="width:60px;"></td><td align="center" style="width:140px;"></td>		</tr><tr style="height:24px;">			<td align="left" style="width:180px;">                  </td><td align="left"></td><td align="center" style="width:60px;"></td><td align="center" style="width:140px;"></td><td align="center" style="width:60px;"></td><td align="center" style="width:140px;"></td>		</tr><tr style="height:24px;">			<td align="left" style="width:180px;">                 </td><td align="left">              </td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td>		</tr><tr style="height:24px;">			<td align="left" style="width:180px;">                 </td><td align="left">                </td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td><td align="center" style="width:60px;"> </td><td align="center" style="width:140px;"> </td>		</tr></table></div></div>

Reply to the discussion (solution)

Your div id=bbb The height and width automatically adapt, but the excess part of the div with id=bbb will have horizontal and vertical scroll bars. This is difficult to achieve. You can make aaa have scroll bars after exceeding the height of aaa

Change the div id=bbb height :100% to height:70px is the effect I want

But this is hard-coded and will not automatically change according to aaaa076402276aae5dbec7f672f8f4e5cc81aaaa076402276aae5dbec7f672f8f4e5cc81

The height and width of your div id=bbb will automatically adapt, but the div with div id=bbb will have horizontal and vertical scroll bars in the excess part. This is difficult to achieve. You can make aaa have a scroll bar when it exceeds the height of aaa. =bbb Changing height:100% to height:70px is the effect I want

But this is hard-coded and will not automatically change according to aaaa076402276aae5dbec7f672f8f4e5cc81aaaa076402276aae5dbec7f672f8f4e5cc81

Is it impossible to call a master?

#bbb{height:100%;width:100%;overflow:scroll;}

<table style="width:200px;height:200px;border:1px solid #84C1FF;margin:50px auto;overflow: hidden">        <tr>            <td>                <div style="float: left">                asdfasfsadfa<br/>                asdfasfsadfa<br/>                asdfasfsadfa<br/>                asdfasfsadfa<br/>                asdfasfsadfa<br/>                </div>            </td>        </tr>        <tr>            <td>                <div style="height: 100%;width: 100%;overflow: auto">                <table>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                </table>                </div>            </td>        </tr>    </table>

The two brothers upstairs, have you run the html code? It doesn’t work.

The two brothers upstairs, have you run the html code? It doesn’t work.

The row height and column width of your table should be Use percentage settings, otherwise the table will adapt to the external height, and the elements inside you will still be fixed. Of course it will be useless

Sorry, I misunderstood your request
According to your request, I can only use js Calculate the height of aaaa076402276aae5dbec7f672f8f4e5cc81aaaa076402276aae5dbec7f672f8f4e5cc81, and then calculate the height required for #bbb

Why do I feel like I don’t understand what you mean?

Your code looks like this.


It seems that the result is the same as what you want, no problem.

At the same time, I also tried it. You said setting the height of div=bbb to 70px has the same effect. There is no difference.

You don’t want the scroll bars to be displayed when the page is initialized? Even if you set the height to 70px, after adding your aaaa076402276aae5dbec7f672f8f4e5cc81, add a few more, bbb will still go down. Since it needs to be adaptive, what is the problem with the current effect?

Or maybe, I don’t understand what effect you want to achieve.

Brothers upstairs, have you run the html code? It doesn’t work.

<table style="width:200px;height:200px;border:1px solid #84C1FF;margin:50px auto;overflow: hidden">    <tr>        <td>            <div style="float: left">                asdfasfsadfa<br/>                asdfasfsadfa<br/>                asdfasfsadfa<br/>                asdfasfsadfa<br/>                asdfasfsadfa<br/>            </div>        </td>    </tr>    <tr>        <td>            <div style="height: 100%;width: 200px;overflow: auto">                <table>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                    <tr><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td><td>aaaaaaaaaaaaa</td></tr>                </table>            </div>        </td>    </tr></table>

Chrome is good.

Why do I feel like I don’t understand what you mean?

Your code looks like this.


It seems that the result is the same as what you want, no problem.

At the same time, I also tried it. You said that setting the height of div=bbb to 70px has the same effect. There is no difference.

You don’t want the scroll bars to be displayed when the page is initialized? Even if you set the height to 70px, after adding your aaaa076402276aae5dbec7f672f8f4e5cc81, add a few more, bbb will still run down. Since it needs to be adaptive, what is the problem with the current effect?

Or maybe, I don’t understand what effect you want to achieve.

The screenshot you took is set to 70px. I tried it myself

The effect you want is impossible to achieve when the height of the parent element is certain

Try adding a few more aaaadf250b2156c434f3390392d09b1c9563 Even if it is 70px, the horizontal scroll bar will not be displayed.

If you insist on such an effect, then use the fixed positioning of the DIV to simulate it, and then use JS to control the simulated scroll bar.

But the complexity will be very high.

It seems that the height can only be hard-coded and cannot be achieved through a certain attribute. The picture you captured is set to 70px. I tried it myself

The effect you want is in When the height of the parent element is certain, it is impossible to achieve

Try adding a few more aaaadf250b2156c434f3390392d09b1c9563. Even if it is 70px, the horizontal scroll bar will not be displayed.

If you insist on such an effect, then use the fixed positioning of the DIV to simulate it, and then use JS to control the simulated scroll bar.

But the complexity will be very high.

You can’t even write it to death

What you said aaaadf250b2156c434f3390392d09b1c9563 there is an indefinite number, you can add a few more, or use 70px to see the effect, it is still the same as you now The desired effect is different.

This is not a question of writing it to death or not.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn