首页 > 解决方案 > 如何对齐背景图像中心

问题描述

我正在尝试添加背景图像中心,但我无法做到我已经尝试了所有方法但无法做到。这是我尝试过的代码

<a href="#" style="background-position:center center;">
      <img src="https://firebasestorage.googleapis.com/v0/b/growthfilepractice.appspot.com/o/ownerCampaign.jpg?alt=media&token=846535ef-b1c7-4063-aace-6e0843f9d001" style="width:800px;height:800px">
    </a>

    <a href="#">
      <img src="https://firebasestorage.googleapis.com/v0/b/growthfilepractice.appspot.com/o/ownerCampaign.jpg?alt=media&token=846535ef-b1c7-4063-aace-6e0843f9d001" style="width: 800px;height: 800px;background-repeat: no-repeat;
      background-attachment: fixed;
      background-position: center; ">
    </a>

标签: htmlcss

解决方案


你需要添加一些样式

    a {
      width: 800px;
      height: 800px;
      background-repeat: no-repeat;
      background-image: url('https://firebasestorage.googleapis.com/v0/b/growthfilepractice.appspot.com/o/ownerCampaign.jpg?alt=media&token=846535ef-b1c7-4063-aace-6e0843f9d001');
      background-position: center;
    }

推荐阅读