CSS basic tutorial background properties
CSS background properties
background-color: background color.
background-image: background image address. For example: background-image:url(images/bg.gif)
background-repeat: background tiling mode, value: no-repeat (not tiling ), repeat-x (horizontal direction), repeat-y (vertical direction)
background-position: background positioning. Format: background-position: horizontal positioning, vertical positioning;
- ## Use English words to position: background-position: left|center|right top| center|bottom;
- Use fixed value positioning: background-position: 50px 50px; //The background is 50px from the left side of the container and 50px from the top of the container
- Use percentage positioning: background-position: 50% 50%; //Horizontally centered, vertically centered
- Use mixed positioning: background-position: left 10px; //Background to the left All together, 10px from the top of the container
Abbreviation
- background: background color background image Tiling method Positioning method;
- ## Example: background:url(images/bg.gif) no-repeat center center;
- Example: background: #ccc url(images/bg.gif) no-repeat left 10px;
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <style type="text/css"> .box1{ background-color:#f0f0f0; width:400px; } .box2{ background-image:url(http://img1.imgtn.bdimg.com/it/u=1182781053,1047826690&fm=21&gp=0.jpg); background-repeat:no-repeat; background-position:center center; width:400px; height:400px; } </style> </head> <body> <div class="box1"> <h1>习近平心中的互联网</h1> <p>互联网是20世纪最伟大的发明,它正在将人类“一网打尽”,人们在不知不觉中已经融入了互联网生态,互联网让世界变成了“鸡犬之声相闻”的地球村。</p> </div> <div class="box2"> </div> </body> </html>