javascript - 为什么当我点击打印按钮时@media print 的选择器没有显示正确的格式?

标签 javascript jquery html css

当我点击打印按钮时,文本应该显示在打印对话框的四列中,但它在我写的时候显示为一个段落。

This are my script code where there is click event of print button. 
when i click it print dialog popup but the text which it suppose to 
show in four column shows it as a paragraphs.

 <script>

    $(document).ready(function () {

        $(document.body).on('click', '#btnPrint', function () {
         
         
            window.print();
           
            
           
        });
    });


</script>
my css code.



@media print {
   
 .FourColumnClass
    {
    -webkit-column-count: 4; 
    -moz-column-count: 4;
    column-count: 4;

    -webkit-column-gap: 40px; 
    -moz-column-gap: 40px;
    column-gap: 40px;
    }

}
my html code.

<div class="clsbtn">
    <button type="button" id="btnPrint">Print</button>
</div>

<div class="FourColumnClass">
  my dog name is jonney. my dog name is jonney. my dog name is jonney.
  my dog name is jonney. my dog name is jonney. my dog name is jonney. 
  my dog name is jonney. my dog name is jonney. my dog name is jonney. my   dog name is jonney.
</div>

最佳答案

添加media="print"在你的<link rel="stylesheet" type="text/css" href="mystyle.css" media="print">在 html 头上

关于javascript - 为什么当我点击打印按钮时@media print 的选择器没有显示正确的格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28925446/

相关文章:

html - CSS:如何在固定宽度、居中的 div 的背景中显示图像?

javascript - 在 jquery ajax 中使用 e.preventDefault() 时图像未发布

javascript - HTML5 `success` 标记的 `ready` 和 `<audio>` 事件?

javascript - laravel 中的 GPS 位置跟踪

javascript - 如何在Javascript中从Azure Blob存储下载数据后将base64编码的数据嵌入图像中?

javascript - 使用Jquery绑定(bind)函数(带参数)到点击事件

html - 在悬停时显示,但仅在悬停的元素上显示

javascript - Array.Push 仅返回最后推送的对象。如何解决?

jquery - 使用悬停显示隐藏的 iframe,然后在 Internet Explorer 中失去焦点

javascript - 数据库插入前检查文本