【问题标题】:How to align background image center [duplicate]如何对齐背景图像中心[重复]
【发布时间】:2020-08-05 04:20:09
【问题描述】:

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

<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>

【问题讨论】:

    标签: html css


    【解决方案1】:

    我假设您的目标是使图像居中。这很容易,只需这样做:

    .img-wrapper{
      text-align: center;
    }
    <div class="img-wrapper"><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">
    </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;">
      </a></div>

    【讨论】:

      【解决方案2】:

      你需要添加一些样式

          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;
          }
      

      【讨论】:

        猜你喜欢
        • 2013-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-31
        • 2011-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多