简体   繁体   English

将图像拉伸到视口的100%

[英]stretch image to 100% of viewport

I made an simple layout for an android application using html and css. 我使用html和css为android应用程序做了一个简单的布局。 The hole page has an background image, but i didnt declared it as: 孔页面有背景图像,但是我没有声明为:

 background-image: url(

Because so belong my information i cannot center it? 因为属于我的信息,我无法集中精力吗? So that my next plan was to make an simple div that covers the image as you can see here: 因此,我的下一个计划是制作一个简单的div,以覆盖图像,如下所示:

<body>
<img src="foto.jpg" class="bg">

<div class="oben">
<h1>Playing Audio</h1>

<button onclick="playAudio('test.mp3')">Play Some Audio</button>
<button onclick="playAudio('test2.mp3')">Play Some Audio2</button>
</div>
</body>

My css is the following: 我的CSS如下:

 .image{
position: relative; 
 width: 100%; 
 }
.oben { 
position: absolute; 
top: 20%; 
left: 0; 
width: 100%; 
}

SO now back to my actual problem, the image is not streching to the 100% of the viewport instead it is having 100% of its own width, what means around 200px! 所以现在回到我的实际问题上,图像没有拉伸到视口的100%,而是拥有其自身宽度的100%,这意味着大约200像素! But i want to strech it all over the page! 但我想全力以赴! Thanks! 谢谢!

That's becuase there is no such thing as .image 那是因为没有.image这样的东西

You should try this 你应该试试这个

img.bg{
  position: relative; 
  width: 100%; 
}

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

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