@Media print css

前端 未结 2 1369
北恋
北恋 2020-12-02 01:13

I have my HTML page with this structure:





   
2条回答
  •  情话喂你
    2020-12-02 01:17

    If that is the exact structure of your html then this will work for you.

    @media print {
      nav, 
      div > div:not(.to-print), 
      div + div:not(.to-print) {
          display: none;
      }
    }
    
    /* So you can see the styles working on the elements you want to hide outside of print */
      nav, 
      div > div:not(.to-print), 
      div + div:not(.to-print) {
          color: red;
      }
    
       

    My div to display in print mode

    ....content....

    .... HTML elements

提交回复
热议问题