php - 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.
解决方案
只需打开和关闭 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 属性,我更改为top
and left
。div
标签也不支持href
属性。
推荐阅读
- php - 检查来自api php的数组中的值是否增加
- sql - 从日期表中选择每周数据
- java - android - 为什么 MediaPlayer 延迟播放 mp3 音频?
- dart - 使用 getter 和 setter 从 1-7 个整数创建字符串
- excel - 带有转置编译错误的复制粘贴
- sql-server - 为没有实例名称的连接设置 SQL Server
- node.js - 为什么我的 jenkins 服务器不能运行 NPM 安装?
- javascript - Angular Datepicker更改日期格式
- c - 构建 Wireshark 时的错误和警告
- sql-server - 触发扩展属性?SQL 服务器