需求效果一行3栏:
场景模拟:同事给了我这么一段静态代码如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<!doctype html>
<html lang= "en" >
<head>
<meta charset= "utf-8" >
<title>document</title>
</head>
<style>
li,ul{padding: 0;margin:0;list-style: none;}
.box{
width:1000px;background: #ddd;height:500px;
}
.box li{margin:0 50px 20px 0;background:red;height:30px;width:300px;float: left;}
</style>
<body>
<div class = "box" >
|
可是动态读取是统一的呀?宽度不够咋办捏?错误的换行效果并不是我们想要的!
解决方案一:样式加宽隐藏
?
1
2
3
4
5
6
7
8
|
<style>
li,ul{padding: 0;margin:0;list-style: none;}
.box{
width:1000px;background: #ddd;height:500px;overflow: hidden;
}
.box ul{width: 1200px;}
.box li{margin:0 50px 20px 0;background:red;height:30px;width:300px;float: left;}
</style>
|
预览正常:
?
1
2
3
4
5
6
7
8
9
10
11
12
|
<div class = "box" >
<ul>
<?php
//列数
$col =3;
for ( $i =0; $i <9; $i ++){
$margin_r = (( $i % $col )==( $col -1))? "margin-right:0;" : "" ; //清除每行最右侧宝贝右边距
echo '<li style="' . $margin_r . '">' . $i % $col . '</li>' ;
}
?>
</ul>
</div>
|
方案一和方案二都是可以实现一样的效果!
以上这篇php动态读取数据清除最右边距的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 81
-
2025-06-04 37
-
Java基于动态规划法实现求最长公共子序列及最长公共子字符串示例
2025-05-29 78 -
2025-05-29 73
-
2025-05-29 42
热门评论