引导程序中的背景图片无法同时在移动设备和台式机上缩放。我该怎么办?

用户名

我正在尝试使背景图像缩放到移动和桌面。

此代码可在桌面上运行:

 /*
 * Globals
 */

/* Links */
a,
a:focus,
a:hover {
  color: #fff;
}

/* Custom default button */
.btn-default,
.btn-default:hover,
.btn-default:focus {
  color: #333;
  text-shadow: none; /* Prevent inheritence from `body` */
  background-color: #fff;
  border: 1px solid #fff;
}


/*
 * Base structure
 */

html,
body {
  height: 100%;
  background-color: #333;
}
body {
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
  box-shadow: inset 0 0 100px rgba(0,0,0,.5);
}

/* Extra markup and styles for table-esque vertical and horizontal centering */
.site-wrapper {
  display: table;
  width: 100%;
  height: 100%; /* For at least Firefox */
  min-height: 100%;
}
.site-wrapper-inner {
  display: table-cell;
  vertical-align: top;
}
.cover-container {
  margin-left: auto;
  margin-right: auto;
}

/* Padding for spacing */
.inner {
  padding: 30px;
}


/*
 * Header
 */
.masthead-brand {
  margin-top: 10px;
  margin-bottom: 10px;
}

.masthead-nav > li {
  display: inline-block;
}
.masthead-nav > li + li {
  margin-left: 20px;
}
.masthead-nav > li > a {
  padding-left: 0;
  padding-right: 0;
  font-size: 16px;
  font-weight: bold;
  color: #fff; /* IE8 proofing */
  color: rgba(255,255,255,.75);
  border-bottom: 2px solid transparent;
}
.masthead-nav > li > a:hover,
.masthead-nav > li > a:focus {
  background-color: transparent;
  border-bottom-color: rgba(255,255,255,.25);
}
.masthead-nav > .active > a,
.masthead-nav > .active > a:hover,
.masthead-nav > .active > a:focus {
  color: #fff;
  border-bottom-color: #fff;
}

@media (min-width: 768px) {
  .masthead-brand {
    float: left;
  }
  .masthead-nav {
    float: right;
  }
}


/*
 * Cover
 */

.cover {
  padding: 0 20px;
}
.cover .btn-lg {
  padding: 10px 20px;
  font-weight: bold;
}


/*
 * Footer
 */

.mastfoot {
  color: #999; /* IE8 proofing */
  color: rgba(255,255,255,.5);
}


/*
 * Affix and center
 */

@media (min-width: 768px) {
  /* Pull out the header and footer */
  .masthead {
    position: fixed;
    top: 0;
  }
  .mastfoot {
    position: fixed;
    bottom: 0;
  }
  /* Start the vertical centering */
  .site-wrapper-inner {
    vertical-align: middle;
  }
  /* Handle the widths */
  .masthead,
  .mastfoot,
  .cover-container {
    width: 100%; /* Must be percentage or pixels for horizontal alignment */
  }
}

@media (min-width: 992px) {
  .masthead,
  .mastfoot,
  .cover-container {
    width: 700px;
  }
}

而此代码在移动设备上:

/*
 * Globals
 */

/* Links */
a,
a:focus,
a:hover {
  color: #fff;
}

/* Custom default button */
.btn-default,
.btn-default:hover,
.btn-default:focus {
  color: #333;
  text-shadow: none; /* Prevent inheritence from `body` */
  background-color: #fff;
  border: 1px solid #fff;
}


/*
 * Base structure
 */

html,
body {
  height: auto%;
  background-color: #333;
}
body {
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
  box-shadow: inset 0 0 100px rgba(0,0,0,.5);
}

/* Extra markup and styles for table-esque vertical and horizontal centering */
.site-wrapper {
  display: table;
  width: auto;
  height: auto; /* For at least Firefox */
  min-height: auto;
}
.site-wrapper-inner {
  display: table-cell;
  vertical-align: auto;
}
.cover-container {
  margin-left: auto;
  margin-right: auto;
}

/* Padding for spacing */
.inner {
  padding: 30px;
}


/*
 * Header
 */
.masthead-brand {
  margin-top: 10px;
  margin-bottom: 10px;
}

.masthead-nav > li {
  display: inline-block;
}
.masthead-nav > li + li {
  margin-left: 20px;
}
.masthead-nav > li > a {
  padding-left: 0;
  padding-right: 0;
  font-size: 16px;
  font-weight: bold;
  color: #fff; /* IE8 proofing */
  color: rgba(255,255,255,.75);
  border-bottom: 2px solid transparent;
}
.masthead-nav > li > a:hover,
.masthead-nav > li > a:focus {
  background-color: transparent;
  border-bottom-color: rgba(255,255,255,.25);
}
.masthead-nav > .active > a,
.masthead-nav > .active > a:hover,
.masthead-nav > .active > a:focus {
  color: #fff;
  border-bottom-color: #fff;
}

@media (min-width: 768px) {
  .masthead-brand {
    float: left;
  }
  .masthead-nav {
    float: right;
  }
}


/*
 * Cover
 */

.cover {
  padding: 0 20px;
}
.cover .btn-lg {
  padding: 10px 20px;
  font-weight: bold;
}


/*
 * Footer
 */

.mastfoot {
  color: #999; /* IE8 proofing */
  color: rgba(255,255,255,.5);
}


/*
 * Affix and center
 */

@media (min-width: 768px) {
  /* Pull out the header and footer */
  .masthead {
    position: fixed;
    top: 0;
  }
  .mastfoot {
    position: fixed;
    bottom: 0;
  }
  /* Start the vertical centering */
  .site-wrapper-inner {
    vertical-align: middle;
  }
  /* Handle the widths */
  .masthead,
  .mastfoot,
  .cover-container {
    width: 100%; /* Must be percentage or pixels for horizontal alignment */
  }
}

@media (min-width: 992px) {
  .masthead,
  .mastfoot,
  .cover-container {
    width: 700px;
  }
}

唯一的区别是移动版本上事物的宽度和高度设置为自动。我需要使网站的背景比例达到两者的水平,同时仍保持良好外观。

我正在通过bootstrap(getbootstrap.com/examples/cover/)使用封面模板(如果有CSS和HTML,就可以使用它)。

最好的祝福,

吉尔库拉纳

多米尼克

不确定这是否是您想要的,但是这就是我的方法。

首先,设置html文件和正文,使其始终为100%

body {
    height: 100%;
    width: 100%;
}

html {
    height: 100%;
    overflow-x: hidden;
}

然后是您的着陆页类,该类还充当了您想要始终居中显示的内容的容器,无论屏幕大小如何。

.landing {
    display: table;
    height: 100%;
    width: 100%;
    position: relative;
    background: url(imagefile) no-repeat center center;
    background-color: #7fbbda; //Put a color here so when your image is loading, your content has a temporary background
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover; 
}

.landing .text-container { //this is the container for your text contents
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

这就是您的html文件的外观

<div class="landing">
    <div class="text-container">
        <h1>Text</h1>
        ...
    </div>
</div>

这对于任何设备均可正确渲染

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

引导面板:在移动设备上折叠但在台式机上扩展了,怎么办?

来自分类Dev

背景图片还要标题图片cc的把戏怎么办?

来自分类Dev

引导背景图片无法在移动时填满空间

来自分类Dev

我该怎么办才能保护台式计算机上的数据免遭被盗的风险?

来自分类Dev

CSS背景图片无法缩放

来自分类Dev

CSS背景图片无法缩放

来自分类Dev

边框图片无法在手机上正确显示,不确定该怎么办

来自分类Dev

边框图片无法在手机上正确显示,不确定该怎么办

来自分类Dev

我无法在Powerpoint 2007中删除背景图片

来自分类Dev

是否可以将远程的,真正的AJAX部分加载到台式机上的引导程序模版中,但作为移动设备中的侧滑形式?

来自分类Dev

在jQuery插件swipebox中,在图片标题中插入的链接在移动设备上无法单击,而只能在台式机上单击,如何解决?

来自分类Dev

引导程序在台式机上每行5列,在桌面上3行,在移动设备上2行?

来自分类Dev

引导修复程序要求64位iso-我该怎么办?

来自分类Dev

引导修复程序要求64位iso-我该怎么办?

来自分类Dev

(CSS)无法调整移动设备的背景图片大小

来自分类Dev

背景图片在移动设备上无法完全响应

来自分类Dev

我无法获得在Pygame中进行自我缩减的背景,该怎么办?

来自分类Dev

CSS背景图片未在移动设备上显示

来自分类Dev

多个CSS背景图片在移动设备上

来自分类Dev

背景图片未显示在移动设备上

来自分类Dev

移动设备上的背景图片大小

来自分类Dev

为什么我的内嵌svg无法在Safari(台式机和移动设备)上正确显示?

来自分类Dev

背景图片无法缩放以适合页面

来自分类Dev

我该怎么办呢?该怎么办?

来自分类Dev

图像资产问题(背景问题) - 我该怎么办?

来自分类Dev

使用CSS和HTML缩放背景图片

来自分类Dev

如何固定背景图片的大小和缩放?

来自分类Dev

我该怎么办,所以程序将输出1和0而不是true和false?

来自分类Dev

我无法使该响应式背景图片随页面滚动

Related 相关文章

  1. 1

    引导面板:在移动设备上折叠但在台式机上扩展了,怎么办?

  2. 2

    背景图片还要标题图片cc的把戏怎么办?

  3. 3

    引导背景图片无法在移动时填满空间

  4. 4

    我该怎么办才能保护台式计算机上的数据免遭被盗的风险?

  5. 5

    CSS背景图片无法缩放

  6. 6

    CSS背景图片无法缩放

  7. 7

    边框图片无法在手机上正确显示,不确定该怎么办

  8. 8

    边框图片无法在手机上正确显示,不确定该怎么办

  9. 9

    我无法在Powerpoint 2007中删除背景图片

  10. 10

    是否可以将远程的,真正的AJAX部分加载到台式机上的引导程序模版中,但作为移动设备中的侧滑形式?

  11. 11

    在jQuery插件swipebox中,在图片标题中插入的链接在移动设备上无法单击,而只能在台式机上单击,如何解决?

  12. 12

    引导程序在台式机上每行5列,在桌面上3行,在移动设备上2行?

  13. 13

    引导修复程序要求64位iso-我该怎么办?

  14. 14

    引导修复程序要求64位iso-我该怎么办?

  15. 15

    (CSS)无法调整移动设备的背景图片大小

  16. 16

    背景图片在移动设备上无法完全响应

  17. 17

    我无法获得在Pygame中进行自我缩减的背景,该怎么办?

  18. 18

    CSS背景图片未在移动设备上显示

  19. 19

    多个CSS背景图片在移动设备上

  20. 20

    背景图片未显示在移动设备上

  21. 21

    移动设备上的背景图片大小

  22. 22

    为什么我的内嵌svg无法在Safari(台式机和移动设备)上正确显示?

  23. 23

    背景图片无法缩放以适合页面

  24. 24

    我该怎么办呢?该怎么办?

  25. 25

    图像资产问题(背景问题) - 我该怎么办?

  26. 26

    使用CSS和HTML缩放背景图片

  27. 27

    如何固定背景图片的大小和缩放?

  28. 28

    我该怎么办,所以程序将输出1和0而不是true和false?

  29. 29

    我无法使该响应式背景图片随页面滚动

热门标签

归档