<a> tag is not displayed if Empty</a>

时间:2011-09-23 20:06:06

标签: html css

如果浏览器为空,则不会显示以下PHP echo语句的标记。在IE9上找到了这个。

echo ' <div id="'.$url['ID'].'" class="link"> '
    .'<img class="link_handle" src="http://www.google.com/s2/favicons?domain='.$urlico.'" align="middle" />'
    .'&nbsp;'
    .'<a href="'.$url->URL.'" target="_blank" onmouseOver="preview_link(\'show\', this, \''.$node['ID'].'\');" onmouseOut="preview_link(\'hide\', this, \''.$node['ID'].'\');" >'.$url->TITLE.'</a> '
    .'<a href="#" title="Edit" class="link_button_edit" onClick=""> </a>'
    .'<a href="#" title="Delete" class="link_button_delete" onClick="delete_link(\''.$url['ID'].'\');"> </a> '
    .'</div>';

最后两个标签用于图像。除非我在<a> </a>中有文字,否则它们会被忽略。为什么会这样。

图像是在这些CSS样式中定义的。

.link .link_button_edit {
   background: url("/icodeact/Edit16.png") no-repeat;
   background-size: 50%;
   cursor: pointer;
   vertical-align: bottom;
}
.link .link_button_delete {
   background: url("/icodeact/Delete16.png") no-repeat;
   background-size: 50%;
   cursor: pointer;
   vertical-align: bottom;
}

为什么会这样?

2 个答案:

答案 0 :(得分:8)

默认情况下,<a>标记的“显示”值为“内联”,因此如果没有内容,则不应显示任何内容。

如果您希望它显示背景图像,您应该将其设为块并为其指定尺寸(宽度和高度)。这应该可以解决你的问题...

答案 1 :(得分:0)

完成设置空<a>标记的最简单方法是将其包装在您希望它的链接宽度和高度的容器中,并为其指定position:relative;然后您可以设置<a>标记属性为width:100%; height : 100%; display:block;,最终应与其父级相同。

相关问题