Assigned width in percentage but want to get it in pixels

前端 未结 11 1219
北荒
北荒 2020-12-15 15:07



        
11条回答
  •  不知归路
    2020-12-15 15:30

    Pls check the code appended below, I hope this is the simplest way to get the width from percentage to pixel.

    HTML

    Perentage to Pixel :

    CSS

     .test {
      border: 1px solid;
      cursor: pointer;
      height: 100%;
      position: relative;
      width: 100%;
      padding: 10px;
    }
    

    JS

    var widPx = $('#test1').width();
    $('#widthPx').append(Math.round(widPx) + 'px');
    

    OUTPUT

    Perentage to Pixel : 609px

    The output would be purely based on the div width.

    Thanks.

提交回复
热议问题