xiaoqiang730730 / blog Goto Github PK
View Code? Open in Web Editor NEW小强的博客记录一些有用的东西
Home Page: http://xiaoqiang730730.github.io/
小强的博客记录一些有用的东西
Home Page: http://xiaoqiang730730.github.io/
这是个普通的设计图,采用css sprite 进行切图设计
dom结构
<div class="itemShareContainer">
<a class="share_weibo" data-type="weibo"></a>
<a class="share_weixin" data-type="weixin"></a>
<a class="share_qzone" data-type="qzone"></a>
<a class="share_qq" data-type="qq"></a>
<a class="share_qqweibo" data-type="qqweibo"></a>
<a class="share_laiwang" data-type="laiwang"></a>
<a class="share_mogujie" data-type="mogujie"></a>
<a class="share_meilishuo" data-type="meilishuo"></a>
<a class="share_douban" data-type="douban"></a>
<a class="share_renren" data-type="renren"></a>
</div>
.itemShareContainer{
a{
display: inline-block;
width: 80px;
height: 80px;
background-image:url('../img/share.png');
background-repeat: no-repeat;
font-size: 0px;
}
.share_weibo{
}
.share_weixin{
background-position: 0 -80px;
}
.share_qzone{
background-position: 0 -160px;
}
.share_qq{
background-position: 0 -240px;
}
.share_qqweibo{
background-position: 0 -320px;
}
.share_laiwang{
background-position: 0 -400px;
}
.share_mogujie{
background-position: 0 -480px;
}
.share_meilishuo{
background-position: 0 -560px;
}
.share_douban{
background-position: 0 -640px;
}
.share_renren{
background-position: 0 -720px;
}
}
现在是最基本的样式已经完成了,
问题来了,给每个a标签添加距离,跟设计图一样。
一开始我用margin来增加距离,但是用户会存在一个空点击。用户在图标的边缘点击了一下,由于采用的是margin,就有可能没有点击到a,就没有事件响应。这是就要替换掉 margin。
第一种想法
使用padding和 blackground-orgin
blackground-orgin设置成content-box。 但是使用的css sprite ,图片是连接在一起的,padding部分也会出现了背景图片。
这样想法不对
第二种想法
可以改变dom结构,在a标签里添加img标签,这个可以尝试下,但是总觉得改变dom不是最好的选择
第三种想法
在我即将去改变dom的时候,突然灵光一现,border可以尝试一下。
a{
display: inline-block;
width: 80px;
height: 80px;
border: 15px solid #fff;
background-image:url('../img/share.png');
background-repeat: no-repeat;
background-origin: content-box;
font-size: 0px;
cursor: pointer;
}
最终达到效果。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.