首页 > 解决方案 > Concatenate a style with a variable

问题描述

Trying to use a variable with style to set a position.

Have researched it, but have yet to find an answer.

<div href="#" id="FabofLifeBox" style="position-top: "+ $ptop; +" position-left: "+$pleft; +" class="zoom">

the $ptop and the $pleft are the variables I am trying to set the position in the style statement.

标签: phphtml

解决方案


只需打开和关闭 PHP 标记,这非常简单。

... your php code ?>

    <div id="FabofLifeBox" style="top:<?php echo $ptop; ?>px;left:<?php echo $pleft; ?>px;" class="zoom">

<?php ...your php code continues

请注意,您在正确的位置打开和关闭 PHP,这是可行的。

ps...position-top并且position-left不是有效的 CSS 属性,我更改为topand leftdiv标签也不支持href属性。


推荐阅读