【发布时间】:2017-02-14 03:14:45
【问题描述】:
我总共有 25 张图片。
我能否以某种方式使用循环来简化自己的工作。我不想像我在下面所做的那样一次又一次地重复相同的代码。
span.boxer1 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 300px;
left: 0;
position: absolute;
top: 0;
width: 275px;
opacity: 0;
}
span.boxer1 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.boxers li:hover span.boxer1 {
opacity: 1;
}
span.boxer2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 300px;
left: 0;
position: absolute;
top: 0;
width: 275px;
opacity: 0;
}
span.boxer2 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.boxers li:hover span.boxer2 {
opacity: 1;
}
span.boxer3 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 300px;
left: 0;
position: absolute;
top: 0;
width: 275px;
opacity: 0;
}
span.boxer3 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.boxers li:hover span.boxer3 {
opacity: 1;
}
span.boxer4 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 300px;
left: 0;
position: absolute;
top: 0;
width: 275px;
opacity: 0;
}
span.boxer4 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.boxers li:hover span.boxer4 {
opacity: 1;
}
【问题讨论】:
-
对所有跨度使用相同的类????或使用其他选择器,例如
ul.boxers li > span??? -
你不能只为
.boxer1、.boxer2、.boxer3使用一个公共类吗?类的想法是它们是可重用的。 -
绝对定位是一种非常糟糕的网页布局方法。它非常不灵活,并且有更好、响应速度更快的选项。查看LearnLayout.com
标签: html css image loops repeat