简体   繁体   English

如何使我的网站上的标题图片具有响应性?

[英]How can I make my header pic on my website responsive?

My header pic looks blurry when I resize the screen so how can I fix this?当我调整屏幕大小时,我的标题图片看起来很模糊,我该如何解决这个问题? The height is 300px.高度为 300px。

 .headerpic { width: 100%; max-width: 100%; height: auto; opacity: 0.8; webkit-transform: scaleX(-1); transform: scaleX(-1); background-repeat: no-repeat; background-attachment: fixed; background-position: center; -moz-background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-size: cover; margin: 0 auto; max-height: 300px; }
 <div class="header"> <img class="headerpic" src="via.placeholder.com/1914x540 " alt="English header" sizes="(max-width: 480px) 100vw"> <div class="title"> <h1>English</h1> </div> </div>

If your original image is proper and has the desired dimension, try the following code.如果您的原始图像是正确的并且具有所需的尺寸,请尝试以下代码。 Generally, banner images are provided as background.通常,横幅图像作为背景提供。 There are ways of using them using HTML, but I will provide you a simpler way of achieving the same result.有多种使用 HTML 的方法,但我将为您提供一种更简单的方法来实现相同的结果。

.header {
  height: auto;
  min-height: 200px;
  max-height: 300px;
  /*Note - If the image doesn't appear, try correcting its path as per your project setup */
  background: center url('images/header.jpg') no-repeat;
  background-size: cover;
  /* background-attachment: fixed; // not required */
}
<div class="header">
  <!-- <img class="headerpic" src="images/header.jpg" alt="English header"/> -->
  <div class="title">
    <h1>English</h1>
  </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM