Changing HTML from CSS media query

后端 未结 4 1376
不知归路
不知归路 2021-02-04 11:47

I have a situation in which I want to change an HREF in an unordered list in HTML when a CSS media query is true. Specifically I want to change an HREF from calendar.html to ca

4条回答
  •  梦如初夏
    2021-02-04 12:26

    I don't think CSS can alter HTML attributes

    you can just "hide" it, and display the other one

    @media only screen and (...) {
        .your-default-calendar {
            display: none;
        }
        .your-calender2 {
            display: inline-block;
        }
    }
    

    but why not just use JavaScript? you can change a attribute easily in JavaScript.

    if (window.matchMedia("your media queries").matches) {
        // ...
    }
    

提交回复
热议问题