• ADADADADAD

    css中整个背景居中[ 编程知识 ]

    编程知识 时间:2024-12-24 19:32:05

    作者:文/会员上传

    简介:

    CSS中整个背景居中是一个常见的需求,下面给大家介绍几种实现方式。/* 第一种方式:使用Flex布局 */body {display: flex;justify-content: center;align-items: center;height:

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    CSS中整个背景居中是一个常见的需求,下面给大家介绍几种实现方式。

    /* 第一种方式:使用Flex布局 */body {display: flex;justify-content: center;align-items: center;height: 100vh;background: url(background.jpg);}/* 第二种方式:使用绝对定位 */body {position: relative;height: 100vh;background: url(background.jpg);}.background {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);}/* 第三种方式:使用Grid布局 */body {display: grid;place-items: center;height: 100vh;background: url(background.jpg);}
    css中整个背景居中.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载