This is a emcas plugin to convert px unit to vw or vh in css or other files.
-
Download the px2vw.el file to your emcas elisp configuration directory, generally it is
~/.emcas.d/lisp/
in MacOS. Or copy the content ofpx-2vw.el
to a.el
file in emcas el config path, and i suggest to also namedpx2vw.el
. -
Add blow code to your emcas config file,
~/.emcas.d/init.el
or~/.emcas.d/custom.el
are ok.
(require 'px2vw)
(global-set-key (kbd "C-c w") 'region-px->vw)
Now,you added a shortcut key to emacs, if it is inconvenient, you can set F9
to do this.
(global-set-key [f9] 'region-px->vw)
- Move point to width number with "px" unit, and press shortcut key
C-c w
, px unit will convert to vw. For example:
.div {
width: 200px;
}
use C-c w
shortcur key in "200px" chars, it will auto convert to
.div {
width: 13.8889vw;
}
The vw value is convert by expression (/ (* px 100) viewport-width) and maintain four float points.
- I gived default width of viewport is 1440, and not support to change by param, so if you want to change, please modify value of the first line constant
viewpoint-width
inpx2vw.el
.