html - 使背景图像响应

标签 html css responsive-design

我正在编写一个即将推出的页面,它在桌面模式下运行良好!但在手机中,图像的一些艺术作品被隐藏了,

在移动 View 中,它看起来像这样: enter image description here

你可能会注意到,在移动 View 中,它隐藏了艺术品的某些部分

但它在桌面模式下效果很好:

enter image description here

这是我的完整片段:

<!DOCTYPE html>
<html>
  <head>
    <title>HOME: </title>
  </head>
<style>
body, html {
  height: 100%;
  margin: 0;
}

.bgimg {
  background-image: url('bg12.png');
  height: 100%;
  max-width: 100%;
  background-position: center;
  background-size: cover;
  position: relative;
  color: black;
  font-family: KhmerUI;
  src: url(KhmerUI.ttf);
  font-size: 25px;
}

.topleft {
  position: absolute;
  top: 0;
  left: 16px;
}

.bottomright {
  position: absolute;
  top: 0;
  right: 30px;
}

.middle {
  position: absolute;
  top: 50%;
  left: 70%;
  transform: translate(-50%, -50%);
  text-align: center;
}

hr {
  margin: auto;
  width: 40%;
}
</style>
<body>

<div class="bgimg">
  <div class="topleft">
    <img src="loDgo-2.png" alt="logo" style="width:150px;height:120px;">
  </div>
  <div class="middle">
    <h1>COMING SOON</h1>
    <hr>
    <p>STAY TUNED</p>
  </div>
  <div class="bottomright">
    <p>Powered By</p>
    <img src="cropD-3.png" style="width:150px;height:50px;">
    <div></div>
  </div>
</div>

</body>
</html>

这是我的背景图片:

enter image description here

谁能帮我修复移动 View ,我需要图像的艺术作品看起来像我看到的桌面模式。艺术品藏不住

最佳答案

一种解决方案是将样式更新为:

.bgimg {
  background-image: url('bg12.png');
  height: 100%;
  max-width: 100%;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  position: relative;
  color: black;
  font-family: KhmerUI;
  src: url(KhmerUI.ttf);
  font-size: 25px;
}

为了进一步自定义图像的位置,您使用媒体查询在 background-position 上尝试不同的选项

在此处查看更多信息: CSS background-size cover and background-position

这里: https://www.w3schools.com/cssref/pr_background-position.asp

关于html - 使背景图像响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58004247/

相关文章:

jquery - 如何在视口(viewport)中启动 CSS3 动画

html - 是否可以制作每行具有不同数字列和列宽的 CSS3 表格?

html - 单击缩略图后不会保留大图像。仅限 HTML 和 CSS

php - 内容和页脚空间问题

javascript - 使用 jquery 将外部 css 样式表应用于动态添加的 html 内容

html - 如何根据元素的数量使 div 位置响应?

javascript - 如何限制在 html 选择框中选择的选项?

javascript - Webpack + SASS + Autoprefixer 不生成 CSS 文件

html - 不同的布局与一个响应式布局来处理不同的设备尺寸和方向

html - 样式标签中 CSS 的顺序