html排版(拼图问题)!

html排版(拼图问题)!,第1张

DW里显示的不一定是页面的实际效果~而且DW自动生成的样式的可编辑性比较差,而且代码比较复杂~建议你学一下css+div布局~

至于你说的站的背景是用几张图片拼成的,其实一般都是一张图片用ps或者fireworks切出来的,里面有个切片功能~

 <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

    <style>

        div div {

            width: 30px

            height: 30px

            display: inline-block

            border: 1px solid black

            background-repeat: no-repeat

            background-size: 300% 300%

        }

        #img1 {

            background-position: top left

        }

        #img2 {

            background-position: top

        }

        #img3 {

            background-position: top right

        }

        #img4 {

            background-position: center left

        }

        #img5 {

            background-position: center

        }

        #img6 {

            background-position: center right

        }

        #img7 {

            background-position: bottom left

        }

        #img8 {

            background-position: bottom

        }

        #img9 {

            background-position: bottom right

        }

    </style>

</head>

<body>

    <div>

        <div id="img1"></div>

        <div id="img2"></div>

        <div id="img3"></div>

    </div>

    <div>

        <div id="img4"></div>

        <div id="img5"></div>

        <div id="img6"></div>

    </div>

    <div>

        <div id="img7"></div>

        <div id="img8"></div>

        <div id="img9"></div>

    </div>

    <button>next</button>

</body>

<script>

    let arr = ["http://iconfont.alicdn.com/t/1522400286994.jpg@100h_100w.jpg", "http://iconfont.alicdn.com/t/1510710350863.png@100h_100w.jpg", "http://iconfont.alicdn.com/t/1553563063102.jpg@100h_100w.jpg"]

    let num = 0

    let imgFun = () => {

        document.querySelectorAll("div div").forEach(item => {

            item.style.backgroundImage = 'url(' + arr[num] + ')'

        })

    }

    imgFun()

    document.querySelector("button").onclick = () => {

        if (num < arr.length - 1) {

            num++

        } else {

            num = 0

        }

        imgFun()

    }

</script>

</html>

 请采纳


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11276773.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存