這是在渲染之後的HTML,或者是從你的編輯器?
考慮到這一點,你有幾個選項來創建一個全尺寸的背景任何類型的屏幕/分辨率。
您可以創建一個居中的背景,將永遠腳一定的屏幕,無論它是多麼大,也不是多麼小的圖像,只有兩個CSS規則:
.app-background {
position: fixed;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
overflow: hidden;
z-index: -1;
}
.app-background > img {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
}
。APP-背景將是背景的包裝並且將具有:
- 位置是:固定;爲了保持其位置,在父元素之一具有水平/垂直滾動條的情況下,並且也不消耗用於頁面內容的空間;
- top/left:-50%;寬度/高度:200%;居中並使其成爲其父/屏幕大小的兩倍; (現在你的圖片有父母,可以居中);
- overflow:hidden; z-index:-1;只是裁剪內部的圖像,並確保頁面的內容不會隱藏在背景後面;
。應用程序背景> IMG將圖像作爲背景,將有:
- 位置:絕對;上/右/下/左:0;保證金:汽車;將圖片在水平和垂直方向居中放置在.app-background;
- 最小寬度/最小高度:50%以防止容器的分辨率/屏幕尺寸的小於100%的圖像。
概念(在全屏觀看)
html, body {
width: 100%;
min-width: 100%;
height: 100%;
min-height: 100%;
margin: 0;
}
.app-background {
position: fixed;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
overflow: hidden;
z-index: -1;
}
.app-background > img {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
}
/* Instructions below this comment are NOT needed for the solution */
body {
font-family: Calibri, Arial;
text-align: center;
}
body:before {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;
margin-left: -0.25em;
}
*, .border-box {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.app-container {
position: relative;
border: 2px solid red;
color: red;
display: inline-block;
vertical-align: middle;
width: 40%;
height: 40%;
}
.app-background {
position: absolute;
border: 2px solid purple;
color: purple;
}
.app-container:before,
.app-background:before {
content: '.app-background';
font-size: 25px;
display: block;
padding-bottom: 10px;
}
.app-container:before {
content: '.app-container';
}
.app-background > img {
opacity: 0.5;
z-index: -1;
}
<div class="app-container">
<b>This red box is what you will see in your screen.</b>
<div class="app-background">
This purple box is where your image will be centered and cropped.
<img src="https://static.vecteezy.com/system/resources/previews/000/094/491/original/polygonal-texture-background-vector.jpg">
<b>Feel free to zoom-in/out your browser to see the effect from different resolutions!</b>
</div>
</div>
請點擊整版按鈕
的SOLUT離子(在全屏觀看)
html, body {
width: 100%;
min-width: 100%;
height: 100%;
min-height: 100%;
margin: 0;
}
body > ion-pane,
body > ion-pane > ion-content {
width: 100%;
height: 100%;
}
.app-background {
position: fixed;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
overflow: hidden;
z-index: -1;
}
.app-background > img {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
}
<body ng-app="starter">
<ion-pane>
<head>
</head>
<ion-content>
<body>
<div class="app-background">
<img src="https://static.vecteezy.com/system/resources/previews/000/094/491/original/polygonal-texture-background-vector.jpg">
</div>
</body>
</ion-content>
</ion-pane>
</body>
請點擊整版按鈕
哪來的CSS? – StackOverMySoul
這不是一個背景圖像... – DaniP