How do I retrieve an HTML element's actual width and height?

前端 未结 14 1664
后悔当初
后悔当初 2020-11-22 02:29

Suppose that I have a

that I wish to center in the browser\'s display (viewport). To do so, I need to calculate the width and height of the &l
相关标签:
14条回答
  • 2020-11-22 03:08

    Use width param as follows:

       style={{
          width: "80%",
          paddingLeft: 100,
          paddingRight: 200,
          paddingTop: 30,
          paddingBottom: 30,
          border: "3px solid lightGray",
        }}
    
    0 讨论(0)
  • 2020-11-22 03:09

    ... seems CSS help to put div on center ...

    <style>
     .monitor {
     position:fixed;/* ... absolute possible if on :root */
     top:0;bottom:0;right:0;left:0;
     visibility:hidden;
     }
     .wrapper {
     width:200px;/* this is size range */
     height:100px;
     position:absolute;
     left:50%;top:50%;
     visibility:hidden;
     }
    
     .content {
     position:absolute;
     width: 100%;height:100%;
     left:-50%;top:-50%;
     visibility:visible;
     }
    
    </style>
    
     <div class="monitor">
      <div class="wrapper">
       <div class="content">
    
     ... so you hav div 200px*100px on center ...
    
      </div>
     </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题