最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Bootstrap 3.x打印預覽背景色與文字顯示異常的解決

 更新時間:2016年11月06日 10:03:03   作者:三塊石頭  
前幾天同事有個問題咨詢我,他在調用print()來打印頁面,發(fā)現(xiàn)打印預覽頁面上的背景色無法顯示以及文字總是顯示為黑色,感覺非常奇怪,我通過測試發(fā)現(xiàn)是Bootstrap的問題,現(xiàn)在將解決的方法分享給大家,希望可以幫助到同樣遇到這個問題的朋友們,下面來一起看看。

我首先測試了一段如下的代碼,發(fā)現(xiàn)打印預覽時的確無法顯示背景色。

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title>Regonline</title>
 <link href="css/bootstrap.css" rel="stylesheet" />
 <link href="css/font-awesome.min.css" rel="stylesheet" />
</head>

<body>

 <style>

  .main{

   overflow: hidden;
   padding: 40px;
  }

  .one, .two, .three{

   float: left;

   height: 40px;
  }

  .one{

   width: 40%;
   background-color: red;
  }

  .two{

   width: 30%;
   background-color: green;
  }

  .three{

   width: 30%;
   background-color: pink;
  }


 </style>
  
  <div class="main">
   <div class="one"></div>
   <div class="two"></div>
   <div class="three"></div>
  </div>
</body>

</html>

比較奇怪的是,如果我刪除bootstrap的樣式引用,就可以正常打印預覽了。想來必定是bootstrap3 設置了@media print相關屬性導致。

果然,翻開源碼,發(fā)現(xiàn)如下代碼:

@media print {
 * {
 color: #000 !important;
 text-shadow: none !important;
 background: transparent !important;
 box-shadow: none !important;
 }
 a,
 a:visited {
 text-decoration: underline;
 }
 a[href]:after {
 content: " (" attr(href) ")";
 }
 abbr[title]:after {
 content: " (" attr(title) ")";
 }
 a[href^="javascript:"]:after,
 a[href^="#"]:after {
 content: "";
 }
 pre,
 blockquote {
 border: 1px solid #999;

 page-break-inside: avoid;
 }
 thead {
 display: table-header-group;
 }
 tr,
 img {
 page-break-inside: avoid;
 }
 img {
 max-width: 100% !important;
 }
 p,
 h2,
 h3 {
 orphans: 3;
 widows: 3;
 }
 h2,
 h3 {
 page-break-after: avoid;
 }
 select {
 background: #fff !important;
 }
 .navbar {
 display: none;
 }
 .table td,
 .table th {
 background-color: #fff !important;
 }
 .btn > .caret,
 .dropup > .btn > .caret {
 border-top-color: #000 !important;
 }
 .label {
 border: 1px solid #000;
 }
 .table {
 border-collapse: collapse !important;
 }
 .table-bordered th,
 .table-bordered td {
 border: 1px solid #ddd !important;
 }
}

 注意代碼里面的 color:#000 !important; 以及 background-color:transparent !important;  。它表示打印時,頁面中的文字都為黑色,并且背景色都設置為透明。因為有了這樣的樣式,我們的背景色就打印

不出來了。去掉這兩段代碼,一切OK!

值得一提的說:如果頁面中有超鏈接,打印時會顯示超鏈接的地址,這樣比較難看。我們刪除對應的樣式即可。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。

相關文章

最新評論

都江堰市| 阳信县| 奉节县| 蒙自县| 三都| 马边| 汶上县| 井研县| 夏河县| 清水县| 和林格尔县| 德庆县| 炉霍县| 咸宁市| 吉首市| 梅州市| 专栏| 合川市| 三门峡市| 太原市| 石城县| 贵定县| 家居| 双柏县| 乌鲁木齐县| 佛冈县| 武陟县| 资中县| 郁南县| 菏泽市| 兴业县| 玉溪市| 乌兰察布市| 东源县| 新巴尔虎左旗| 攀枝花市| 大厂| 长顺县| 苍南县| 鄂尔多斯市| 南溪县|