GithubHelp home page GithubHelp logo

blog's People

Contributors

xiaoqiang730730 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

blog's Issues

巧妙使用border 配合blackground-orgin 来做背景定位

share
这是个普通的设计图,采用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;
    } 

最终达到效果。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.