如何让多个行内元素(如span li a)在固定宽度的div里均匀排列?行内元素个数根据后台有改变!
2个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index10</title>
<script src="js/jquery-2.0.3.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
var num = $('.box span').length; //获取一共有几个span
$('.box span').css('width',(100/num)+"%"); //计算平均宽度并添加样式
});
</script>
<style>
.box{ width: 600px; height: 50px;}
.box span{ display: block; float: left; height: 50px; background: #0C00FF; color: #fff; text-align: center; line-height: 50px;}
</style>
</head>
<body>
<div class="box">
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
</div>
</body>
</html>
我是用jquery写的,别忘了调用jquery包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询