需求:
效果:
代码:
<!DOCTYPE html>
<html>
<head>
<title>四分之一圆</title>
<style type="text/css">
.class_div_bg {
width: 400px;
height: 200px;
background-color: #ccc;
/*设置div垂直居中*/
position: absolute;
margin: auto;
/*注意: top bottom left right四者数值相同即可*/
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.class_div_arc1 {
width: 50px;
height: 50px;
background-color: #fc0;
/*四分之一圆*/
border-radius: 0 0 100% 0;
/*定位*/
position: absolute;
left: 0;
top: 0;
}
.class_div_arc2 {
width: 50px;
height: 50px;
background-color: #fc0;
/*四分之一圆*/
border-radius: 100% 0 0 0;
/*定位*/
position: absolute;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div class="class_div_bg">
<div class="class_div_arc1"></div>
<div class="class_div_arc2"></div>
</div>
</body>
</html>
核心内容:
1. div屏幕居中:
/*设置div垂直居中*/
position: absolute;
margin: auto;
/*注意: top bottom left right四者数值相同即可*/
top: 0;
bottom: 0;
left: 0;
right: 0;
2. CSS画四分之一圆
border-radius: 100% 0 0 0; // 左上1/4圆
border-radius: 0 0 100% 0; // 右下1/4圆
border-radius: 左上 右上 右下 左下
3. 绝对定位相关知识点
3.1 绝对定位的元素的位置相对于最近的已定位父元素,
如果元素没有已定位的父元素,那么它的位置相对于<html>:
3.2 相对定位元素经常被用来作为绝对定位元素的容器块。
3.3 HTML元素的默认没有定位,元素出现在正常的流中。