php - 将不同的类添加到标签和值并在同一行输出
问题描述
我正在尝试向标签和值添加不同的类,以便我可以对它们进行不同的样式设置,但需要做两件事。
- 添加一条在两者下方延伸的边框底部线
- 在同一行显示标签名称和值
这是我正在使用的 PHP
$output .= '<div class="property-details">';
foreach ( (array) $this->property_details as $label => $key ) {
$output .= sprintf( '<div class="label">%s</div><div class="value">%s</div>', $label, $value ) );
}
$output .= '</div>';
return $output;
这给了我这个:
价格:
10,000,000
我需要的是这个
价格:10,000,000
名称:价值
所以每个标签和值都内联显示
解决方案
尝试这个..
$output .= '<div class="property-details">';
foreach ( (array) $this->property_details as $label => $key ) {
$output .= sprintf( '<div class="label" style="display: inline-block;">%s</div><div class="value" style="display: inline-block;">%s</div>', $label, $value ) );
}
$output .= '</div>';
return $output;
尽管除非您使用像 Bootstrap 这样的库,否则我鼓励您span
改用:
$output .= '<div class="property-details">';
foreach ( (array) $this->property_details as $label => $key ) {
$output .= sprintf( '<span class="label" >%s</span ><span class="value">%s</span >', $label, $value ) );
}
$output .= '</div>';
return $output;
对多行使用br
标签:
$output .= '<div class="property-details">';
foreach ( (array) $this->property_details as $label => $key ) {
$output .= sprintf( '<span class="label" >%s</span ><span class="value">%s</span > <br>', $label, $value ) );
}
$output = substr_replace($output , '', strrpos($output , '<br>'), 4);
$output .= '</div>';
return $output;
推荐阅读
- search - 3 年后,我的站点地图中有 1338 个 URL 的网站仍然在 Search Console 中显示 1232 个页面“已抓取 - 当前未编入索引”。这是正常的吗?
- javascript - 作曲家更新 - magento-cloud-metapackage - 您的要求无法解决为一组可安装的软件包
- python - 将python代码拆分为不同的文件
- javascript - 如何在脚本中添加谷歌标签管理器
- javascript - 如何在全屏点击中关闭模态
- nginx - nginx端口跳转返回错误码502
- sql - 将日期与计算的 DATEADD 日期匹配
- ios - 使用 CMAKE CHECK_FUNCTION_EXISTS 时如何禁用 BITCODE
- javascript - 无法将 EJS 文件呈现为对 POST 请求的响应
- arrays - 排序numpy数组