Conditional Formatting in HTML Tags

前端 未结 7 1247
挽巷
挽巷 2020-12-31 12:23

Is there any option for using IF-ELSE conditioning in HTML tags

   do something     
      do something            


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 12:56

    With acknowledgement to Kevin Loney and his javaScript solution, we should also consider CSS conditionals. If the conditional is based on browser-sensing/responsive design, then javaScripting can be bypassed:

    show something
    show something

    "Show something" in the sense that you would merely hide the condition which does not apply. In the example below, "if-part" is shown on mobile devices only. "else-part" is shown on larger screens.

    @media screen and (max-width:767px){
        .if-part{display:initial;}
        .else-part{display:none}
    }
    @media screen and (min-width:768px){
        .if-part{display:none;}
        .else-part{display:initial}
    }
    

    This answer offers even more CSS options to consider.

提交回复
热议问题