CSS - Use calc() to keep widths of elements the same

后端 未结 3 2054
予麋鹿
予麋鹿 2021-02-05 06:08

Is something like this possible in CSS?

elementOne elementt
3条回答
  •  -上瘾入骨i
    2021-02-05 06:57

    No, it's not possible with CSS.

    For that you will have to use JavaScript (document.getElementById(elementOne).offsetWidth or similar, depending on exactly what width you are looking for). Calc is used to do math, not execute scripts. There is no way of putting JS in a CSS statement, like you are trying to do.

    For more help on the JS bit, see How do I retrieve an HTML element's actual width and height?

    Edit: For some background on why this would be a bad idea to implement in CSS, se Value calculation for CSS (TL;DR: It has been tried. Things exploded)

提交回复
热议问题