【问题标题】:div and class not showing updiv 和 class 没有出现
【发布时间】:2015-12-22 20:09:53
【问题描述】:

我正在我的网站上测试条形码,但由于某种原因,代表条形码的 class="b128" 的 div 没有显示出来。如果我在另一个网站上测试相同的源代码,它确实会显示出来,但样式不同。

有谁知道我怎样才能让这个源代码显示出来并同时保持原始样式?

<style>
div.b128{
border-left: 1px black solid;
height: 60px;
}   
</style>

<?php
global $char128asc,$char128charWidth;
$char128asc=' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';                 
$char128wid = array(
'212222','222122','222221','121223','121322','131222','122213','122312','132212','221213', // 0-9 
'221312','231212','112232','122132','122231','113222','123122','123221','223211','221132', // 10-19 
'221231','213212','223112','312131','311222','321122','321221','312212','322112','322211', // 20-29             
'212123','212321','232121','111323','131123','131321','112313','132113','132311','211313', // 30-39 
'231113','231311','112133','112331','132131','113123','113321','133121','313121','211331', // 40-49 
'231131','213113','213311','213131','311123','311321','331121','312113','312311','332111', // 50-59 
'314111','221411','431111','111224','111422','121124','121421','141122','141221','112214', // 60-69 
'112412','122114','122411','142112','142211','241211','221114','413111','241112','134111', // 70-79 
'111242','121142','121241','114212','124112','124211','411212','421112','421211','212141', // 80-89 
'214121','412121','111143','111341','131141','114113','114311','411113','411311','113141', // 90-99
'114131','311141','411131','211412','211214','211232','23311120'   );                      // 100-106

////Define Function
function bar128($text) {                        // Part 1, make list of widths
  global $char128asc,$char128wid;               
  $w = $char128wid[$sum = 104];                         // START symbol
  $onChar=1;
  for($x=0;$x<strlen($text);$x++)                               // GO THRU TEXT GET LETTERS
if (!( ($pos = strpos($char128asc,$text[$x])) === false )){ // SKIP NOT FOUND CHARS
  $w.= $char128wid[$pos];
  $sum += $onChar++ * $pos;
}                   
  $w.= $char128wid[ $sum % 103 ].$char128wid[106];          //Check Code, then END
                                            //Part 2, Write rows
  $html="<table cellpadding=0 cellspacing=0><tr>";              
  for($x=0;$x<strlen($w);$x+=2)                         // code 128 widths: black border, then white space
$html .= "<td><div class=\"b128\" style=\"border-left-width:{$w[$x]};width:{$w[$x+1]}\"></div>";    
  return "$html<tr><td  colspan=".strlen($w)." align=center><font family=arial size=2><b>$text</table>";        
}
?>
<?php
$test = "12345";
echo '<div style="border:3px double #ababab; padding:5px;margin:5px auto;width:135px;">';
echo bar128(stripslashes($test));
echo '</div>';
?>

【问题讨论】:

  • 为什么不使用 svg 来达到这个目的?
  • @PavelGatnar 我其实对 svg 并不熟悉,但我会试一试

标签: php html css barcode


【解决方案1】:

您没有关闭大部分标签。试试这个:

    $html = "<table cellpadding=0 cellspacing=0><tr>";
    for ($x = 0; $x < strlen($w); $x += 2)                         // code 128 widths: black border, then white space
        $html .= "<td><div class=\"b128\" style=\"border-left-width:{$w[$x]};width:{$w[$x+1]}\"></div></td>";
    return "$html</tr><tr><td  colspan=" . strlen($w) . " align=center><font family=arial size=2><b>$text</b></font></td></tr></table>";

【讨论】:

  • 我试过了,但还是没有出现。我在另一个网站上尝试过,它确实出现了,但样式再次与原来的不同。
猜你喜欢
  • 2014-02-09
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 2016-07-19
  • 1970-01-01
  • 2019-05-06
  • 1970-01-01
相关资源
最近更新 更多