简体   繁体   中英

How to create a background image in CSS

I am new to the world of webdesign and am not completely not entirely sure how to create a full background image.

I am playing around with the warship.ts example on typescriptlang.org, and I am trying to add in a background photo of a battleship. Below is the code of the CSS file:

html 
{
width: 100%;
height: 100%;
-ms-content-zooming: none;
margin: 0px;
border: 0px;
padding: 0px;
background-image: url(pictures/cats.jpg); //My code
background-size: cover;
}
body {
font-family: Verdana;
width: 100%;
height: 100%;
/*background-color: #b5caae;*/
background: url('img/bg2.jpg');
margin: 0px;
border: 0px;
padding: 0px;
min-height: 480px;
min-width: 640px;
}
#header {
width: 100%;
height: 25%;
}
#boards {
width: 100%;
height: 75%;
}
.quadrant 
{
display: inline-block;
box-sizing: border-box;
-moz-box-sizing: border-box;
width: 40%;
margin: 2%;
vertical-align: top;
}
#banner {
font-size: 40pt;
font-weight: 800;
font-style: italic;
color: white;
text-shadow: -1px 0 black, 0 2px black, 1px 0 black, 0 -1px black;
height: 100px;
}
#status 
{
width: 80%;
border: 1px dotted gray;
padding: 1%;
background-color: #CCCCCC;
height: 80%;
}
.board {
background-color: #111111;
border: 2px groove black;
height: 80%;
padding: 0%;
position: relative;
}
.cell {
box-sizing: border-box;
-moz-box-sizing: border-box;
float: left;
height: 10%;
width: 10%;
border: 1px dotted #A0A0FF;
margin: 0px;
padding: 0px;
position: relative;
}

.notBombed {
opacity: 0.2;
background:  url('img/bg.jpg') repeat;
/*background-color: black;*/
z-index: 0;
}

.cellHit {
opacity: 0.5;
background-color: #C00000;
z-index: 2;
}

.cellMiss{
opacity: 0.5;
background-color: #008000;
z-index: 2;
}

.ship {
position: absolute;
box-sizing: border-box;
-moz-box-sizing: border-box;
margin: 0%;
padding: 0%;
width: 10%;
height: 10%;
border-radius: 20%;
/*background-color: #FFFF80;*/
background: #666666;
border: 2px solid black;
z-index: 1;
-ms-touch-action: none;
}

.dropTarget {
background-color: white;
}

As an IDE, I am using Visual Studio 2015. From the examples I have seen online, I place the url image in the solution explorer, then I reference it in the html method, and then set the image as a color. However, whenever I try to run it, nothing changes. Is there something that I am missing from the code, or am I updating this in the wrong spot? Do I need to change the HTML/ts code?

If you are trying to html background image in every resolution, try with this code

background: url(pictures/cats.jpg) no-repeat  fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;

do this for only body{} sector. remove background images code from other sectors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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