1. Using the calc () method
I do not understand what you mean by dynamic change. But to do a relative calculation, use the calc() method.
Example:
width: calc(100% - 80px);
2. Using a preprocessor such as SASS
You can also check out Sass for preprocessing. One of the well-supported functions is variables.
You can define variables and do some calculations.
$body-size: 200px; body { width: $body-size/2 ; }
Here is a simple example that I created: jsfiddle
Link: SASS
3. Using jQuery
OP mentions resizing when resizing a window. One approach would be to use jQuery
$(window).resize(function() { var width = $(window).width(); var height = $(window).height(); $('#item').width(width); });
4. Using the vw and vh attributes
The OP mentioned the desire to resize according to the viewport in the comment.
vw and vh refers to the width and height of the viewport, respectively.
div.responsive { width: 10vw; height: 10vh; background-color: black; }
geckob
source share