简体   繁体   中英

Calculating DIV-height with LESS

i'm having a weird question:

How can i calculate the heigth of an HTML-DIV via less, depending on the width of the screen?

Situation:

I'm building a new homepage for my company with TYPO3 and the bootstrap 3 package. On the mainpage, my boss wants an image carousel. The problem is, the image is resizable, but noch the carousel itself.

Now i want to calculate the height of this DIV.

This would be the calculation (pic size = 1920px*600px):

carousel_height = 100 * window_width / 320  

Now, how can i calculate this with LESS?

LESS-Code i want to expand:

.carousel .item {
    background-position: 0 0;
    background-size: contain;
    height: 600px;
}
Should be this:

    .carousel .item {
      height: 100 * 100vw / 320;
    }

And actually, if you just use a calculator, you can simplyfy that a bit further:

    .carousel .item {
      height: 31.25vw;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM