在我们使用电脑时,大多数的窗口都是圆角的。个人觉得圆角确实比直角耐看。
为了把网页上的窗口也做成圆角,我们可以通过border-radius
使得边框带有圆角效果。
基本语法:
border-radius:length;
length
是内切圆的半径,数值越大,弧线越强烈。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
width: 200px;
height: 100px;
border:2px solid red;
border-radius: 10px;
}
</style>
</head>
<body>
<div>
hello
</div>
</body>
</html>
具体想要什么样的圆角矩形可以不断地修改length
来观察图像变化得到最满意地圆角矩形。
首先我们需要人宽和高相同,然后把length
设置为正方形宽度地一半即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
width: 100px;
height: 100px;
border:2px solid red;
border-radius: 50px;
}
</style>
</head>
<body>
</body>
</html>
border-radius
是一个复合写法,实际上我们可以对四个角进行分别地处理。
border-radius:2px;
等价于
border-top-left-radius:2px;
border-top-right-radius:2px;
border-bottom-right-radius:2px;
border-bottom-left-radius:2px;
同样的
border-radius: 10px 20px 30px 40px;
等价于
border-top-left-radius:10px;
border-top-right-radius:20px;
border-bottom-right-radius:30px;
border-bottom-left-radius:40px;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
width: 100px;
height: 200px;
border: 2px solid red;
border-radius: 10px 20px 30px 40px;
}
</style>
</head>
<body>
</body>
</html>
演示效果:
在CSS中,HTML的标签的显示模式有很多。 但是,本文只介绍以下两个:
常见的元素
h1-h6
p
div
ul
ol
li
...
特点:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.test .parent{
width:500px;
height: 500px;
background-color: red;
}
.test .child{
height: 200px;
background-color: blue;
}
</style>
</head>
<body>
<div class="test">
<div class="parent">
<div class="child">
child1
</div>
<div class="child">
child2
</div>
</div>
</div>
</body>
</html>
注意:
.test .child{
height: 200px;
background-color: blue;
}
不写width默认和父元素一样宽,不写height,默认为0. 同时注意:
常见的元素:
a
strong
b
em
i
del
s
ins
u
span
...
特点:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style>
.demo2 span {
width: 200px;
height: 200px;
background-color: red;
}
</style>
<div class="demo2">
<span>child1</span>
<span>child2</span>
<span>child3</span>
</div>
</body>
</html>
特性 | 行内元素 | 块级元素 |
---|---|---|
显示方式 | 与其他元素同一行 | 占据整个行 |
占用空间 | 仅占内容空间 | 占据整行空间 |
宽高控制 | 不能设置宽高 | 可以设置宽高 |
是否可以设置外边距 | 只能设置左右外边距 | 可以设置上下和左右外边距 |
换行行为 | 不会换行 | 总是换行 |
希望本文对你有所帮助。 往期文章:前端
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有