V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ygf0934
V2EX  ›  CSS

如何通过 css 控制图片超过屏幕分辨率仍居中显示,且超出部分不显示(不出现滚动条)

  •  
  •   ygf0934 · Apr 30, 2015 · 7818 views
    This topic created in 4023 days ago, the information mentioned may be changed or developed.

    类似这样的

    <div class="banner">
        <a href="#"><img src="#" alt=""/></a>
    </div>
    
    4 replies    2015-06-29 23:24:37 +08:00
    luckylion
        1
    luckylion  
       Apr 30, 2015
    1:背景形式
    2:通过JS获取可视范围,动态调整图片的maring值
    gonghao
        2
    gonghao  
       Apr 30, 2015
    http://dabblet.com/gist/e191e05066016cb040d4

    可以尝试一下这种方法 :)
    coraline
        3
    coraline  
       Apr 30, 2015
    假设 img 100x100 px,外层设定为 40x40 px
    a {
    position: relative;
    width: 40px;
    height: 40px;
    overflow: hidden;
    }
    img {
    position: absolute;
    left: 50%;
    margin-left: -50px;
    top: 50%;
    margin-top: -50px;
    }
    lifang
        4
    lifang  
       Jun 29, 2015 via Android
    background:url(xxx.png) center center no-repeat;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2631 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 11:52 · PVG 19:52 · LAX 04:52 · JFK 07:52
    ♥ Do have faith in what you're doing.