css - JavaScript, AngularJS: How do I know if element is larger than its container? -


let’s have title in h1 element (any element do). content dynamic (do not know length of title). supposed displayed in 1 line. h1 in div (let’s call container) of limited size.

how know if element (h1) overflows container (div)?

so if overflows apply css class deal situation. example scroll hidden content of h1 view.

  • width of container defined relative screen size.

example:

#container {      width: 60%;      background-color: gray;      height: 50px;      // overflow: hidden;      position: relative;  }    h1 {      overflow: hidden;      height: 100%;      margin: 0;      line-height: 50px;  }
<div id="container">      <h1>a soft white or grey mineral consisting of hydrated calcium sulphate. occurs chiefly in sedimentary deposits , used make plaster of paris , fertilizers, , in building industry.</h1>  </div>

best solution if used in: primary in ngif, secondary in ngclass directives, of following technologies good: javascript, angularjs, css, angularjs directive.

assuming jquery check widths of elements.

if ($('h1').scrollwidth >   $('#container').innerwidth()) { //overflown 

}


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -