前端开发——CSS笔记

大学生一枚,最近在写前端代码。发现以前遇到过的技术问题,由于缺乏总结与复习,如今又再次碰到,让我觉得自己真是没一点进步,于是乎开始写博客。知道背单词重复的重要性,学其他怎么就坚持不下去呢?真傻!!!

写在前面:该死,出师未捷身先死,犯了个命名规则的错误:

class选择器命名规则

class命名规则
ID选择器命名规则
ID选择器命名规则

  1. 元素相对于父元素垂直居中的方法:
    第一种:在父元素样式中加上如下代码(缺一不可):
    display: flex; justify-content: center; align-items: center;
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述

测试文件内容

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>测试居中</title>
	<style>
		body{
			background-color:whitesmoke;
		}
		#father_div{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 256px;
			height: 256px;
			margin: 0 auto;
			background-color: #01AAED;
		}
		#children_div{
			width: 50px;
			height: 50px;
			background-color: #00FFFF;
		}
		#brother_div{
			width: 256px;
			height: 256px;
			margin: 0 auto;
			background-color: #01AAED;
		}
		#cousin_div{
			width: 50px;
			height: 50px;
			background-color: #00FFFF;
		}
	</style>
	</head>
	<body>
		<h1>元素相对于父元素垂直居中的方法一</h1>
		<div id="father_div">
			<div id="children_div"></div>
		</div>
		<h1>显然没居中</h1>
		<div id="brother_div">
			<div id="cousin_div"></div>
		</div>
	</body>
</html>

居中效果图:
效果图
其他方法用到再更新。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值