css图片图片居中显示
2016-07-20 11:08
393 查看
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>测试页面</title>
</head>
<body>
<style>
* {
padding: 0;
margin: 0;
}
.box {
width: 200px;
height: 200px;
overflow: hidden;
border: 2px solid #000;
border-radius: 50%;
}
div.box {
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
img.box {
object-fit: cover;
object-position: center;
}
</style>
<h1>原图(非正方形)</h1>
<img src="http://img6.cache.netease.com/m/2016/7/18/20160718170620f5fe3.png" width="200">
<br><br>
<h1>第一种: 用background-size和bakground-position </h1>
<div class="box" style="background-image:url(http://img6.cache.netease.com/m/2016/7/18/20160718170620f5fe3.png)"></div>
<br><br>
<h1>第二种: object-fit和object-position </h1>
<img class="box" src="http://img6.cache.netease.com/m/2016/7/18/20160718170620f5fe3.png">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>测试页面</title>
</head>
<body>
<style>
* {
padding: 0;
margin: 0;
}
.box {
width: 200px;
height: 200px;
overflow: hidden;
border: 2px solid #000;
border-radius: 50%;
}
div.box {
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
img.box {
object-fit: cover;
object-position: center;
}
</style>
<h1>原图(非正方形)</h1>
<img src="http://img6.cache.netease.com/m/2016/7/18/20160718170620f5fe3.png" width="200">
<br><br>
<h1>第一种: 用background-size和bakground-position </h1>
<div class="box" style="background-image:url(http://img6.cache.netease.com/m/2016/7/18/20160718170620f5fe3.png)"></div>
<br><br>
<h1>第二种: object-fit和object-position </h1>
<img class="box" src="http://img6.cache.netease.com/m/2016/7/18/20160718170620f5fe3.png">
</body>
</html>
相关文章推荐
- CSS Transitions and Transforms
- css中隐藏元素的几种方法
- 浅谈 CSS 清除浮动的 6 种方法(转)
- 【js】检测CSS JS 文件是否被引入。
- 建站css-tip
- CI 漂亮的分页样式(页码样式)
- css 字体不撑开默认块级元素问题
- css 字体不撑开默认块级元素问题
- 纯css3 3D图片立方体旋转动画特效
- css字体家族
- css animation让图标不断旋转
- What is Vertical Align?
- CSS中样式覆盖优先顺序
- css布局和定位总结
- ionic2.0的时间标签ion-datetime的时间显示样式和控件显示样式
- 如何在浏览器控制台(console)里输出彩色样式调试信息
- 关于上一篇鼠标移到按钮时的“按下”效果的三种方法
- css属性兼容主流浏览器
- WPF的Datagrid显示,样式(隔行换色)
- CSS样式