Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set dynamically height to element?

I am trying to set dynamically height to element in my demo .I will tell you issue I am taking static or constant value of height in my demo .I take 250px constant value

 #wrapper{
    background-image: url(https://dl.dropboxusercontent.com/s/nz1fzunlqzzz7uo/login_bg.png?dl=0);
    min-height: 250px;
    background-repeat: no-repeat; 
}

But I need to add this height dynamically .I got height from this

$scope.hgt =$window.innerHeight/3;
alert($scope.hgt)

But I need to set $scope.hgt to min-height to #wrapper div dynamically?.I don't want to take static value of div height .I want to add dynamically .

here is my code http://codepen.io/anon/pen/bdgawo

same thing i need to in angular what we do in jquery

$('#wrapper').css('height': $window.innerHeight / 3)
like image 621
user944513 Avatar asked May 30 '15 14:05

user944513


People also ask

How do I set dynamic height in HTML?

getElementById('myDiv'). style. height = '500px'; . If you have a dynamic height you can use height + 'px' .

How do you create dynamic height?

We use css property height: calc( 100% - div_height ); Here, Calc is a function. It uses mathematical expression by this property we can set the height content div area dynamically.

How do I change the dynamic height of a div?

The content height of a div can dynamically set or change using height(), innerHeight(), and outerHeight() methods depending upon the user requirement.

How set dynamic width and height in CSS?

Top header with 100% width and 50px height. Left navigation bar with 200px width and dynamic height to fill the screen. A container on the right of the nav bar and under the header with dynamic width and height to fill the screen.


2 Answers

You could simply achieve this by own directive which will add css dynamically

Markup

<div id="wrapper" set-height>
  <h4 class="headerTitle">tell Mother name</h4>
</div>

Directive

.directive('setHeight', function($window){
  return{
    link: function(scope, element, attrs){
        element.css('height', $window.innerHeight/3 + 'px');
        //element.height($window.innerHeight/3);
    }
  }
})

The better solution would be you could use ng-style directive that expects the values in JSON format.

<div id="wrapper" ng-style="{height: hgt+ 'px'}">
  <h4 class="headerTitle">tell Mother name</h4>
</div>

Working Codepen

like image 79
Pankaj Parkar Avatar answered Oct 19 '22 19:10

Pankaj Parkar


The following should work. Putting it in the codepen snippet won't show as the window size is small so it draws height from the min-height attribute. Test it out on a bigger window.

<div id="wrapper" style="height: {{ hgt }}px" >
    <h4 class="headerTitle">tell Mother name</h4>
<div>
like image 1
srthu Avatar answered Oct 19 '22 19:10

srthu