国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

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

2019-11-19 19:03:10
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

<!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的樣式引用,就可以正常打印預(yù)覽了。想來(lái)必定是bootstrap3 設(shè)置了@media print相關(guān)屬性導(dǎo)致。

果然,翻開(kāi)源碼,發(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;  。它表示打印時(shí),頁(yè)面中的文字都為黑色,并且背景色都設(shè)置為透明。因?yàn)橛辛诉@樣的樣式,我們的背景色就打印

不出來(lái)了。去掉這兩段代碼,一切OK!

值得一提的說(shuō):如果頁(yè)面中有超鏈接,打印時(shí)會(huì)顯示超鏈接的地址,這樣比較難看。我們刪除對(duì)應(yīng)的樣式即可。

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 昆明市| 宣恩县| 灌南县| 靖州| 大石桥市| 贡山| 宝丰县| 朔州市| 西充县| 五原县| 瑞金市| 会同县| 清涧县| 怀柔区| 海原县| 德江县| 永仁县| 鄢陵县| 连城县| 龙胜| 通许县| 乌拉特中旗| 镇坪县| 石城县| 广水市| 阿克陶县| 彩票| 桐乡市| 五莲县| 大姚县| 漳平市| 中方县| 明溪县| 镇江市| 瑞金市| 万山特区| 浦城县| 吉首市| 济源市| 陆良县| 县级市|