【问题标题】:Responsive Background?响应式背景?
【发布时间】:2021-01-11 20:51:30
【问题描述】:

如何将附加的背景集成到响应式网站中?还有一个附加的移动视图和背景。

我曾尝试将它作为 SVG 图形,但效果不佳,因为它总是奇怪地缩放并且没有响应。 CSS中的“clip-path”也对我不起作用。

还有一个PNG/JPG图像不好,因为质量不好或文件太大。

如何显示这个绝对响应的背景?如果可能,它应该可以在手机上显示,但也可以在 4k (8k) 上显示。

我期待任何答案!

图片:https://drive.google.com/drive/u/0/folders/1olJcDIMsbi2mAEbbr9vyf9n74ENaMeWB

【问题讨论】:

标签: html css responsive-design background responsive


【解决方案1】:

看看这个可能会有所帮助

img {
width: 30%;
display: inline-block
}
body {
background-image: url(https://i.ibb.co/SPBfZxS/bg1-1.png);
background-size: cover;
color: white;
}
button {
  padding: 10px 20px;
    background: #2BBBAD; 
    color: white;
    border: 0;
    font-size: 15px;
    box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
    cursor: pointer;
    border-radius: 4px;
    outline: 0;
    text-transform: uppercase;
    user-select: none;
    transition: all .2s;
}
@media only screen and (max-width: 600px) {
img {
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.hero-image {
  background-image: url("/w3images/photographer.jpg");
  background-color: #cccccc;
  height: 400px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}

.hero-text {
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}
</style>
</head>
<body>

<div class="hero-image">
  <div class="hero-text">
    <h1 style="font-size:50px">I am [YOUR_NAME_HERE]</h1>
    <h3>[INSERT_TAGLINE_HERE]</h3>
    <button>Button</button>
  </div>
</div>
<div style="padding:20px">
<p>Page content..</p>
<img src="https://via.placeholder.com/300x200">
<img src="https://via.placeholder.com/300x200">
<img src="https://via.placeholder.com/300x200">
<img src="https://via.placeholder.com/300x200">
</div>
</body>
</html>
基本上,您需要使用@media 选择器
@media only screen and (max-width: 600px) {
img {
width: 100%;
}

【讨论】:

  • 非常感谢!但这是 SVG... 图形的问题。如果我让网站像手机一样变窄,您无需向下滚动即可看到页脚。因为图形总是以全尺寸显示。这意味着它的长度必须始终为 100%,但从左 + 右截断。或者我必须为每个更窄的尺寸创建一个新图像。使用媒体查询?
  • 好的,只需在 SVG 周围包裹一个父 div。然后它会工作
  • 像这样:&lt;div class="image"&gt;&lt;svg&gt;&lt;/svg&gt; &lt;/div&gt;
  • 和@media 规则:@media only screen and (max-width: 600px) { .image { width: 100%; }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-02
  • 2016-07-02
  • 2019-05-15
  • 2015-11-24
  • 2015-04-12
  • 2015-04-09
  • 1970-01-01
相关资源
最近更新 更多