为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我让隐藏的文字块显示在原本位置的右边不行,显示在左边就可以?具体疑问见代码注释

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>

        div{
            float: left;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        div a{
            display: block;
            position: relative;
            z-index: 0;
            height: 170px;
            margin-bottom: 10px;
        }
       div a span{
            position: absolute;
            width:300px ;
            height: 170px;
            right: 104%;/*若改为left:104%,就显示不出来了好像是被覆盖了*/
            top: 0px;
            background:gray ;
           z-index: 22;
           color: white;
           line-height: 40px;
           text-align: center;
           filter:alpha(Opacity=50);/*IE6*/
           -moz-opacity: 0.5;
           opacity: 0.5;
           -khtml-opacity:0.5;
           -webkit-opacity:0.5;
           display: none;
           border: solid 4px #ff5500;
           box-sizing:border-box;
           margin-bottom: 10px;
        }

    </style>
</head>
<body>
         <div id="li1">
             <a>
                 <img src="img/2.jpg">
                 <span>这是透明1</span>
             </a>
         </div>
         <div id="li2">
             <a>
                 <img src="img/1.jpg">
                 <span>这是透明2</span>
             </a>
         </div>
         <div id="li4">
             <a>
                 <img src="img/3.jpg">
                 <span>这是透明3</span>
             </a>
         </div>
         <div id="li5">
             <a>
                 <img src="img/1.jpg">
                 <span>这是透明2</span>
             </a>
         </div>
         <div id="li6">
             <a>
                 <img src="img/3.jpg">
                 <span>这是透明3</span>
             </a>
         </div>
         <div id="li7">
             <a>
                 <img src="img/3.jpg">
                 <span>这是透明3</span>
             </a>
         </div>
         <div id="li8">
             <a>
                 <img src="img/1.jpg">
                 <span>这是透明2</span>
             </a>
         </div>
         <div id="li9">
             <a>
                 <img src="img/3.jpg">
                 <span>这是透明3</span>
             </a>
         </div>
<script>
    function show(){
        var li=document.getElementsByTagName('div');
        for(var i=0;i<li.length;i++){
            if(i%4==0) {
                li[i].getElementsByTagName('span')[0].style.right = "-104%";
            }
        }
        for(var i=0;i<li.length;i++){
                li[i].onmouseover = function () {
                    this.getElementsByTagName('span')[0].style.display = 'block';
                }
                li[i].onmouseout = function () {
                    this.getElementsByTagName('span')[0].style.display = 'none'
                }
        }
    }
    show()
</script>
</body>
</html>


正在回答

1 回答

不行的话直接改成像素吧 估计不能设置超过100%


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
图片展示特效
  • 参与学习       29139    人
  • 解答问题       81    个

使用JS技术实现图片展示效果效果,让网页增彩是否心动,快快加入我们

进入课程

为什么我让隐藏的文字块显示在原本位置的右边不行,显示在左边就可以?具体疑问见代码注释

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信