遇到有人问如下效果怎么写,一时兴起,自己写一个玩玩。

看到这个样子,首先应该考虑一下 DOM 结构,以我的观点,把DOM结构设计为如下形式:

    <div>
<img src="./img1.png" />
<img src="./img2.png" />
<img src="./img3.png" />
</div>

即,一个 DIV 中包含图片,对于左侧的文字,这里考虑使用 ::before CSS实现。

首先,我们建立整个的 HTML 如下,

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css"></style>
</head>
<body>
<div>
<img src="./img1.png" />
<img src="./img2.png" />
<img src="./img3.png" />
</div>
</body>
</html>

我们将 like 列表的 CSS 样式命名为 like-list, 在 style 标签中添加如下代码:

.like-list {
height: 40px;
width: 300px;
padding: 5px;
border: none;
float: right;
background-color: lightseagreen;
margin-right: 0;
border-radius: 30px 0 0 30px;
}

然后,将样式附加到div,整体代码修改如下:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.like-list {
height: 40px;
width: 300px;
padding: 5px;
border: none;
float: right;
background-color: lightseagreen;
margin-right: 0;
border-radius: 30px 0 0 30px;
}
</style>
</head>
<body>
<div class="like-list">
<img src="./img1.png" />
<img src="./img2.png" />
<img src="./img3.png" />
</div>
</body>
</html>

显示效果如下:

嗯,外层效果出来了,我们再把下面几张图片下载下来,放在和HTML文件相同位置:

刷新浏览器,我们看到如下效果:

图片变得好大,调整一下,添加如下样式:

.like-list> img {
margin: 0;
height: 30px;
width: 30px;
border-radius: 30px;
border: 3px solid white;
margin-left: -15px;
}

再看:

嗯,有点样子了,接下来,添加文本,我们就不多创建DOM节点了,再添加如下CSS:

.like-list::before {
height: 30px;
width: 30px;
content: "Like";
color: white;
position: relative;
top: -15px;
margin-right: 15px;
}

再看效果:

好了,效果出来了,全部代码如下:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.like-list {
height: 35px;
width: 300px;
border-radius: 30px 0 0 30px;
border: none;
float: right;
background-color: lightseagreen;
margin-right: 0;
padding: 5px;
} .like-list > img {
margin: 0;
height: 30px;
width: 30px;
border-radius: 30px;
border: 3px solid white;
margin-left: -15px;
} .like-list::before {
height: 30px;
width: 30px;
content: "Like";
color: white;
position: relative;
top: -15px;
margin-right: 15px;
}
</style>
</head>
<body>
<div class="like-list">
<img src="./img1.png" />
<img src="./img2.png" />
<img src="./img3.png" />
</div>
</body>
</html>

总结一下,这里主要使用了 border-radius CSS设置圆角,用border设置边框,然后使用 margin-left: -15px; 进行了图片堆叠。

最近准备发奋了,要多写些东西分享了,欢迎关注下面公众号,更多文章期待与你相遇:

最新文章

  1. iOS中常用的设计模式
  2. 虚拟机NUMA和内存KSM
  3. c#指定日期格式
  4. paip.提升分词---准确度--常用量词表
  5. redis学习笔记——(4)
  6. zookeeper3.4.6的安装
  7. 论文笔记之:Pedestrian Detection aided by Deep Learning Semantic Tasks
  8. rman--增量备份
  9. Android学习笔记(四)深入探讨Activity
  10. 二分查找里的upper bound与lower bound的实现与分析
  11. 优酷播放器demo
  12. C#整理5——break与continue.及数组
  13. cocopods安装与使用
  14. Egret index.html设置
  15. iOS 懒加载模式
  16. 关于数据库管理系统DBMS--关系型数据库(MySQL/MariaDB)
  17. 1.3 第一个python程序
  18. 【Ansible 文档】【译文】Playbooks 变量
  19. argv[1] 路径问题
  20. [转]pycharm active code

热门文章

  1. zsh &amp; git alias
  2. webpack 5 new features All In One
  3. ReactDOM API All In One
  4. koa-router all in one
  5. html template tag
  6. OpenCV &amp; Web Assembly &amp; Web Worker
  7. Web 安全 &amp; 反爬虫原理
  8. c++ readIntger writeIntger
  9. PAA房产智慧社区:解决社区管理服务的痛点难点
  10. DeFi 热潮下,NGK将成为下一个财富密码