GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 面试题:使用 CSS 画一个三角形 · Issue #123 · sisterAn/JavaScript-Algorithms

面试题:使用 CSS 画一个三角形 #123

New issue
Copy link
New issue
Copy link
Open
Open
面试题:使用 CSS 画一个三角形#123
Copy link
Labels
字节

Description

@sisterAn
sisterAn
opened on Nov 1, 2020
Issue body actions
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>画三角形</title>
    <style>
        .triggle{
            width: 0px;
            height: 0px;
            border-width: 100px;
            border-style: dotted dotted solid dotted;
            border-color: transparent transparent red transparent;
        }
    </style>
</head>
<body>
    <div class="triggle"></div>
</body>
</html>


前端小技巧:边框写三角形

Activity

  1. sisterAn
    added
    字节
    on Nov 1, 2020
  2. latte03 commented on Nov 2, 2020

    @latte03
    latte03
    on Nov 2, 2020
    More actions

    通过border模拟实现

    当div 的宽高为0,存在边框的时候,四条边框的中心将会是一个点,通过设置其他三条边框的透明度,实现三角形。

    div{
      width:0;
      height:0;
      border-width:8px;
      border-style:solid;
      border-top-color: transparent;
      border-right-color: transparent;
      border-bottom-color: transparent;
      border-left-color: red;
    }
    Reacted by miyanoshiyo and Mengyuan Liu
  3. U-LAN commented on Nov 2, 2020

    @U-LAN
    U-LAN
    on Nov 2, 2020
    More actions

    通过border模拟实现

    当div 的宽高为0,存在边框的时候,四条边框的中心将会是一个点,通过设置其他三条边框的透明度,实现三角形。

    div{
      width:0;
      height:0;
      border-width:8px;
      border-top-color: transparent;
      border-right-color: transparent;
      border-bottom-color: transparent;
      border-left-color: red;
    }

    显示不出来需要再加一个属性: border-style:solid;

  4. latte03 commented on Nov 2, 2020

    @latte03
    latte03
    on Nov 2, 2020
    More actions

    通过border模拟实现

    当div 的宽高为0,存在边框的时候,四条边框的中心将会是一个点,通过设置其他三条边框的透明度,实现三角形。

    div{

    width:0;

    height:0;

    border-width:8px;

    border-top-color: transparent;

    border-right-color: transparent;

    border-bottom-color: transparent;

    border-left-color: red;

    }

    显示不出来需要再加一个属性: border-style:solid;

    啊 漏了..补上

  5. ryadav96 commented on Feb 13, 2021

    @ryadav96
    ryadav96
    on Feb 13, 2021
    More actions

    Using clip-path property

    .triangle {
    width:200px;
    height: 200px;
    background-color: #119933;
    clip-path: polygon(50% 0, 50% 0, 100% 100%, 0 100%);
    }

    Reacted by fxwing, 王畅, Mingwei Deng, Kim Yang, Mengyuan Liu, catcher and hanshuo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    字节

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.