Answer the question
In order to leave comments, you need to log in
How to teach the browser to understand the "dp" unit??
When I began to study material design, the question arose of how to teach the browser to understand such a unit of measurement as "dp". Let me clarify a little: I mean, how can I make the browser transform dp from CSS, say, into px.
Google gives a simple formula: dp = (width in pixels * 160) / screen density, where
screen density = screen width (or height) in pixels / screen width (or height) in inches
It seems to be nothing complicated, and all sizes can be obtained normally js. But here's how to substitute this in the style file, I don't understand. That is, if I write in the CSS file: button { width: 32dp; }, JS calculates dp for my screen and replaces 32dp with 180px for example. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
For the browser 1px = 1dp, if the <head>
page is written
<meta name="viewport" content="width=device-width, initial-scale=1.0">
I don’t know why you need to use a unit of measure in css, which is not there ?! - oh well,
you can use the preprocessor and drive it all into a mixin
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question