简体   繁体   English

背景和相对位置的HTML和CSS问题

[英]Issue with background and relative positioning html and css

I have a problem with html and css. 我对html和CSS有问题。

Today, for the first time, I've tried to make a page with a big image for the background. 今天,我第一次尝试制作一个背景大的页面。

I'm using foundation framework, and I'm stuck on one thing. 我正在使用基础框架,而我只停留在一件事上。 As we know foundation is a adaptive framework and when I re-size my browser, I've got a bug. 我们知道基础是一个自适应框架,当我调整浏览器大小时,我遇到了一个错误。

You can see it on my screenshot: https://imgurhd.ru/i/270a.jpg (also here you can find my css). 您可以在我的屏幕截图上看到它: https : //imgurhd.ru/i/270a.jpg (也在这里您可以找到我的CSS)。

I need to make the text and image under menu vertically centered on any screen size. 我需要使菜单下的文本和图像垂直于任何屏幕尺寸居中。

I'm using position relative with a percent value, as you can see. 如您所见,我正在使用具有百分比值的相对位置。 So please help me to find where is the problem. 因此,请帮助我找出问题所在。

You can set the background size to cover . 您可以将背景尺寸设置为cover

Cover This keyword specifies that the background image should be scaled to be as small as possible while ensuring both its dimensions are greater than or equal to the corresponding dimensions of the background positioning area. Cover此关键字指定在确保背景图像尺寸均大于或等于背景定位区域的相应尺寸的同时,将背景图像缩放至尽可能小。

html { 
  background: url(/*YOUR IMAGE HERE*/) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

This is supported in most recent browsers 最新的浏览器都支持

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

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