在一个表中想要包括销售价格,但它插入到一个新的单元格中,而不是相同的


in a table want to include sale price but it inserts into a new cell and not the same

我实际上并不是在使用表格,我使用的是列表,而是将其格式化为表格,但我遇到了一个问题,我想在同一单元格中包含销售价格和原始价格,但如果我将它们放在div中,它会将它们拆分为两个单元格。

       for($z =0; $z < 4; $z++ )
                {
                     if($i+$z >= count($varProduct))
                     {  break;} 
                    if ($varProduct[$z+$i][11] > 0)
                    {
                    echo                  
                    '<div class = "salePrice"> SALE $' . $varProduct[$z+$i][11] . '&nbsp; </div>' . '<div class ="originalPrice"> $' . $varProduct[$z+$i][2] . '</div>'
                    ;   
                    }                       
                }   

我以为既然是一个回声,那就是一个细胞,但它增加了两个,有办法绕过这一点吗?

编辑:my.css

.originalPrice{
font-size:14px;
float:left;
color:black;
text-decoration: line-through;
width:317px;
margin-right:0px;
margin-left:0px;
text-align: center;
margin-bottom:20px;
}
.salePrice{
font-size:14px;
float:left;
color:red;
width:317px;
margin-right:0px;
margin-left:0px;
text-align: center;
margin-bottom:20px;

}

在您的CSS中,您应该有这样的东西:

.salePrice { display:inline-block; }
.originalPrice{ display:inline-block; }

如果您将其格式化为"表格",则可能需要在每个DIV元素的CSS内部提供一个宽度或一些填充,以使用户更容易阅读它。

您也可以使用内联属性(如果您针对最常见的做法进行选择):

 for($z =0; $z < 4; $z++ )
                {
                     if($i+$z >= count($varProduct))
                     {  break;} 
                    if ($varProduct[$z+$i][11] > 0)
                    {
                    echo                  
                    '<div class = "salePrice" style="display:inline-block;"> SALE $' . $varProduct[$z+$i][11] . '&nbsp; </div>' . '<div class ="originalPrice;" style="display:inline-block"> > $' . $varProduct[$z+$i][2] . '</div>'
                    ;   
                    }       

            }   

如果选择使用浮动,也可以浮动div元素。

.salePrice { float:left; }
.originalPrice{ float:left; }

只要确保你使用一个浮动:清除;在最后一个元素的CSS中。