2017-01-07 6 views
-2

으로 이미 여기에 설명 오버라이드 (override) : 이 Background color not showing in print preview부트 스트랩 인쇄 CSS

내 실제 텍스트 색상을 얻는 방법을 아직 파악하지 않았습니다. 부트 스트랩 클래스 인쇄 - 표시와 함께 인쇄에만 표시 div 얻을 싶지만, 모든 색칠 미리보기에서 손실됩니다.

@media print { 
    .test { 
    background-color: #1a4567 !important; 
    -webkit-print-color-adjust: exact; 
    } 
} 

나는 그것이 무엇을해야합니까 미디어 인쇄 CSS를 추가,하지만 난 텍스트 색상을하지 CSS에서 설정 한 색상을 원하는 경우

JsFiddle

. 의견에 따라

+0

을 설정하고 있는가? – epascarello

+0

예. jsFiddle에서 bootstrap-cdn을 제거하면 텍스트 색상으로 인쇄됩니다. – AHahn

답변

1

편집 :

당신은 두 가지 방법으로 자바 스크립트의 style.setProperty() 방법을 사용하여 !important을 추가 할 수 있습니다

  1. 순수 JS :document.getElementById().
  2. jQuery 하이브리드 : jQuery의 .each() 안에 감싸십시오. 아래

모두 예 : 프린터 설정은 배경 색상과 이미지를 인쇄 할 수 있도록

$('#filePrintPreview').html("TEST"); 
 
//way 1: pure JS exmple 
 
document.getElementById('filePrintPreview').style.setProperty('color', 'red', 'important'); 
 
//way 2: wrapped inside jQuery's each() example 
 
$('h3').each(function() { 
 
    this.style.setProperty('color', '#12FF12', 'important'); 
 
});
@media print { 
 
    .test { 
 
    background-color: #1a4567 !important; 
 
    -webkit-print-color-adjust: exact; 
 
    } 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="col-md-12 test"> 
 
    <h3>Heading</h3> 
 
    <div class="box no-border shadow" id="filePrintPreview" style="padding: 2px; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-line;"> 
 
    </div> 
 
</div> 
 

 
<button class="btn btn-flat btn-primary btn-sm" style="margin-top:15px;" onclick=" window.print();">Print 
 
</button>

+0

필자의 경우 중요한 방법은 명백하게 작동합니다. 하지만 그게 정확히 내가 필요로하는 것은 아닙니다. 인쇄 된 텍스트의 색상을 선택할 수있는 사용자가 있습니다. jQuery를 통해! important 태그를 설정할 수 있습니까? – AHahn

+0

DrDreo, 네, JS로 할 수 있지만, 위의 편집, 희망이 도움이됩니다. 문안 인사. – Syden

+0

그런 식으로 색상 가져 오기 설정을 생각한 적이 없어요. 고맙습니다. ! important를 설정하는 것은 고통이지만, 단 하나의 부분 만 색상으로 인쇄하면됩니다. 이것은 정확하게 작동하는 방법입니다. – AHahn