jquery set line-height equal to parent container height

CreateSean

I need to set the line-height dynamically for an h4 based on how high the containing div is. Height will change based on content and screensize.

html

  <div class="col-sm-6 left">
    <div>
      <h4>Lorem ipsum</h4>
    </div>
  </div>

jquery

// set line height of h4 to height of containing div
var divHeight = $('.left').height();

$('.left h4').css('line-height',divHeight);

This isn't working. I've tried a couple of different ways to pass divHeight through but it doesn't work.

Updated with a bootply http://www.bootply.com/9fOHaR0iv0

Banana

following your update with bootply link, it seems you have pictures load in your div which define the div's height.

you have run your code inside $(document).ready() which executes once DOM loads, when in fact you need to wait until all the images load and not the DOM.

you should change your

$(document).ready()

to:

$(window).load()

it will make sure that all images are loaded, and then you will get the correct height.

here is your fixed code: Bootply

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set height equal to browser height

From Dev

jquery set height equal to image height works approx 50% of the time

From Dev

Set height of child to height of parent

From Dev

Flexboxes of equal height, content filling height of container

From Dev

Flexboxes of equal height, content filling height of container

From Dev

JQuery Equal Height Rows

From Java

Equal height rows in a flex container

From Dev

Set height depending on container

From Java

Set min-height equal to content height

From Dev

Set height of div equal to height of image

From Dev

Unable to set row height equal to table height

From Dev

Set height of div equal to height of image

From Dev

How to set a height of the panel equal to the content in jquery mobile?

From Dev

Set equal height for group of divs

From Dev

responsive and equal height for a set of boxes

From Dev

Set equal height for 2 divs

From Dev

Set height of container class to height of image

From Dev

Set parent height relative to child height.

From Dev

Make parent container the height of a hovered child container

From Dev

Make parent container the height of a hovered child container

From Dev

jQuery to set div height

From Dev

Can't get canvas element height to equal container height

From Dev

CSS - Automatically set height of container?

From Dev

Make height of input and div equal to their parent

From Dev

Make div height equal to its parent (100%)

From Dev

jQuery get height of the contents in a container

From Dev

jQuery set height of a div to the 'dynamic height' of another

From Dev

react-konva How to set stage width and height to be equal to its container?

From Dev

Set Div Height equal to Page height using JavaScript / AngularJS / CSS

Related Related

HotTag

Archive