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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

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.

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.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

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.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles