简单实例之插入图片与背景图片区分及用法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div {
width: 300px;
height: 100px;
border: 1px solid pink;
text-align: center; /*文字水平居中*/
margin: 10px auto; /*盒子水平居中*/
}
section {
width: 300px;
height: 300px;
border: 1px solid #000;
}
section img { /*插入图片更改大小用height weight*/
width: 200px;
height: 210px;
margin-top: 40px;
margin-left: 50px; /*插入图片更改位置用margin 或padding 盒模型,插入图片也类似一个盒子*/
}
aside
{
width: 300px;
height: 300px;
border: 1px solid #000;
background: #fff url(https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2534506313,1688529724&fm=26&gp=0.jpg) 0 0 no-repeat;
background-size: 200px 210px; /*背景图片更改大小只能用background-size*/
/*
背景图片更改位置只能用 background-position*/
}
</style>
</head>
<body>
1:文字水平居中和盒子水平居中
<div>文字水平居中</div>
2:插入图片和背景图片
<section>
<img src="https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=137628589,3436980029&fm=26&gp=0.jpg" alt="">
</section>
<aside>
sideside
</aside>
3:
一般情况下,背景图片适合做一些小图标,
产品展示之类的一般用插入图片
</body>
</html>
网页打开结果