php - 页面左侧和顶部有一个空白,背景在 wordpress 上没有改变

标签 php css wordpress

我在 wordpress 上做一个主题,创建了一个名为 newpage-template.php 的页面模板,代码如下:

<div class="akmos">

   <img src="<?php echo get_bloginfo('template_url') ?>/imagens/banner-akmos.png">

</div>

但是左边和上面有一个空隙(但右边没有),就像你在这里看到的:

enter image description here

我的这个页面的 CSS 是:

<?php /* Template Name: Stuff */ ?>
.akmos {
   height: 500px;
 }

.akmos img {
   width:100%
}

我已经设置了 margin:0,但它不起作用。

body {
margin:0 !important;
}

最奇怪的是我不能通过css改变图像的大小,它不起作用。例如,如果我尝试将它的宽度设置为 400px,它就不会改变。这让我相信问题出在 php 上,但我不确定。如何解决?

最佳答案

.akmos imgwidth:100% 不起作用的原因是您没有在父 div 中声明宽度,即.akmos。我建议在 .akmos 中设置维度并告诉 .akmos img 遵循父属性:

.akmos {
  position:fixed;
  top:0;margin-top:0px;
  left:0;margin-left:0px;
  width:100%;
  height:500px;
}

.akmos img {
  width:100%;
  height:100%;
}

看看这是否有效:)

关于php - 页面左侧和顶部有一个空白,背景在 wordpress 上没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56613329/

相关文章:

php - 使用 JQUERY 实时将 JSON 填充到表中

php - 如何在Datalife Engine 的主页上只显示一个div block ?

html - 如何在 H1 标签内的堆叠文本旁边显示图像?

WordPress 的 JavaScript 依赖管理?

.htaccess - Wordpress Multisite .htaccess ..请解释功能

html - 在WordPress子主题中覆盖父CSS的媒体查询

php - Woocommerce 3.x 中的导入和导出产品品牌

Php 本地主机错误

html - 为什么我收到 CSS 文件的 'A Term Expected' 错误?

html - 调整文字上划线的粗细