html - 为什么屏幕上看不见的元素在打印时会部分出现?

标签 html css printing material-ui

我生成季后赛锦标赛分组... 通常在每次旅行中有 2^n 参与者:16、8、4、2。并且很容易在 flex 列中调整它们。但是有一个棘手的事情,在第一轮(轮)中,参与者人数在 16 到 8 之间。我需要隐形决斗,就像括号中的占位符一样,用于调整。
我试着让它们 {visibility: hidden},它们在屏幕上消失了。但是在打印的时候竟然部分出现了。 为什么会这样?

它在屏幕上的样子(很好,就像我计划的那样):

how it looks on the screen

以及打印时的外观 (ctrl+P):

how it looks while printing

还有一个代码:

import React from 'react'
import { Checkbox, Box } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import { find } from 'lodash'
import { athletName, trainerName } from '../../config/functions'

function DuelSimple(props) {
  const {
    duelData,
    participants,
    onFighterChange,
    onWinnerChange,
    showScoreInput,
    showWinnerCheckbox
  } = props
  const { id, fighterRed, fighterBlue, winner, label /* scoreRed, scoreBlue  */ } = duelData

  const styles = {
    duelTable: props => ({
      /* width: '5cm', */
      border: '1px solid gray',
      borderRadius: 5,
      marginBottom: 5,
      borderSpacing: 0,
      tableLayout: 'fixed',
      visibility: props.duelData.status === 'fake' ? 'hidden' : 'visible'
    }),
    duelNumber: {
      width: 30,
      borderRight: '1px solid gray',
      textAlign: 'center',
      color: 'slategray'
    },
    duelLabel: {
      fontSize: 9
    },
    athletRed: { width: 140, height: 33, padding: '0 5px', borderBottom: '1px solid gray' },
    athletBlue: { width: 140, height: 33, padding: '0 5px' },
    athletInput: { width: '100%', border: 'none' },
    checkboxColumn: { width: 35, height: 33 },
    checkboxColumnRed: { borderBottom: '1px solid gray' },
    checkboxRed: { width: 7, height: 7, marginTop: 2, color: 'red' },
    checkboxBlue: { width: 7, height: 7, marginTop: 2, color: 'blue' },
    trainer: { color: 'gray', fontSize: 10 },
    athletColorColumn: { width: 5 },
    athletColorRed: { backgroundColor: 'rgba(255,0,0,0.5)', borderBottom: ' 1px solid gray' },
    athletColorBlue: { backgroundColor: 'rgba(0,0,255,0.5)' },
    scoreColumn: { width: 35, borderLeft: ' 1px solid gray' },
    scoreColumnRed: {
      '& input': { color: 'rgba(255,0,0,0.5)', fontWeight: 'bold' },
      borderBottom: ' 1px solid gray'
    },
    scoreColumnBlue: { '& input': { color: 'rgba(0,0,255,0.5)', fontWeight: 'bold' } },
    scoreInput: { border: 'none', width: 31, height: 25, textAlign: 'center' }
  }

  const useStyles = makeStyles(theme => styles)

  const classes = useStyles(props)

  let athletRedName, athletBlueName, trainerRedName, trainerBlueName

  //populate fighters data by id
  if (fighterRed) {
    const participantRedPopulated = find(participants, { athlet: { id: fighterRed } })
    athletRedName = athletName(participantRedPopulated.athlet)
    trainerRedName = trainerName(participantRedPopulated.trainer)
  } else {
    athletRedName = ''
  }
  if (fighterBlue) {
    const participantBluePopulated = find(participants, { athlet: { id: fighterBlue } })
    athletBlueName = athletName(participantBluePopulated.athlet)
    trainerBlueName = trainerName(participantBluePopulated.trainer)
  } else {
    athletBlueName = ''
  }

  return (
    <table className={classes.duelTable}>
      <tbody>
        <tr>
          <td className={classes.duelNumber} rowSpan='2'>
            {id}
            {label ? <div className={classes.duelLabel}>{label}</div> : ''}
          </td>
          <td className={classes.athletRed}>
            <input
              onChange={onFighterChange(id)}
              type='text'
              data-id={id}
              data-color='Red'
              className={classes.athletInput}
              value={athletRedName}
            />
            <div className={classes.trainer}>{trainerRedName}</div>
          </td>
          {showWinnerCheckbox && (
            <td className={`${classes.checkboxColumnRed} ${classes.checkboxColumn}`}>
              <Box displayPrint='none'>
                <Checkbox
                  inputProps={{ 'data-winner': fighterRed }}
                  onChange={onWinnerChange(id)}
                  className={classes.checkboxRed}
                  checked={winner === fighterRed && winner ? true : false}
                />
              </Box>
            </td>
          )}
          {showScoreInput && (
            <td className={`${classes.scoreColumn} ${classes.scoreColumnRed}`}>
              <input className={classes.scoreInput} />
            </td>
          )}
          <td className={`${classes.athletColorRed} ${classes.athletColorColumn}`}></td>
        </tr>
        <tr>
          <td className={classes.athletBlue}>
            <input
              onChange={onFighterChange(id)}
              type='text'
              data-id={id}
              data-color='Blue'
              className={classes.athletInput}
              value={athletBlueName}
            />
            <div className={classes.trainer}>{trainerBlueName}</div>
          </td>
          {showWinnerCheckbox && (
            <td className={`${classes.checkboxColumn}`}>
              <Box displayPrint='none'>
                <Checkbox
                  inputProps={{ 'data-winner': fighterBlue }}
                  onChange={onWinnerChange(id)}
                  className={classes.checkboxBlue}
                  checked={winner === fighterBlue && winner ? true : false}
                />
              </Box>
            </td>
          )}
          {showScoreInput && (
            <td className={`${classes.scoreColumn} ${classes.scoreColumnBlue}`}>
              <input className={classes.scoreInput} />
            </td>
          )}
          <td className={`${classes.athletColorBlue} ${classes.athletColorColumn}`}></td>
        </tr>
      </tbody>
    </table>
  )
}

export default DuelSimple

以及元素的依赖:

{
"@material-ui/core": "^4.5.2",
"@material-ui/icons": "^4.5.1",
"firebase": "^7.2.3",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-redux": "^7.1.1",
"react-redux-firebase": "^3.0.4",
"react-router-dom": "^5.1.2",
"react-scripts": "2.1.5",
"redux": "^4.0.4",
"redux-firestore": "^0.9.0"
}

最佳答案

我刚刚设置了 opacity:0,它帮助了我) 打扰了)

关于html - 为什么屏幕上看不见的元素在打印时会部分出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58662021/

相关文章:

c# - 如何从c#中的html代码中获取html代码的一部分?

javascript - Jquery 单击仅在切换时工作一次

javascript - 为 Bootstrap 3 Accordion 设置显示三 Angular 形

php - 将鼠标悬停在图像上,获取打印对话框?

jQuery .fadeTo 添加元素

jquery - 如何使用多分辨率字体大小对齐 div 中间的文本

javascript - 防止点击暂停视频

html - 找出带有标题的三列布局的 CSS [包括草图]

printing - 是否有一种可移植的方法来打印来自 C 预处理器的消息?

java - 打印多个类