相关文章推荐
高大的机器人  ·  在DataGridView底部实现统计行-阿 ...·  2 年前    · 
玩篮球的松鼠  ·  cv::imread读不出图片的解决办法「建 ...·  2 年前    · 
没人理的爆米花  ·  go1.6.2 linux/amd64 ...·  3 年前    · 
刚毅的火车  ·  curl能访问但是浏览器不能访问_curl可 ...·  3 年前    · 
绅士的蚂蚁  ·  java - Setting up ...·  3 年前    · 
Code  ›  CSS实现图形效果开发者社区
css border-radius background css三角形
https://cloud.tencent.com/developer/article/1690053?from=article.detail.1685631&areaSource=106000.1&traceId=NWIhsf2Zg3rwe3CFYDHef
路过的毛衣
3 年前
作者头像
WindrunnerMax
0 篇文章

CSS实现图形效果

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > Czy‘s Blog > 正文

CSS实现图形效果

发布 于 2020-09-01 10:39:42
678 0
举报

CSS实现图形效果

CSS 实现正方形、长方形、圆形、半圆、椭圆、三角形、平行四边形、菱形、梯形、六角星、五角星、心形、消息框。

正方形

<section>
    <div id="square"></div>
</section>
<style type="text/css">
    #square{
        width: 100px;
        height: 100px;
        background: #4C98F7;
</style>

长方形

<section>
    <div id="rectangle"></div>
</section>
<style type="text/css">
    #rectangle{
        width: 200px;
        height: 100px;
        background: #4C98F7;
</style>

圆形

<section>
    <div id="circle"></div>
</section>
<style type="text/css">
    #circle{
        width: 100px;
        height: 100px;
        background: #4C98F7;
        border-radius: 50%;
</style>

半圆

<section>
    <div id="semicircle"></div>
</section>
<style type="text/css">
    #semicircle{
        width: 100px;
        height: 50px;
        background: #4C98F7;
        border-radius: 100px 100px 0 0;
</style>

椭圆

<section>
    <div id="oval"></div>
</section>
<style type="text/css">
    #oval{
        width: 100px;
        height: 50px;
        background: #4C98F7;
        border-radius: 100px / 50px;
</style>

三角形

<section>
    <div id="regular-triangle"></div>
</section>
<style type="text/css">
    #regular-triangle{
        width: 0;
        height: 0;
        border-left: 50px solid transparent;
        border-right: 50px solid transparent;
        border-bottom: 100px solid #4C98F7;
</style>
<section>
    <div id="corner-triangle"></div>
</section>
<style type="text/css">
    #corner-triangle{
        width: 0;
        height: 0;
        border-top: 100px solid #4C98F7;
        border-right: 100px solid transparent;
</style>

平行四边形

<section>
    <div id="parallelogram"></div>
</section>
<style type="text/css">
    #parallelogram{
        margin: 0 15px;
        width: 200px; 
        height: 100px; 
        transform: skew(-20deg); 
        background: #4C98F7;
</style>

菱形

<section>
    <div id="diamond"></div>
</section>
<style type="text/css">
    #diamond {
        width: 0;
        height: 0;
        border: 100px solid transparent;
        border-bottom-color: #4C98F7;
        position: relative;
        top: -100px;
    #diamond:after {
        content: "";
        position: absolute;
        left: -100px;
        top: 100px;
        width: 0;
        height: 0;
        border: 100px solid transparent;
        border-top-color: #4C98F7;
</style>

六角星

<section>
    <div id="hexagons"></div>
</section>
<style type="text/css">
    #hexagons {
        width: 0;
        height: 0;
        border: 100px solid transparent;
        border-bottom-color: #4C98F7;
        position: relative;
        top: -100px;
    #diamond:after {
        content: "";
        position: absolute;
        left: -100px;
        top: 100px;
        width: 0;
        height: 0;
        border: 100px solid transparent;
        border-top-color: #4C98F7;
</style>

五角星

<section>
    <div id="five-pointed-star"></div>
