Table of Contents
Reply to the discussion (solution)
Home Web Front-end HTML Tutorial Child div height adapts to fixed parent div_html/css_WEB-ITnose

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

Jun 24, 2016 pm 12:26 PM

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

aaaa
aaaa
is dynamically changing div id=aaa height and width are fixed
I want to achieve that no matter how many aaaa
aaaa
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>
Copy after login


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 aaaa
aaaa

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 aaaa
aaaa

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>
Copy after login

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 aaaa
aaaa
, 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 aaaa
, 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>
Copy after login

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 aaaa
, 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 aaaa
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 aaaa
. 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 aaaa
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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles