자바 스크립트를 사용하여 div 콘텐츠를 인쇄하려고합니다. 스타일링을 위해 외부 CSS 파일을 사용하고 있습니다. 그러나 인쇄 문서는 bootstrap.css
을 추가 한 후에 스타일을 적용하지 않습니다.HTML div를 인쇄하여 스타일이 부트 스트랩과 작동하지 않습니다.
여기 내 코드입니다. 그것은 미디어 쿼리에 문제가
HTML 페이지
<html>
<head>
<title>Print Div Test</title>
<link href="css/mycss.css" rel="stylesheet" />
<link href="css/bootstrap.css" rel="stylesheet" />
<script src="js/lib/jquery-1.11.1.js"></script>
<script type="text/javascript">
function PrintElem() {
Popup($('#mydiv').html());
}
function Popup(data) {
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
mywindow.document.write("<link rel=\"stylesheet\" href=\"css/bootstrap.css\" type=\"text/css\" media=\"print\" />");
mywindow.document.write("<link rel=\"stylesheet\" href=\"css/mycss.css\" type=\"text/css\" />");
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
//mywindow.close();
return true;
}
</script>
</head>
<body>
<div>
<div id="mydiv" class="row">
<h1>This will be printed. </h1>
<div class="col-md-6">
<div style="color: red">In line styles applied.</div>
</div>
<div class="col-md-6">
<div class="myclass">Style from sheet</div>
</div>
</div>
<input type="button" value="Print Div" onclick="PrintElem()" />
</div>
</body>
</html>
CSS 파일
.myclass {
color: greenyellow;
}
인가? 부트 스트랩을 추가하기 전에 다른 스타일로 작동합니다.
이 .myclass {색상을 시도 내에서 더 추가해야 할 수도 있습니다 사용하는 미디어 쿼리를 추가 : greenyellow! important;} –
! important를 추가하는 것은 관련 요소에 대해 성공한 것이지만 인쇄 문서에 부트 스트랩 스타일을 적용해야합니다. 위의 예제 코드와 같이 전체 문서에 부트 스트랩 그리드 시스템을 사용하고 있습니다. –