</section>
<style type="text/css">
    #five-pointed-star { 
        margin: 100px 0 50px 0; 
        position: relative;
        width: 0px; 
        ; 
        border-right: 100px solid transparent; 
        border-bottom: 70px solid #4C98F7; 
        border-left: 100px solid transparent; 
        transform: rotate(35deg); 
     #five-pointed-star:before { 
        content: ""; 
        position: absolute; 
        height: 0; 
        width: 0; 
        top: -45px; 
        left: -65px; 
        border-bottom: 80px solid #4C98F7; 
        border-left: 30px solid transparent; 
        border-right: 30px solid transparent; 
        transform: rotate(-35deg); 
    #five-pointed-star:after { 
        content: ""; 
        position: absolute; 
        top: 3px; 
        left: -105px; 
        width: 0px; 
        ; 
        border-right: 100px solid transparent; 
        border-bottom: 70px solid #4C98F7; 
        border-left: 100px solid transparent; 
        transform: rotate(-70deg); 
</style>

心形

<section>
    <div id="five-pointed-star"></div>
</section>
<style type="text/css">
    #five-pointed-star { 
        margin: 100px 0 50px 0; 
        position: relative;
        width: 0px; 
        ; 
        border-right: 100px solid transparent; 
        border-bottom: 70px solid #4C98F7; 
        border-left: 100px solid transparent; 
        transform: rotate(35deg); 
     #five-pointed-star:before { 
        content: ""; 
        position: absolute; 
        height: 0; 
        width: 0; 
        top: -45px; 
        left: -65px; 
        border-bottom: 80px solid #4C98F7; 
        border-left: 30px solid transparent; 
        border-right: 30px solid transparent; 
        transform: rotate(-35deg); 
    #five-pointed-star:after { 
        content: ""; 
        position: absolute; 
        top: 3px; 
        left: -105px; 
        width: 0px; 
        ; 
        border-right: 100px solid transparent; 
        border-bottom: 70px solid #4C98F7; 
        border-left: 100px solid transparent; 
        transform: rotate(-70deg); 
</style>

消息框

<section>
    <div id="message-box"></div>
</section>
<style type="text/css">
    #message-box { 
        margin: 0 20px;
        width: 120px; 
        height: 80px; 
        background: #4C98F7; 
        position: relative; 
        border-radius: 10px; 
    #message-box:before { 
        content:"";
        position: absolute; 
        right: 100%; 
        top: 26px; 
        width: 0; 
        height: 0; 
        border-top: 13px solid transparent; 
        border-right: 26px solid #4C98F7; 
        border-bottom: 13px solid transparent; 
</style>

示例

