【css】backgroud-position控制背景图位置

概述

background-position 用来设置背景图像起始位置的CSS样式属性

| |
|–|–|
| | |

属性

使用值

描述
x轴:left right center 默认值: left top
y轴:top bottom center 可以使用两个值,也可以使用一个值,当使用一个值另一个默认为center

使用百分比

描述
x% y% 第一个值是水平位置,第二个值是垂直位置。

css——backgroud-position控制背景图位置

例子代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>背景图position设置图片位置</title>
        <style>
            .card{
                display: inline-block;
                padding: 8px;
                height: 400px;
                width: 600px;
                border: 1px solid #efefef;
                margin: 0 30px;
               
                background-color: #efefef;

                background-repeat: no-repeat;

                /*
                使用background-position 来设置背景图像的位置
                    x轴:left right center
                    y轴: top  bottom center
                    默认值: left top

                    可以使用两个值,也可以使用一个值,当使用一个值另一个默认为center
                */
                background-position: right center;

                background-position: right bottom;

                background-position: center;
                
            }
            .card1{
                background-image: url('image/1.jpg');
            }
            .card2{
                background-image: url('image/2.jpg');
            }
        </style>
    </head>
    <body>
        <h1>设置图片位置</h1>
        <div class="card card1">
            
        </div>
        <div class="card card2">
            
        </div>
    </body>
</html>

相关推荐

  1. 【css】backgroud-position控制背景位置

    2024-04-08 13:00:03       32 阅读
  2. fabricjs控制背景和画布图片展示

    2024-04-08 13:00:03       36 阅读
  3. Android自由控制阴影位置

    2024-04-08 13:00:03       31 阅读
  4. R语言中ggplot2图例位置、颜色、背景、标题

    2024-04-08 13:00:03       45 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-08 13:00:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-08 13:00:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-08 13:00:03       82 阅读
  4. Python语言-面向对象

    2024-04-08 13:00:03       91 阅读

热门阅读

  1. windows 环境下docker打包python项目

    2024-04-08 13:00:03       40 阅读
  2. 基于单片机的风向风速传感器防冻装置设计

    2024-04-08 13:00:03       34 阅读
  3. 网络入门基础

    2024-04-08 13:00:03       29 阅读
  4. ISBN信息查询api接口

    2024-04-08 13:00:03       38 阅读
  5. 【云开发笔记NO.25】缓存和技术中台

    2024-04-08 13:00:03       31 阅读
  6. SpringBoot 使用redis

    2024-04-08 13:00:03       32 阅读
  7. 这个开源项目,支持中文版啦~

    2024-04-08 13:00:03       33 阅读
  8. SSL根证书是什么

    2024-04-08 13:00:03       38 阅读
  9. Vue3_2024_10天【Vue2和Vue3父传子,使用props的区别】

    2024-04-08 13:00:03       38 阅读