Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sisterAn opened this issue Nov 1, 2020 · 4 comments
Open

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

sisterAn opened this issue Nov 1, 2020 · 4 comments
Labels

Comments

@sisterAn
Copy link
Owner

sisterAn commented Nov 1, 2020

<!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>


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

@sisterAn sisterAn added the 字节 label Nov 1, 2020
@latte03
Copy link

latte03 commented Nov 2, 2020

通过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;
}

@U-LAN
Copy link

U-LAN commented Nov 2, 2020

通过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;

@latte03
Copy link

latte03 commented Nov 2, 2020

通过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;

啊 漏了..补上

@ryadav96
Copy link

Using clip-path property

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants