背景图像显示图像的特定部分

问题描述 投票:1回答:3

我在这里有一个image,我只想要一个特定的位置展示什么。但我的工作没有用。我只希望手能够在不裁剪原始image的情况下观看。提前致谢

enter image description here

预期结果

enter image description here

HTML

<div class="banner">
            <h1>できる限り<br>
                自然な形で育てた<br>
                こだわりの野菜です。</h1>
            <h4>生産者/川口太郎・川口久美子さん(安芸市)</h4>
</div>

CSS

.banner{
    background: url(../img/img1.png);
    background-size: 100%;
    padding: 32% 0 5% 6%;
    color: white;
    letter-spacing: 0.1em;
    border-radius: 1%;
}
html css image background-image
3个回答
3
投票

background-sizebackground-position CSS属性的组合。不要忘记你可以使背景大小值大于100%。我会把它扔到它并从那里微调:

.banner{
  background: url(../img/img1.png);
  // background-size takes height and width but shorthand is one value used for both
  background-size: 200%;
  // background-position options include center, cover, and more: https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
  background-position: center center;
}

0
投票

使用CSS剪辑。您可以在页面上裁剪图像,而无需编辑原始图像源文件。

https://www.w3schools.com/cssref/pr_pos_clip.asp


0
投票

看看你想要的图像,我想你可以试试这个:

background-repeat: no-repeat;
background-size: cover;
background-position: top;
© www.soinside.com 2019 - 2024. All rights reserved.