在php中使用<div>标签

时间:2015-04-23 21:19:28

标签: html css wordpress

我正在使用WordPress 4.1.2

我有一些php显示小图片左侧的标签列表:

<p align="right"><?php
the_tags( '&#160; ', ' • ', '<a href="https://www.lawlessfrench.com/faq/lessons-by-level/"><img src="https://www.lawlessfrench.com/graphics/icon-files.png" alt="Lawless French Files" width="20" height="30" align="right" hspace="10" border="0"></a>' );
?></p>

我想用精灵替换img:

<div id="icon-files" style="float:right; height:30px; width:20px margin:10px" alt="Lawless French Files"></div>

所以这是我使用的代码:

<?php the_tags( '&#160; ', ' • ', '<a href="https://www.lawlessfrench.com/faq/lessons-by-level/"><div id="icon-files" style="float:right; height:30px; width:20px margin:10px" alt="Lawless French Files"></div></a>' ); ?>

但它不起作用 - 图像下降到下一行,而不是停留在标签的右侧。

在php中使用div标签有一些技巧吗?您可以在https://www.lawlessfrench.com

看到它的实际效果

2 个答案:

答案 0 :(得分:1)

将此粘贴​​粘贴到您的网址:

view-source:https://www.lawlessfrench.com/

代码来源很好:

 <a href ...><div ...></div></a>

当您移除<p>周围的标记时,

<div>代码中的

<p>代码无法正常使用。

查看此处:

Why <p> tag can't contain <div> tag inside it?

  

这与http://www.w3.org/TR/html401/struct/text.html#h-9.3.1,&gt;一致,即P元素&#34;不能包含块级元素(包括P&gt;本身)。&#34;

和:

  

开场<div>代码会自动关闭<p>元素。

只需删除<p>代码。

或使用<span>代码而不是<div>代码。

答案 1 :(得分:0)

不要使用&#34; p&#34;对于你的标签,P将会进入新的行,并使用div。

相关问题