利用 html+css 画同心圆(concentric circles)——绝对布局与相对布局

本文转载于:猿2048网站利用 html+css 画同心圆(concentric circles)——绝对布局与相对布局

一、css 绘制圆

1  
2 #circle {
3     width: 300px;
4    height: 300px;
5    background-color: #000000;
6    border-radius: 300px;
7 }

key:

1、width = height 相当于画一个正方形

2、border-radius > 0.5*width                (border-radius:圆角半径 )

 

二、同心圆,两种画法

2.1 absolute构成同心圆

绘制外面的圆:

1 #exCircle{
2     margin:auto;
3     width: 300px;
4     height: 300px;
5     border-radius: 300px;
6     background-color: green;
7 }

key:

1、margin: auto 使圆居中显示

2、外部圆的半径为150px(width/2)

 

绘制里面的圆

1 #inCircle{
2     margin-top: 50px;
3     margin-left: 50px;      
4     position: absolute;
5     width: 200px;
6     height: 200px;
7     border-radius: 150px;
8     background-color: yellow;
9 }

 key:

1、内部圆半径为100px(width/2)

2、position:absolute 使用绝对布局

3、margin-top:50px (外部圆半径-内部圆半径)

 

2.2 relative构成同心圆

绘制外面的圆:

1 #exCircle{
2     margin:auto;
3     width: 300px;
4     height: 300px;
5     border-radius: 150px;
6     background-color: green;
7 }

 

绘制内部的圆:

1 #inCircle{
2     top: 50px;
3     left: 50px;      
4     position: relative;
5     width: 200px;
6     height: 200px;
7     border-radius: 100px;
8     background-color: yellow;
9 }

key:

1、top/left 都是 width/2

 

三、效果:

1359776-20180404183451387-1423436944.png

四、知识补充

1、border-radius:参考https://blog.csdn.net/liuyan19891230/article/details/50724630

2、position属性,relative/absolute区分,网上信息比较乱,最近整理以后再发一篇

 

附:

完整源码(absolute)

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>concentric circles</title>
    <style type="text/css">

#exCircle{
    margin:auto;
    width: 300px;
    height: 300px;
    border-radius: 150px;
    background-color: green;
}

#inCircle{
    margin-top: 50px;
    margin-left: 50px;      
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 100px;
    background-color: yellow;
}

</style>
</head>
<body>

<div id="exCircle">
    <div id="inCircle">
    </div>
</div>

</body>
<html>

 

转载于:https://my.oschina.net/u/4191619/blog/3096995

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值