开发者社区> 问答> 正文

CSS中怎么让一个div成为遮罩?

也就是说让一个div限定在另一个div的区域里面(类似于css background-image中大尺寸图片定义在小尺寸的div中,图像只显示其在小尺寸div中的部分---但是这里不用background-image,而是换成一个div,就不知道怎么实现了 ╮( ̄  ̄)╭)

比如这个随便写的这个网页,想让 .phone:hover 上移的div只显示其在手机屏幕中的部分

展开
收起
a123456678 2016-03-26 14:04:46 2018 0
1 条回答
写回答
取消 提交回答
  • <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>关注ReSur的微信</title>
    <style type="text/css">
    body {margin: 0;background-color: #FAFAFA;}
    .block {position: relative;margin-top: 275px;width: 100%;height: 195px;background: #00C389;}
    .draw {position: relative;margin: 0 auto;height: 391px;height: 579px;background: url('http://1992s.com/images/wechat-bg.png') no-repeat;}
    .draw_box{margin: 134px 0 0 409px; background:#000; width:219px; height:391px; float:left; overflow:hidden; position:relative;}
    .phone {position: absolute;top: 137px;left:0;width: 219px;height: 391px;text-align: center;background: white;transition: top 1s;-webkit-transition: top 1s;-moz-transition: top 1s;-o-transition: top 1s;}
    .phone:hover {top: 0px;}
    .qrcode {position: relative;top: 87px;margin: 0 auto;width: 165px;height: 165px;background: url('http://1992s.com/images/wechat.png') no-repeat;}
    .text {position: relative;top: 140px;font: 12px "Lucida Grande","Lucida Sans Unicode",Helvetica,Arial,Verdana,sans-serif,"Microsoft YaHei","微软雅黑";}
    </style>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <script type="text/javascript" src="http://1992s.com/wp-content/themes/portfolio-press-child/js/info.js"></script>
    </head>
    <body>
    <div class="block">
        <div class="draw">
            <div class="draw_box">
                <div class="phone">
                    <div class="qrcode"></div>
                    <div class="text">
                        <p>或在“查找公众号”<br />中搜索“ReSur”</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </body>
    </html>
    2019-07-17 19:16:07
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
零基础CSS入门教程 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载