简体   繁体   中英

css:- changing { height: fixed } to {height : fit to content}

<div> line 1 <br>
  line 2  <br>
  line 3  <br>
  line 4  <br>
  ...     ...
</div

css:-

div {
  line-height: 20px;
  height: 80px;
}

jQuery:

$('div').css('height', xxx)

can i use the above jQuery code or any other, to make height of div flexible again, ie, to fit the content rather than be predetermined manually?

应用auto ,这是height的默认值,以实现以下目的:

$('div').css('height', 'auto')

Create a second class declaration in your CSS file called "flexible"

.flexible{
  height: auto !important;
}

and then use jQuery to add the class

$('div').addClass('flexible');

http://jsfiddle.net/WQcHs/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM