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

标签 html css image background-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%;
}

最佳答案

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

关于html - 背景图像显示图像的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55133964/

相关文章:

javascript - 我想用 rxjs observable 替换 addEventListener

c# - Jquery Accordion : How do I get rid of these scroll bars for good?

html - 如何在包装器中垂直居中 2 个不同高度的 div

ruby-on-rails - 在使用 Google 的网络搜索 API 时,我应该如何提供网站的图像预览?

html - 用于剪贴板访问的 HTML5 API 是否可用?你如何使用它?

Html 表格行宽因内容而异

html - 没有在 <head> 标签中插入 google 字体链接,但我仍然可以使用 Roboto?

html - css如何使列自动填充背景颜色到高度100%

c++ - 如何从 QGraphicsView 保存图像?

JavaScript:如何强制 Image() 不使用浏览器缓存?