<!DOCTYPE html>
    <title>CSS实现图形效果</title>
    <style type="text/css">
        section{
            margin: 10px 0;
        #square{
            width: 100px;
            height: 100px;
            background: #4C98F7;
        #rectangle{
            width: 200px;
            height: 100px;
            background: #4C98F7;
        #circle{
            width: 100px;
            height: 100px;
            background: #4C98F7;
            border-radius: 50%;
        #semicircle{
            width: 100px;
            height: 50px;
            background: #4C98F7;
            border-radius: 100px 100px 0 0;
        #semicircle{
            width: 100px;
            height: 50px;
            background: #4C98F7;
            border-radius: 100px 100px 0 0;
        #oval{
            width: 100px;
            height: 50px;
            background: #4C98F7;
            border-radius: 100px / 50px;
        #regular-triangle{
            width: 0;
            height: 0;
            border-left: 50px solid transparent;
            border-right: 50px solid transparent;
            border-bottom: 100px solid #4C98F7;
        #corner-triangle{
            width: 0;
            height: 0;
            border-top: 100px solid #4C98F7;
            border-right: 100px solid transparent;
        #parallelogram{
            margin: 0 15px;
            width: 200px; 
            height: 100px; 
            transform: skew(-20deg); 
            background: #4C98F7;
        #diamond {
            width: 0;
            height: 0;
            border: 100px solid transparent;
            border-bottom-color: #4C98F7;
            position: relative;
            top: -100px;
        #diamond:after {
            content: "";
            position: absolute;
            left: -100px;
            top: 100px;
            width: 0;
            height: 0;
            border: 100px solid transparent;
            border-top-color: #4C98F7;
        #hexagons{ 
            margin: 35px 0;
            width: 0; 
            height: 0; 
            border-left: 60px solid transparent; 
            border-right: 60px solid transparent; 
            border-bottom: 60px solid #4C98F7; 
            position: relative; 
        #hexagons:after { 
            width: 0; 
            height: 0; 
            border-left: 60px solid transparent; 
            border-right: 60px solid transparent; 
            border-top: 60px solid #4C98F7; 
            position: absolute; 
            content: ""; 
            top: 20px; 
            left: -60px; 
        #five-pointed-star { 
            margin: 100px 0 70px 0; 
            position: relative;
            width: 0px; 
            ; 
            border-right: 100px solid transparent; 
            border-bottom: 70px solid #4C98F7; 
            border-left: 100px solid transparent; 
            transform: rotate(35deg); 
         #five-pointed-star:before { 
            content: ""; 
            position: absolute; 
            height: 0; 
            width: 0; 
            top: -45px; 
            left: -65px; 
            border-bottom: 80px solid #4C98F7; 
            border-left: 30px solid transparent; 
            border-right: 30px solid transparent; 
            transform: rotate(-35deg); 
        #five-pointed-star:after { 
            content: ""; 
            position: absolute; 
            top: 3px; 
            left: -105px; 
            width: 0px; 
            ; 
            border-right: 100px solid transparent; 
            border-bottom: 70px solid #4C98F7; 
            border-left: 100px solid transparent; 
            transform: rotate(-70deg); 
        #heart-shaped {
            position: relative;
            width: 100px;
            height: 90px;
        #heart-shaped:before,
        #heart-shaped:after {
            content: "";
            position: absolute;
            left: 50px;
            top: 0;
            width: 50px;
            height: 80px;
            background: #4C98F7;
            border-radius: 50px 50px 0 0;
            transform: rotate(-45deg);
            transform-origin: 0 100%;
        #heart-shaped:after {
            left: 0;
            transform: rotate(45deg);
            transform-origin: 100% 100%;
        #message-box { 
            margin: 0 20px;
            width: 120px; 
            height: 80px; 
            background: #4C98F7; 
            position: relative; 
            border-radius: 10px; 
        #message-box:before { 
            content:"";
            position: absolute; 
            right: 100%; 
            top: 26px; 
            width: 0; 
            height: 0; 
            border-top: 13px solid transparent; 
            border-right: 26px solid #4C98F7; 
            border-bottom: 13px solid transparent; 
    </style>
</head>
    <section>
        <div id="square"></div>
    </section>
    <section>
        <div id="rectangle"></div>
    </section>
    <section>
        <div id="circle"></div>
    </section>
    <section>
        <div id="semicircle"></div>
    </section>
    <section>
        <div id="oval"></div>
    </section>
    <section>
        <div id="regular-triangle"></div>
    </section>
    <section>
        <div id="corner-triangle"></div>
    </section>
    <section>
        <div id="parallelogram"></div>
    </section>
    <section>
        <div id="diamond"></div>
    </section>
    <section>
        <div id="hexagons"></div>
    </section>
    <section>
        <div id="five-pointed-star"></div>
    </section>
    <section>
        <div id="heart-shaped"></div>
    </section>
    <section>
 
推荐文章
高大的机器人  ·  在DataGridView底部实现统计行-阿里云开发者社区
2 年前
玩篮球的松鼠  ·  cv::imread读不出图片的解决办法「建议收藏」-腾讯云开发者社区-腾讯云
2 年前
没人理的爆米花  ·  go1.6.2 linux/amd64 的一个bug: gcc: 无法识别的选项‘-no-pie’ - 蝈蝈俊 - 博客园
3 年前
刚毅的火车  ·  curl能访问但是浏览器不能访问_curl可以访问但浏览器访问不了_未来,值得期待的博客-CSDN博客
3 年前
绅士的蚂蚁  ·  java - Setting up properly SonarQube for Code Coverage - Stack Overflow
3 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号