响应式PNG图像覆盖在背景图像上?

huangapple go评论49阅读模式
英文:

Responsive PNG image over background image?

问题

我试图制作一个像这样的页面设计:点击

我已经制作了它。问题是,当我更改网页的分辨率时,元素会重叠,背景div和PNG会有不同的行为,一切看起来很糟糕。(我尝试过使用position: absolute(PNG)和position: relative(背景))

英文:

I'm trying to make a page design like this one: click

I made it, actually. Problem is that when I change the resolution of my webpage, the elements overlap, the background div and the PNG acts different and everything looks awful. (I've tried with position: absolute (PNG) and position: relative (background))

答案1

得分: 0

你可以使用background-sizebackground-position CSS 属性。你可以尝试以下方式:

body {
  background-image: url("your-bg-image.jpg");
  background-size: cover;
  background-position: center;
}

.responsive-image {
  background-image: url("your-image.png");
  background-size: contain;
  background-position: center;
  width: 100%;
  height: 100%;
}
英文:

You can use the background-size and background-position CSS properties. You should try this way:

body {
  background-image: url("your-bg-image.jpg");
  background-size: cover;
  background-position: center;
}

.responsive-image {
  background-image: url("your-image.png");
  background-size: contain;
  background-position: center;
  width: 100%;
  height: 100%;
}

huangapple
  • 本文由 发表于 2023年2月9日 03:33:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390861.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定