T
T
Twixel2020-04-22 16:01:45
css
Twixel, 2020-04-22 16:01:45

How to calculate content area width by code?

Could you explain how to calculate the width of the content area of ​​the .content element.



.wrapper
{
box-sizing: border-boxl;
width: 500px
padding: 20px
}

.content
{
box-sizing: border-box;
padding: 10px
}
What to pay attention to when calculating, and under what properties, something can change into a solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
smigles, 2020-04-22
@Twixel

The .wrapper content is 500 − 20 * 2 = 460px wide. If the .content is inside the .wrapper, then the .content content will be 460 − 10 * 2 = 440px wide. In both cases, we subtract the left and right padding. If there was a border, it would also be subtracted.

H
hzzzzl, 2020-04-22
@hzzzzl

getComputedStyle

(2 pixels go to border 1px + 1px)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question