CSS Equivalent of the “if” statement

前端 未结 12 1379
暖寄归人
暖寄归人 2020-12-01 13:49

Is there any way to use conditional statements in CSS?

12条回答
  •  情深已故
    2020-12-01 14:26

    I would argue that you can use if statements in CSS. Although they aren't worded as such. In the example below, I've said that if the check-box is checked I want the background changed to white. If you want to see a working example check out www.armstrongdes.com. I built this for a client. Re size your window so that the mobile navigation takes over and click the nav button. All CSS. I think it's safe to say this concept could be used for many things.

         #sidebartoggler:checked + .page-wrap .hamb {
            background: #fff;
          }
    
    // example set as if statement sudo code.
    
    if (sidebaretoggler is checked == true) {
    set the background color of .hamb to white;
    }
    

提交回复
热议问题