>  기사  >  웹 프론트엔드  >  CSS3에서 반원을 그리는 방법

CSS3에서 반원을 그리는 방법

青灯夜游
青灯夜游원래의
2021-07-21 17:56:405141검색

CSS3에서 반원을 그리는 방법: 1. 이를 달성하려면 border-radius 속성을 사용하세요. 두 개의 인접한 모서리 값을 너비/높이의 절반으로 설정하고 다른 쪽 모서리만 설정하면 됩니다. 두 모퉁이가 0이 됩니다. 2. 이를 달성하려면 CSS3의 클립 속성과 ret() 함수를 사용하세요.

CSS3에서 반원을 그리는 방법

이 튜토리얼의 운영 환경: Windows7 시스템, CSS3&&HTML5 버전, Dell G3 컴퓨터.

방법 1: border-radius를 사용하여 반원 구현

border-radius 속성은 요소에 둥근 테두리를 설정하는 데 사용됩니다. 1~4의 값을 지정하여 둥근 모양을 만들 수 있습니다. 구문:

border-radius: 1-4 length|%

각 반경에 대한 네 가지 값의 순서는 왼쪽 위, 오른쪽 위, 오른쪽 아래, 왼쪽 아래입니다. 왼쪽 아래 모서리를 생략하면 오른쪽 위 모서리도 동일합니다. 오른쪽 아래 모서리를 생략하면 왼쪽 위 모서리도 동일합니다. 오른쪽 위 모서리가 생략되면 왼쪽 위 모서리도 동일합니다.

예:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
* {
margin: 0;
padding: 0;
}

.clearfix {
zoom: 1;
/*为IE6,7的兼容性设置*/
}

.clearfix:after {
content: &#39;.&#39;;
display: block;
height: 0;
clear: both;
visibility: hidden;
}

ul li {
list-style: none;
float: left;
margin: 50px 0 50px 20px;
text-align: center;
}

li {
background: red;
}

h2 {
margin-top: 20px;
}

.circle1 {
width: 100px;
height: 50px;
border-radius: 50px 50px 0 0;
line-height: 50px;
}

.circle2 {
width: 50px;
height: 100px;
border-radius: 0 50px 50px 0;
line-height: 100px;
}

.circle3 {
width: 100px;
height: 50px;
border-radius: 0 0px 50px 50px;
line-height: 50px;
}

.circle4 {
width: 50px;
height: 100px;
border-radius: 50px 0 0 50px;
line-height: 100px;
}

.circle5 {
width: 100px;
height: 100px;
border-radius: 50px;
line-height: 100px;
}

</style>
</head>
<body>
<div>
<h2>用border-radius实现半圆</h2>
<ul>
<li>上边圆</li>
<li>左边圆</li>
<li>下边圆</li>
<li>左边圆</li>
<li>全圆</li>
</ul>

</div>
</body>
</html>
렌더링:

CSS3에서 반원을 그리는 방법

방법 2: CSS3의 클립 방법을 사용하여 반원

clip 속성을 달성하여 절대 위치에 있는 요소를 클립합니다. 즉, position:absolute가 설정된 경우에만 유효합니다. 유효한 유일한 모양 값은 다음과 같습니다:

rect (top, right, bottom, left) 예:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>

.clearfix {
zoom: 1;
/*为IE6,7的兼容性设置*/
}

ul li {
list-style: none;
float: left;
margin: 50px 0 50px 20px;
text-align: center;
}

li {
background: red;
}

h2 {
margin-top: 20px;
}


.demo {
/*左半圆*/
position: absolute;
/*clip 属性剪裁绝对定位元素。也就是说,只有 position:absolute 的时候才是生效的。*/
width: 100px;
height: 100px;
border-radius: 50px;
/* line-height: 50px; */
clip: rect(0px 50px 100px 0px);
/*唯一合法的形状值是:rect (top, right, bottom, left)*/
}

.right-circle {
/*右半圆*/
left: 200px;
clip: rect(0px 100px 100px 50px);
/*唯一合法的形状值是:rect (top, right, bottom, left)*/
}


</style>
</head>
<body>
<div>
<h2>css3的clip 方法剪裁实现半圆</h2>
<p style="color: red;"></p>
<ul style="position: relative;">
<li>左半圆</li>
<li class="demo right-circle">右半圆</li>
<li></li>
</ul>
</div>
</body>
</html>

렌더링:


CSS3에서 반원을 그리는 방법(동영상 공유 학습:

css 동영상 튜토리얼

)

위 내용은 CSS3에서 반원을 그리는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.