Set width of fixed positioned div relative to his parent having max-width

后端 未结 3 1254
轻奢々
轻奢々 2021-01-02 01:24

Is there any solution without JS?

html

css

3条回答
  •  -上瘾入骨i
    2021-01-02 01:35

    It seems there is no solution without JS. This blog post by Felipe Tadeo explains why:

    https://dev.to/phillt/inherit-the-width-of-the-parent-element-when-position-fixed-is-applied

    It explains the confusion around width: inherit

    "Fixed positions itself relative to the viewport... whenever you inherit width (with position fixed) it will be with respect to the viewport"

提交回复
热议问题