Table of Contents
回复讨论(解决方案)
Home Web Front-end HTML Tutorial css fills the remaining height of div_html/css_WEB-ITnose

css fills the remaining height of div_html/css_WEB-ITnose

Jun 24, 2016 am 11:59 AM
css div filling high

我的代码如下:


        

        

        

        


main这个div我做成了可以随意缩放改变其大小,即他的height和width是随时改变的,top这个div的高度是固定的,我想让bottom这个div的高度随着main这个div的高度改变而改变,填充剩余的部分,即始终等于main.height-top.height,请问如何用 CSS的方式解决?


回复讨论(解决方案)

只能用JS去解决了

bottom的高度和宽度使用百分比,即100%试一试。

bottom的高度和宽度使用百分比,即100%试一试。


top是有一个高度的,用100%的话,会超出的。

只能用JS去解决了


就是不想用js的方式解决啊、、、、

在main中的高度确定后,减去top的高度,就是bottom的高度

main这个div你做成随意缩放是什么意思?是用鼠标可以拖动main这个div吗?

用position试试看,然后main跟bottom的高度用百分比。

在main中的高度确定后,减去top的高度,就是bottom的高度


这样说没错,但是如何用 CSS实现?

main这个div你做成随意缩放是什么意思?是用鼠标可以拖动main这个div吗?


对,我做的就是一个类似文件夹的功能,打开后,可以拖动,可以缩放,在缩放时,main这个div的高度和宽度是在一直变化的,用js的方式当然可以解决,但我就是想用CSS的方式解决,不知道有没有好的方法

根据7楼pad1614同学的提醒,最后我采用的是这样的方法:将top的position设置为absolute,将bottom的heigth设置为100%,再在bottom里面添加一个div,其高度和top一样,这样top就会将其覆盖,bottom中剩下的内容则在top的下面显示出来,代码如下:
.top {height:30px; width:100%;position:absolute}
.top2 {height:30px}
.bottom{height:100%}


    

    

    

        

        

    

CSS是可以的

.main{    padding-top:40px;  /*top的高度 假?40px*/    position:relative;}.top{    position:absolute; /*固定在上面*/    top:0;    left:0;    width:100%;}.bottom{    height:100%;}
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

CSS是可以的

.main{    padding-top:40px;  /*top的高度 假?40px*/    position:relative;}.top{    position:absolute; /*固定在上面*/    top:0;    left:0;    width:100%;}.bottom{    height:100%;}
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你这是





这个意思吗?用top覆盖在bottom上,可以实现楼主说的效果吗??


CSS是可以的

.main{    padding-top:40px;  /*top的高度 假?40px*/    position:relative;}.top{    position:absolute; /*固定在上面*/    top:0;    left:0;    width:100%;}.bottom{    height:100%;}
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你这是





Does this mean? Can the effect mentioned by the original poster be achieved by covering the bottom with top? ?


Original? No?

Example:
http://jsbin.com/hesuxonozula/2/edit

CSS is OK

.main{    padding-top:40px;  /*top的高度 假?40px*/    position:relative;}.top{    position:absolute; /*固定在上面*/    top:0;    left:0;    width:100%;}.bottom{    height:100%;}
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


This is okay, but one problem is that the height of main will increase the height of top. If there is a parent div outside main, and the main If height is set to 100%, then the total height of main will exceed the height of the parent div. But thank you very much for proposing another good method!


CSS is OK

.main{    padding-top:40px;  /*top的高度 假?40px*/    position:relative;}.top{    position:absolute; /*固定在上面*/    top:0;    left:0;    width:100%;}.bottom{    height:100%;}
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


This is OK, but there is a problem that the height of main will be Increase the height of top. If there is a parent div outside main and set the height of main to 100%, then the total height of main will exceed the height of the parent div. But thank you very much for proposing another good method!




.main{
box-sizing : border-box;
}



CSS is OK

.main{    padding-top:40px;  /*top的高度 假?40px*/    position:relative;}.top{    position:absolute; /*固定在上面*/    top:0;    left:0;    width:100%;}.bottom{    height:100%;}
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


This way is OK, but there is a problem that the height of main will increase the height of top. If there is a parent outside main div, and set the height of main to 100%, then the total height of main will exceed the height of the parent div. But thank you very much for proposing another good method!


.main{
box-sizing : border-box;
}
God, it sure works! ! !
Thank you very much! ! !

Let’s post the code:















In this way, no matter how the height of outer changes, the height of bottom is the height of main minus the height of top, and the height of top is fixed.
Thanks to classmate u012280941!

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

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.

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

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.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

See all articles