search
HomeWeb Front-endHTML Tutorial纯CSS实现一个微信logo,需要几个标签?_html/css_WEB-ITnose

博客已迁移至http://lwzhang.github.io。

纯CSS实现一个微信logo并不难,难的是怎样用最少的 html 标签实现。我一直在想怎样用一个标签就能实现,最后还是没想出来,就只好用两个标签了。

首先需要两个标签元素:

    <div class="bg">        <div class="inner"></div>    </div>

先画个背景:

    .bg {        width: 300px;        height: 300px;        background-color: #08c406;        border-radius: 10px;        position: relative;    }

再画个大的椭圆:

    .inner {        width: 180px;        height: 150px;        border-radius: 50%;        background-color: #fff;        position: absolute;        top: 60px;        left: 35px;    }

小的椭圆利用 .inner 的 ::before 伪元素实现:

    &::before {        content: "";        width: 140px;        height: 120px;        border-radius: 50%;        background-color: #fff;        position: absolute;        top: 60px;        left: 90px;        border: 2px solid #08c406;    }

下图时现在的结果:

里面的四个圆怎么画呢?可以利用CSS3的 box-shadow 属性实现,一般重复性的东西都会用这个属性,因为它可以制造出无数个一模一样的东西出来。

利用 .bg 的 ::before 伪元素实现这些圆:

    &::before {       content: "";       position: absolute;       width: 16px;       height: 16px;       border-radius: 50%;       background-color: #08c406;       top: 150px;       left: 155px;       z-index: 2;       box-shadow: 70px 0 #08c406, -70px -50px 0 2px #08c406, 0 -50px 0 2px #08c406;    }

::before 本身会实现一个圆(一个小圆),然后利用 box-shadow 属性实现其它的三个圆。

来看看现在的效果:

现在就剩下两个角了,想想还有哪些东西没用上?还有两个伪元素,分别是 .bg 的 ::after 和 .inner 的 ::after ,刚好可以实现两个角。

这两个角其实就是平常的小三角,然后再旋转个 45 度, CSS 实现小三角太常见了:

    .bg::after {        content: "";        border-width: 30px 12px;        border-style: solid;        border-color: #fff transparent transparent transparent;        position: absolute;        top: 182px;        left: 50px;        transform: rotate(45deg);    }    .inner::after {        content: "";        border-width: 30px 10px;        border-style: solid;        border-color: #fff transparent transparent transparent;        position: absolute;        top: 155px;        left: 200px;        transform: rotate(-45deg);    }

最终效果:

全部 css 代码:

    @mixin pos($left, $top) {      position: absolute;      left: $left;      top: $top;    }    .bg {      width: 300px;      height: 300px;      background-color: #08c406;      border-radius: 10px;      position: relative;      &::before {       @include pos(155px, 150px);       content: "";       width: 16px;       height: 16px;       border-radius: 50%;       background-color: #08c406;       z-index: 2;       box-shadow: 70px 0 #08c406, -70px -50px 0 2px #08c406, 0 -50px 0 2px #08c406;      }      &::after {       @include pos(50px, 182px);       content: "";       border-width: 30px 12px;       border-style: solid;       border-color: #fff transparent transparent transparent;       transform: rotate(45deg);     }     .inner {       width: 180px;       height: 150px;       border-radius: 50%;       background-color: #fff;       @include pos(35px, 60px);       &::before {        @include pos(90px, 60px);        content: "";        width: 140px;        height: 120px;        border-radius: 50%;        background-color: #fff;        border: 2px solid #08c406;       }       &::after {        @include pos(200px, 155px);        content: "";        border-width: 30px 10px;        border-style: solid;        border-color: #fff transparent transparent transparent;        transform: rotate(-45deg);       }      }    }

画这个logo最难的地方应该就是实现四个小圆的时候,因为 CSS3 不太熟的人可能不会想到利用 box-shadow 去实现。

大家还有其它的方法实现微信logo吗?有没有一个标签就能实现的?欢迎留下你的实现方式。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment