繁体   English   中英

图像仅填充一页

[英]image filling only one page

我试图用图像填充首页,而整个图像没有空白。 一些文本和链接将位于其顶部。 最初,我尝试通过使用类创建一个简单的图像标签以使用css(z-index等)提供所需的属性来达到此目的,但是由于im完全没有经验,因此无法解决。

现在,我正在尝试使用background-element做同样的事情。 问题是我无法将其仅限制在首页上而不会丢失其设置。 是否有简单的解决方法,还是我应该尝试其他方法?

HTML代码

<img class="home" src="patsas.jpg" />

<h1> some <br> text  </h1>

CSS代码

body.home { 
              background: url(patsas.jpg) no-repeat center center fixed; 
              -webkit-background-size: cover;
              -moz-background-size: cover;
              -o-background-size: cover;
              background-size: cover;
            }

有几个问题。 首先,您的图片不会终止,从而使html无效。 其次,仅当body.cover具有“ cover”类时, body.cover与body元素匹配。 它永远不会匹配图像。

对于最终解决方案,我根本不会使用<img> ,而只会使用具有背景图像的<div>

 .cover { /* Make the element cover the entire viewport */ width: 100vw; height: 100vh; /* Set the background image to cover the entire element */ background: url(https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150) center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; /* Make it stay put, if you want to.. This part wasn't really clear. */ position: fixed; top: 0; left: 0; } 
 <!-- HTML is as simple as a div --> <div class="cover"></div> 

暂无
暂无

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

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