如何去掉最后一个li的右边距

智障青年 2016-02-20 01:52:10
li 的css样式的右边距都是20;一行显示4个li,想请教大神一下如何去掉最后一个li的右边距。
...全文
781 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
top慢慢 2016-02-29
  • 打赏
  • 举报
回复 1
.class li:last-child{margin-right:0}
u011151921 2016-02-29
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<style type="text/css">
	div{width:1000px; border:1px solid #f00; overflow:hidden;}
	div ul{margin: 0;padding: 0; overflow:hidden; margin-right:-20px;list-style:none;}
	div ul li{width:235px; float:left; height:235px;margin-right:20px;margin-bottom:20px; background:#ddd;}
</style>
<div>
	<ul>
    	<li>1</li><li>2</li><li>3</li><li>4</li>
    	<li>5</li><li>6</li><li>7</li><li>8</li>
    	<li>9</li><li>10</li><li>11</li><li>12</li>
    </ul>
</div>
</body>
</html>
分三层,最外层设置宽度,第二层不要设置宽度,设置要向右超出多少。第三层就是列表了。
言葉i 2016-02-27
  • 打赏
  • 举报
回复
多个li左浮动,然后用margin间隔开吗? 是这样的话用li+li{margin-left:xxpx;}这种写法
lovebaby 2016-02-26
  • 打赏
  • 举报
回复
可以考虑使用jquery的last设置最后一个元素的样式
Y丶Jonh 2016-02-25
  • 打赏
  • 举报
回复
引用 5 楼 u011189092 的回复:
在CSS中这样写li:last-child{ margin-left:(你需要的数字)px; }
可以的话别忘了给分哦亲
Y丶Jonh 2016-02-25
  • 打赏
  • 举报
回复
在CSS中这样写li:last-child{ margin-left:(你需要的数字)px; }
落泪的只有我 2016-02-22
  • 打赏
  • 举报
回复
楼上正解 。。。。。。。。。
vswen5 2016-02-22
  • 打赏
  • 举报
回复
引用 1 楼 vswen5 的回复:
最后一个li里写 style="margin-left:20px";
那就margin-left:0px,margin-left:40px,margin-left:-20px。自己多试试啊 这么简单的东西
智障青年 2016-02-21
  • 打赏
  • 举报
回复
好像不可以啊
vswen5 2016-02-20
  • 打赏
  • 举报
回复
最后一个li里写 style="margin-left:20px";

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