简介
搞了一个晚上,对此有了一定的理解。
由于对box-sizing中的border-box,content-box的概念不熟悉,所以没有用到它。
思路
这是名片的大体布局,一个矩形表示的是一个盒子,即一个div。
很多东西我都是看着写的,主要就是以下几个方面要注意一下:
1 position:relative和top: 这两个应该搭配使用。
2 去除下滑线的代码是 text-decoration: none;
3 .user-info-content-photo img {} 表示的是class值为user-info-content-photo的子标签img
4 如果两个盒子同时向左浮动,中间会没有间隙,此时可以设置右边盒子的左边距。
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 导入外部样式表 -->
<link rel="stylesheet" href="/about.css">
</head>
<body>
<div class="user-info">
<div class="user-info-time">
asked Feb 9, 2019 at 18:18
</div>
<div class="user-info-content">
<div class="user-info-content-photo">
<a href="https://www.acwing.com/user/myspace/index/136759/">
<img src="https://cdn.acwing.com/media/user/profile/photo/136759_lg_199ac0224c.jpg" alt="">
</a>
</div>
<div class="user-info-detail">
<div class="user-info-detail-username">
<a
href="https://cdn.acwing.com/media/user/profile/photo/136759_lg_199ac0224c.jpg">the_rubbish_dog</a>
</div>
<div class="user-info-detail-detail">
2022年5月29日
</div>
</div>
</div>
</div>
</body>
</html>
css代码
.user-info-content-photo img {
width: 64px;
height: 64px;
background-repeat: no-repeat;
}
.user-info-content-photo img {
border-radius: 1px;
float: left;
}
.user-info-detail {
float: left;
margin-left: 10px;
}
.user-info {
width: 230px;
height: 100px;
background-color: #d9eaf7;
padding: 5px 6px 7px 7px;
}
/* 去除下划线 */
.user-info a {
text-decoration: none;
}
.user-info-time {
font-size: 15px;
color: #909ca6;
margin: 1px 0px 4px 0px;
}
.user-info-detail-username a {
font-size: 14px;
color: #2287d3;
}
.user-info-detail {
position: relative;
top: 20px;
}
.user-info-detail-detail {
font-size: 14px;
color: #838c95;
float: left;
position: relative;
top: 8px;
}
实现效果