-1

Is possible to get "10vw" for the element width in browser or extension.Chrome "Copy Styles" just works fine.But I wanna do it in an extension.

Source code for chrome devtools

chrome copy styles just works fine

<style>
  div { width: 10em }
  body div { width: 10em }
  #id { width: 10vw }
</style>

<div id="dom"></div>
// if viewport width is 375px

var dom = document.getElementById('app');
var style = window.getComputedStyle(dom);

var width = style.getPropertyValue('width');

console.log(width) // 37.5px, "10vw" would be great
李晓爽
  • 61
  • 9

1 Answers1

1
var element = document.getElementById('dom')
var elementWidth = getComputedStyle(element ).width

this will always return width with pixels. hope this will be helpfull