I
I
iugi2017-08-17 16:52:46
css
iugi, 2017-08-17 16:52:46

How to define the width or height of an element in css?

Hello! How to get the width of an element in css.
For example, I need to calculate the margin from the top: .element{margin-top: calc(50vh-n)}
where n is the height of the element. How is it labeled

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
paramid, 2017-08-18
@iugi

vh-vw are just units.

.element{
margin-top: calc(50vh-n) // n - тут не прокатит, это переменная, её нельзя пропихнуть в css
}
this is css, you can’t really code in it, there are no variables here if you don’t use preprocessors.
you need to use js, and directly js to work with sizes.
using jquery library like
var h = $('#container').css('height');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question