Home > Net >  Use @Media Width in CSS Width Calculation
Use @Media Width in CSS Width Calculation

Time:09-16

I would like to dynamically calculate the width of an image based on the width of the window.

Current CSS which isn't working:

    .banner-image-side {
      width: calc((@media(width) - 1527px) / 2); 
    }

CodePudding user response:

Try to using vw unit for get with of window.

example:

    .banner-image-side {
      width: calc((100vw - 1527px) / 2); 
    }

CodePudding user response:

Use vw

vw ==> 1% of the viewport's width.

Documentation: CSS values and units

.banner-image-side {
    width: calc((@media(vw) - 1527px) / 2); 
}

P.S: I think -1527px is too great a value to reduce with

  •  Tags:  
  • css
  • Related