美文网首页
一种让超大banner图片不拉伸、全屏宽、居中显示的方法

一种让超大banner图片不拉伸、全屏宽、居中显示的方法

作者: 筱筱2019 | 来源:发表于2019-03-04 18:11 被阅读0次

一种让超大banner图片不拉伸、全屏宽、居中显示的方法

现在很多网站的Banner图片都是全屏宽度的,这样的网站看起来显得很大气。这种Banner一般都是做一张很大的图片,然后在不同分辨率下都是显示图片的中间部分。实现方法如下:

<html>

<head>

    <title>Title</title>

    <style>

        .bannerbox {

            width:100%;

            position:relative;

            overflow:hidden;

            height:200px;

        }

        .banner {

            width:3000px; /*图片宽度*/

            position:absolute;

            left:50%;

            margin-left:-1500px; /*图片宽度的一半*/

        }

    </style>

</head>

<body>

    <div class="bannerbox">

        <div class="banner">

            <img src="t1.jpg">

        </div>

    </div>

</body>

</html>

把css中 .bannerbox 中 height 及 .banner 和 width 换成你banner图的大小,然后 .banner 中margin-left 的值改成banner图宽度的一半即可。 

相关文章

网友评论

      本文标题:一种让超大banner图片不拉伸、全屏宽、居中显示的方法

      本文链接:https://www.haomeiwen.com/subject/woquuqtx.html