【问题标题】:Header image resize标题图像调整大小
【发布时间】:2017-06-19 01:19:53
【问题描述】:

我需要一些帮助,当我调整窗口大小时,图像的高度或宽度没有调整好,我正在使用 WordPress 主题 27,我使用以下代码来降低高度并删除标题图像中的图像二十七主题。图片相关

.has-header-image .custom-header-media img, 
.has-header-video .custom-header-media video, 
.has-header-video .custom-header-media iframe, 
.has-header-image:not(.twentyseventeen-front-page):not(.home) 
.custom-header-media img {
height: 66% !important;
object-fit: fill !important;
width: 100%;
max-height: 100% !important;
display: block !important;
position: relative !important;
}

#wp-custom-header {
height: 100% !important;
}

【问题讨论】:

  • 尝试将max-width: 100% 添加到img
  • 我的imgmax-width: 100% !important; max-height: 100% !important; display: block !important; position: relative !important; }已经有这个了
  • 不,你不...不在你提供的 CSS 中。

标签: html css wordpress


【解决方案1】:

您可以使用像这样的像素安全地将图像设置为最小宽度和最小高度

img{
    max-width: 420px !important;
    max-height: 270px !important; 
    width:100%
    display: block !important; 
    position: relative !important; 
   } 

要调整图像大小,您可以通过在 head 标签之间添加以下行来使用引导程序,并将 img-responsive 类添加到预期图像。

(由于您使用的是 WORDPRESS,因此您将需要以下内容,因为 WP 已经包含引导程序)

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

这些链接是从 https://www.w3schools.com/bootstrap/bootstrap_get_started.asp 复制而来的,您还可以在其中找到有关如何使用引导程序的非常好的教程。

为了回答您添加的评论, 请使用以下 css 代码并从 div class="wp-custom-header" 中的 html 代码中删除标签,而使用以下 css 代码

.wp-custom-header{
 background-image: url('http://web.ipca.pt/poliempreende/wp-
 content/uploads/2017/05/Logo-IPCA-Poliempreende.png');
 background-repeat:no-repeat;
 background-size: 'find out which size you want';
 }

【讨论】:

  • 但是我尝试max-width: 420px !important; max-height: 270px !important; 图像仍然没有为小窗口(移动窗口)调整大小
  • 是的,请尝试一下,只是不要忘记将类 img-responsive 添加到图像中
  • 是的,请尝试一下,只是不要忘记将类 img-responsive 添加到图像中
  • 我试了一下,它只会调整字体大小
  • 你使用类 img-responsive 吗?另外,如果这不起作用,我们可以轻松地进行硬编码,我已经为您编辑了我的答案
【解决方案2】:

height: 66% !important;

设置的高度值会扭曲您的标题图像。

编辑:试试object-fit: contain !important;,告诉我它是否有效。

EDIT_2:删除您在 img 上设置的任何高度,灰色应该会消失。

EDIT_3:告诉我它是怎么回事,如果我帮助了你,将这个答案标记为正确,它也会帮助其他有同样问题的人。


摆脱您在图像上设置的高度。

#wp-custom-header > img {
  height: auto !important;
}


删除多余的空间。

.custom-header {
  height: 25vw !important;
}

【讨论】:

  • 我删除了,但是当我将窗口调整为小窗口时,img 仍然存在高度问题。
  • 杜博斯基,我编辑了我的答案。再试一次,告诉我结果如何!
  • 它的工作,但它显示新问题图像中的灰色空间我现在需要删除他,我插入新图像。
  • 我再次编辑了我的答案。尝试删除您在 CSS 中为 img 设置的任何高度。告诉我它是否有效。
  • 正如我所说,是wordpress,我已经尝试编辑父主题CSS,但问题仍然存在,以下代码是父主题标题css:.has-header-image .custom-header-media img, .has-header-video .custom-header-media video, .has-header-video .custom-header-media iframe { position: fixed; height: auto; max-width: 1000%; min-height: 100%; min-width: 100%; min-width: 100vw; /* vw prevents 1px gap on left that 100% has */ width: auto;}
猜你喜欢
  • 2012-10-17
  • 2018-06-20
  • 1970-01-01
  • 2020-08-26
  • 2022-01-17
  • 2017-12-09
  • 1970-01-01
  • 1970-01-01
  • 2021-09-21
相关资源
最近更新 更多