简体   繁体   English

如何使用引导程序在页面中间垂直和垂直设置它

[英]How to set it hor and vertically in the middle of page with bootstrap

[Excuse me for my English] I just centered my "logo" horizontally and vertically. [对不起,我的英语]我只是水平和垂直居中放置了“徽标”。 But what I want is that when I resize my browser that my logo becomes a little bit smaller. 但是我想要的是,当我调整浏览器的大小时,我的徽标会变小一点。 How can I do this in bootstrap? 如何在引导程序中执行此操作?

Index.html Index.html

<section>
    <div class="container">
        <div class="bg">
        </div>
    </div>
</section>

screen.css screen.css

.bg {
    position: absolute;
    background: url("../images/comingsoon.png") no-repeat center center fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
}

You can use background-size : 您可以使用background-size

.bg {
    position: absolute;
    background: url("../images/comingsoon.png") no-repeat center center fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    background-size: 100% 100%;
}

This will make your background image resizable, because it's relative to the parent size. 这将使您的背景图片可调整大小,因为它是相对于父级大小的。

More information: 更多信息:

http://www.w3schools.com/cssref/css3_pr_background-size.asp http://www.w3schools.com/cssref/css3_pr_background-size.asp

You can use viewport units (1) vw and vh with the background-size to make the size of the background depends on the window width and height 您可以将视口单位(1) vwvhbackground-size配合使用,以使background-size取决于窗口的宽度和高度

JS Fiddle 1 JS小提琴1

 .bg { position: absolute; background: url("//placehold.it/400x200/00AA00/ffffff?text=Coming Soon") no-repeat center center fixed; background-size:50vw 40vh; /*added this */ top: 0; left: 0; bottom: 0; right: 0; background-color:orange; margin: auto; } 
 <section> <div class="container"><div class="bg"></div></div> </section> 


Or you can use percentage values, change change the above background-size line into this: 或者,您可以使用百分比值,将上面的background-size行更改为:

background-size:50% 40%;

JS Fiddle 2 JS小提琴2

From MDN - Background-Size : 来自MDN-背景大小

A <percentage> value that scales the background image in the corresponding dimension to the specified percentage of the background positioning area, which is determined by the value of background-origin. <percentage>值,用于将相应尺寸的背景图像缩放到背景定位区域的指定百分比,该百分比由background-origin的值确定。 The background positioning area is, by default, the area containing the content of the box and its padding; 默认情况下,背景定位区域是包含框内容及其填充的区域; the area may also be changed to just the content or to the area containing borders, padding, and content. 该区域也可以更改为仅内容或包含边框,填充和内容的区域。 If the background's attachment is fixed, the background positioning area is instead the entire area of the browser window, not including the area covered by scrollbars if they are present . If the background's attachment is fixed, the background positioning area is instead the entire area of the browser window, not including the area covered by scrollbars if they are present Negative percentages are not allowed. 不允许使用负百分比。


Note that the 50vw , 40vh , 50% and 40% are just values for demonstration purposes, you can put any positive values you want . 请注意 50vw40vh50%40%只是用于演示的值,您可以输入所需的任何正值

------------------------------------------------------------------------------- -------------------------------------------------- -----------------------------

(1) Resources: (1)资源:

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

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