答案 0 :(得分:0)
如果在包含两者的元素上使用flex-box,则可以使用印刷媒体查询中的order
属性对其进行更改:
document.getElementById('simulate').addEventListener('click', function() {
document.getElementById('container').classList.toggle('print');
});
#container {
display: flex;
flex-direction: column;
}
#container > div {
width: 100%;
border: solid 1px;
}
@media print {
#container > div:first-child {
order: 2;
}
}
#container.print > div:first-child {
order: 2;
}
<div id="container">
<div>Top</div>
<div>Bottom</div>
</div>
<button id="simulate">Simulate Print</button>