当 PHP 函数构建表格时,是什么阻止了 CSS 正确格式化表格?
我有一个在我的网络应用程序上动态构建的表。行数和行内内容由一系列 PHP 函数决定。
一旦确定了这一点,他们就会调用另一组 PHP 函数来创建各个表行并包含类来定义它们的外观。尽管我的应用程序上的其他地方都有工作表,但我不明白为什么我无法获得适用于该表的标准和格式。输出被排序到表格中,但我无法更改字体大小、最小宽度、背景颜色或任何内容。
如果有人能指出我的问题,我将不胜感激!
这是确定结构的 PHP 函数:
// Determines the core number of buckets and the appropriate general structure for tree
function drawFullTree ($hyp, $b_count, $sb_count, $b, $sb)
{
// loop through *all* buckets
// if any bucket has no-sub buckets, put three (blanks) in it
for($i = 0; $i < $b_count; $i++){
if(!isset($sb[$i])){
$sb[$i][0] = '(blank)';
$sb[$i][1] = '(blank)';
$sb[$i][2] = '(blank)';
}
}
echo '<table class="answer">';
if($b_count > 0){
if(isset($sb[0])){
drawBuc_Sub($b[0], $sb[0]);
}
else{
echo 'sub-bucket blank';
}
}
if($b_count == 0){
echo 'What! No buckets - lets turn up the effort here!';
}
else if($b_count == 1){
echo "One bucket! Ok, it's a start... keep 'em coming";
}
else if($b_count == 2){
drawTop_Hyp_Buc_Sub($hyp, $b[1], $sb[1]);
}
else if($b_count == 3){
drawHyp_Buc_Sub($hyp, $b[1], $sb[1]);
drawBuc_Sub($b[2], $sb[2]);
}
else if($b_count == 4){
drawBuc_Sub($b[1],$sb[1]);
writeHyp($hyp);
drawBuc_Sub($b[2],$sb[2]);
drawBuc_Sub($b[3],$sb[3]);
}
else if($b_count == 5){
drawBuc_Sub($b[1],$sb[1]);
drawHyp_Buc_Sub($hyp, $b[2],$sb[2]);
drawBuc_Sub($b[3],$sb[3]);
drawBuc_Sub($b[4],$sb[4]);
}
else if($b_count == 6){
drawBuc_Sub($b[1],$sb[1]);
drawBuc_Sub($b[2],$sb[2]);
writeHyp($hyp);
drawBuc_Sub($b[3],$sb[3]);
drawBuc_Sub($b[4],$sb[4]);
drawBuc_Sub($b[5],$sb[5]);
}
echo '</table>';
}
这是一个 PHP 函数的示例,我无法正确应用格式:
function writeHyp_Buc_Sub ($hyp, $buc, $sub)
{
echo '<tr>';
echo '<td class="x">' . $hyp . '</td>';
echo '<td class="x">' . $buc . '</td>';
echo '<td class="x">' . $sub . '</td>';
echo '</tr>';
}
这是我拥有的 CSS:
table{
border-collapse: collapse;
}
td
{
font-size:.80em;
color: #333333;
padding: 6px 4px;
text-align:left;
/*border-bottom: 1px dotted #cccccc;*/
}
table.answer{
background-color:green;
border:3px black;
}
td.x
{
width:230px;
font-size:1.1em;
border:2px solid black; /*#DCDCDC; */
}
调用 php 函数并将其插入页面的 jquery:
$('#process_structure').live('click', function () {
var postData = $('#inputs_structure').serializeArray();
postData.push({name: 'count', value: count});
$('#testing').fadeOut('slow');
$.ajax ({
type: "POST",
url: "structure_process.php",
data: $.param(postData),
success: function(text){
$('#testing').fadeIn('500', function(){
$('#testing').html(text);
})
}
});
$(this).parent().html('<form action="structure.php"><button class="begin_mod_button">Do another!</button></form>');
clearInterval(interval);
return false;
});
I have a table that is built dynamically on my web app. The number of the rows and contents within rows is determined by a series of PHP functions.
Once this is determined, they call another set of PHP functions that create the individual table rows and contain classes to define how they should look. Despite having working tables everywhere else on my app, I can't figure out why I can't get standard and formatting to work for this table. The output is ordered into a table but I can't change font size, min-width, background color or anything.
If someone could point out my problem, that would be greatly appreciated!
Here is the PHP function that determines structure:
// Determines the core number of buckets and the appropriate general structure for tree
function drawFullTree ($hyp, $b_count, $sb_count, $b, $sb)
{
// loop through *all* buckets
// if any bucket has no-sub buckets, put three (blanks) in it
for($i = 0; $i < $b_count; $i++){
if(!isset($sb[$i])){
$sb[$i][0] = '(blank)';
$sb[$i][1] = '(blank)';
$sb[$i][2] = '(blank)';
}
}
echo '<table class="answer">';
if($b_count > 0){
if(isset($sb[0])){
drawBuc_Sub($b[0], $sb[0]);
}
else{
echo 'sub-bucket blank';
}
}
if($b_count == 0){
echo 'What! No buckets - lets turn up the effort here!';
}
else if($b_count == 1){
echo "One bucket! Ok, it's a start... keep 'em coming";
}
else if($b_count == 2){
drawTop_Hyp_Buc_Sub($hyp, $b[1], $sb[1]);
}
else if($b_count == 3){
drawHyp_Buc_Sub($hyp, $b[1], $sb[1]);
drawBuc_Sub($b[2], $sb[2]);
}
else if($b_count == 4){
drawBuc_Sub($b[1],$sb[1]);
writeHyp($hyp);
drawBuc_Sub($b[2],$sb[2]);
drawBuc_Sub($b[3],$sb[3]);
}
else if($b_count == 5){
drawBuc_Sub($b[1],$sb[1]);
drawHyp_Buc_Sub($hyp, $b[2],$sb[2]);
drawBuc_Sub($b[3],$sb[3]);
drawBuc_Sub($b[4],$sb[4]);
}
else if($b_count == 6){
drawBuc_Sub($b[1],$sb[1]);
drawBuc_Sub($b[2],$sb[2]);
writeHyp($hyp);
drawBuc_Sub($b[3],$sb[3]);
drawBuc_Sub($b[4],$sb[4]);
drawBuc_Sub($b[5],$sb[5]);
}
echo '</table>';
}
Here is an example of a PHP function where I can't get formatting applied correctly:
function writeHyp_Buc_Sub ($hyp, $buc, $sub)
{
echo '<tr>';
echo '<td class="x">' . $hyp . '</td>';
echo '<td class="x">' . $buc . '</td>';
echo '<td class="x">' . $sub . '</td>';
echo '</tr>';
}
And here is the CSS I have:
table{
border-collapse: collapse;
}
td
{
font-size:.80em;
color: #333333;
padding: 6px 4px;
text-align:left;
/*border-bottom: 1px dotted #cccccc;*/
}
table.answer{
background-color:green;
border:3px black;
}
td.x
{
width:230px;
font-size:1.1em;
border:2px solid black; /*#DCDCDC; */
}
the jquery that calls the php functions and inserts it into page:
$('#process_structure').live('click', function () {
var postData = $('#inputs_structure').serializeArray();
postData.push({name: 'count', value: count});
$('#testing').fadeOut('slow');
$.ajax ({
type: "POST",
url: "structure_process.php",
data: $.param(postData),
success: function(text){
$('#testing').fadeIn('500', function(){
$('#testing').html(text);
})
}
});
$(this).parent().html('<form action="structure.php"><button class="begin_mod_button">Do another!</button></form>');
clearInterval(interval);
return false;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的css是在html文档的头部吗?如果不是,那可能是问题所在...如果您使用的是 IE<=7(也可能是较新的版本),我很确定这就是解决方案。 IE 仅在页面加载时渲染 css...如果 css 不在 head 部分,则内联 css 不会应用于插入 dom 中的新内容。
因为 php 是函数,我猜它们输出正确的 html (您可能在其他地方使用它们)。所以唯一可能出错的事情(考虑上面的声明)是你的 html/css “绑定”。
is your css in the head of the html document? if not that might be the problem... if you're using IE<=7 (maybe newer versions too) I'm pretty sure this is the solution. IE only renders css on pageload... inline css is not applied on new things inserted in the dom if the css is not in the head section.
since the php are functions I guess they output correct html (you are probably using them elsewhere). so the only thing that can be wrong (considered the statement above) is your html/css "binding".