实现css3便签列表,要求便签的标题和内容需要从本地存储中进行读取,有12个标签,第一行有六个,第二行有六个,通过nth-child选择器实现对便签的背景色和字体颜色控制,标签有旋转、阴影效果,并且鼠标箭头移上便签时标签有放大过渡效果
时间: 2024-01-30 14:02:07 浏览: 100
CSS3别针纸网页便签纸特效
好的,这是一个关于CSS3的问题。实现CSS3便签列表的方法如下:
HTML结构:
```
<div class="note-list">
<ul>
<li>
<h2>Title 1</h2>
<p>Content 1</p>
</li>
<li>
<h2>Title 2</h2>
<p>Content 2</p>
</li>
...
</ul>
</div>
```
CSS样式:
```
.note-list ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
.note-list li {
width: calc(50% - 10px);
margin: 5px;
padding: 20px;
background-color: #fff;
color: #333;
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
border-radius: 10px;
transition: all 0.2s ease-in-out;
transform-origin: center bottom;
position: relative;
z-index: 1;
}
.note-list li:hover {
transform: scale(1.05);
z-index: 2;
}
.note-list li:nth-child(2n+1) {
background-color: #f6f6f6;
}
.note-list li:nth-child(2n+1) h2 {
color: #333;
}
.note-list li:nth-child(2n+1) p {
color: #666;
}
.note-list li:nth-child(2n) {
background-color: #e6e6e6;
}
.note-list li:nth-child(2n) h2 {
color: #888;
}
.note-list li:nth-child(2n) p {
color: #aaa;
}
.note-list li:before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
background-color: #fff;
transform: skew(-20deg) rotate(-8deg);
box-shadow: -3px 3px 6px rgba(0, 0, 0, 0.16);
}
.note-list li:nth-child(4n+1):before {
background-color: #f6f6f6;
}
.note-list li:nth-child(4n+2):before {
background-color: #e6e6e6;
}
.note-list li:nth-child(4n+3):before {
background-color: #f6f6f6;
}
.note-list li:nth-child(4n+4):before {
background-color: #e6e6e6;
}
.note-list h2 {
margin: 0;
font-size: 18px;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
transform: rotate(-5deg);
text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.16);
z-index: 1;
position: relative;
}
.note-list p {
margin: 0;
font-size: 14px;
line-height: 1.5;
transform: rotate(-5deg);
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.16);
}
```
这里用了CSS3的伪元素(`:before`)来实现标签的旋转和阴影效果。同时通过`nth-child`选择器实现对便签的背景色和字体颜色控制。鼠标箭头移上便签时,通过`hover`选择器实现标签的放大过渡效果。在JS代码中,需要从本地存储中读取便签的标题和内容。
阅读全文