doubi7346 2013-08-17 02:12
浏览 85
已采纳

Wordpress二十二十全屏响应背景图像

I have just started front-end development with Wordpress Twenty Twelve child theme.

I want to make my background full-screen responsive. I followed from this post: Full-screen responsive background image because it is exactly what I'm looking for.

But when I copy and paste this css code into my style.css:

img.bg {
  /* Set rules to fill background */
  min-height: 100%;
  min-width: 1024px;

  /* Set up proportionate scaling */
  width: 100%;
  height: auto;

  /* Set up positioning */
  position: fixed;
  top: 0;
  left: 0;
}

@media screen and (max-width: 1024px) { /* Specific to this particular image */
  img.bg {
    left: 50%;
    margin-left: -512px;   /* 50% */
  }
}

It doesn't work. It feels like img.bg doesn't exist. This is my current website.

Please help! I cannot move on without this and I'm behind schedule :( Thank you for your time!

  • 写回答

2条回答 默认 最新

  • doulang9953 2013-08-17 02:23
    关注

    There's a nice css way of doing this:

    div
    {
    position: absolute; width: 100%; height: 100%;
    background-image:url('smiley.gif');
    background-repeat:no-repeat;
    background-size:cover;
    }
    

    The key is the background-size: cover; line - it will resize no matter what the window size. Check it out at http://www.w3schools.com/cssref/playit.asp?filename=playcss_background-size&preval=cover

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。