中心打印输出
问题描述:
我打印收据使用jQuery条码条码的条形码。无论我做什么,我都无法将它居中放在收据的底部,它总是显示为左对齐。我试着用中心事业部缠条形码这样中心打印输出
HTML:
<div class="bc_center">
<p id="pr-bcTarget"></p>
</div>
CSS:
.bc_center {
float: none;
margin-left: auto;
margin-right: auto;
}
我也尝试了各种各样的CSS选择从其他StackOverflow的建议。目前没有任何工作。
jQuery的/ JavaScript代码创建条形码看起来像这样
var bar0 = "<div style=\"float: left; font-size: 0px; background-color: " + settings.bgColor + "; height: " + mh + "px; width: &Wpx\"></div>";
var bar1 = "<div style=\"float: left; font-size: 0px; width:0; border-left: &Wpx solid " + settings.color + "; height: " + mh + "px;\"></div>";
我敢肯定它与做“浮动:左”,我试图消除这一点,当然发生了什么事条形码的每一行都出现在一行中。
编辑:我试过几个下面的建议。我现在的代码就是这样
<span class="bc_center" id="pr-bcTarget"></span>
它产生与我原来的完全相同的结果。使用Chrome检查这是什么“的jQuery条形码”正在生成...
<span class="bc_center" id="pr-bcTarget" style="padding: 0px; overflow: auto; width: 77px;">
<div style="float: left; font-size: 0px; background-color: #FFFFFF; height: 50px; width: 10px"></div>
<div style="float: left; font-size: 0px; width:0; border-left: 2px solid #000000; height: 50px;"></div>
... etc ...
<div style="clear:both; width: 100%; background-color: #FFFFFF; color: #000000; text-align: center; font-size: 10px; margin-top: 5px;">1179</div>
</span>
你会发现“明确:既”在最后DIV允许的条码编号“1179”为中心,这确实。
答
@media print {
#pr-bcTarget {
/*might have to add clear:both I can't tell from here*/
float: none;
margin-left: auto;
margin-right: auto;
}
}
给一些宽度与该元素,否则'div'是块元素,充分宽度。 – skobaljic
我向css类添加了以下内容。 “宽度:50%;”并在div中添加了一些文字,以获得较好的效果。仍然没有运气 –