[JavaScript] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>测试1111111</title>
<style>
*{margin:0;padding:0;}
div{
width: 200px;
height: 200px;
border: 1px solid #000;
margin-left: 15px;
margin-bottom: 15px;
float: left;
overflow: hidden;
position: relative;
}
div img {
position: absolute;
max-width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto; /* 设置四个值为零,margin:auto;可以设置元素水平垂直居中 */
}
</style>
</head>
<body>
<div><img src="./images/kul.jpg" alt=""></div>
<div><img src="./images/lf.png" alt=""></div>
<div><img src="./images/timg (1).jpg" alt=""></div>
</body>
</html>
[JavaScript] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>测试222222</title>
<style>
*{margin:0;padding:0;}
div{
width: 200px;
height: 200px;
line-height: 200px;
border: 1px solid #000;
margin-left: 15px;
margin-bottom: 15px;
float: left;
text-align: center;
overflow: hidden;
}
div img {
/*采用行内块的特性进行图片的垂直居中特性
图片设置最大宽度和最小宽度;
vertical-align--> 文字对齐方式采用middle 居中
*/
max-width: 200px;
max-height: 200px;
vertical-align: middle;
}
</style>
</head>
<body>
<div><img src="./images/kul.jpg" alt=""></div>
<div><img src="./images/lf.png" alt=""></div>
<div><img src="./images/timg (1).jpg" alt=""></div>
</body>
</html>
[JavaScript] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>测试3333333</title>
<style>
*{margin:0;padding:0;}
div{
width: 200px;
height: 200px;
border: 1px solid #000;
margin-left: 15px;
margin-bottom: 15px;
float: left;
overflow: hidden;
position: relative;
}
div img {
/* 宽高100%
设置的是 IMG 标签的 关于 内容src的宽高属性会根据内容自动填充,会产生不完整的现象
*/
width: 100%;
height: 100%;
object-fit:none; /* 默认情况显示 */
object-position: center; /* 图片内容采用 center 方式进行居中 */
}
</style>
</head>
<body>
<div><img src="./images/kul.jpg" alt=""></div>
<div><img src="./images/lf.png" alt=""></div>
<div><img src="./images/timg (1).jpg" alt=""></div>
</body>
</html>
---------------------