Hide form controls when printing an HTML page with CSS

后端 未结 6 845
被撕碎了的回忆
被撕碎了的回忆 2021-02-12 12:20

Certain HTML form elements have extra UI attached to them, like the up/down arrows on number. When printing the page however, those buttons are no longer needed, as

6条回答
  •  自闭症患者
    2021-02-12 12:32

    A better solution, as it doesn't use vendor prefix, will be to use the output element.

    Principles

    1. hide output element on @media screen ;
    2. update the value of the output element on field input ;
    3. toggle visibility of the input and the output element on @media print.

    → codepen available here.

    HTML

    5 (default print value)

    The output element replace the input on print media

    CSS

    .print {
      display: none;
    }
    
    @media print {
      .screen {
        display: none;
      }
      .print {
        display: inline-block;
      }
    }
    

提交回复
热议问题