【问题标题】:Material ui - How would i add small triangle in the corner?Material ui - 我将如何在角落添加小三角形?
【发布时间】:2018-07-26 11:59:22
【问题描述】:

我试图在我的 MUI 按钮中获得这样的结果 - http://jsfiddle.net/bcGdJ/3160/

我最终得到了这个,但似乎 beforeafter css 选择器都不起作用。

import React from "react";
import Button from "@material-ui/core/Button";
import Notifications from "@material-ui/icons/Notifications";
import "./box.css";

const styles = {
    color: 'purple',
    backgroundColor: 'gray',
    minWidth: '40px',
    minHeight: '40px',
    borderRadius: 1,
    position: "relative",
    "&:before,&:after": {
      content: '',
      position: "absolute",
      bottom: 0,
      left: 0,
      borderColor: "transparent",
      borderStyle: "solid"
    },
    "&:before": {
      borderWidth: "8px",
      borderLeftColor: "#efefef",
      borderBottomColor: "#efefef",
    },
     "&:after": {
      borderRadius: "3px",
      borderWidth: "5px",
      borderLeftColor: "#fff", /* color of the triangle */
      borderBottomColor: "#fff" /* color of the triangle */
    }
  };

function CustomizedInputs(props) {
  return (
    <div id="container">
      <Button color="primary" style={styles}>
        <Notifications />
      </Button>
    </div>
  );
}

export default CustomizedInputs;

```

https://codesandbox.io/s/72jyr75461

任何帮助将不胜感激

【问题讨论】:

    标签: material-design material-ui


    【解决方案1】:

    你的代码很好,但你错过了一些简单的点。

    您需要使用content: "''" 而不是content: ""

    对于beforeafter,您需要使用:: 而不是:

      cssRoot: {
        color: theme.palette.getContrastText(purple[500]),
        backgroundColor: purple[200],
        minWidth: "40px",
        minHeight: "40px",
        borderRadius: 1,
        position: "relative",
        "&::before,&::after": {
          content: "''",
          position: "absolute",
          bottom: 0,
          left: 0,
          borderColor: "transparent",
          borderStyle: "solid"
        },
        "&::before": {
          borderWidth: "8px",
          borderLeftColor: "#efefef",
          borderBottomColor: "#efefef"
        },
        "&::after": {
          borderRadius: "3px",
          borderWidth: "5px",
          borderLeftColor: "#fffff" /* color of the triangle */,
          borderBottomColor: "#fffff" /* color of the triangle */
        }
      }
    

    https://codesandbox.io/s/541v247qlp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 2011-12-07
      • 2014-09-08
      • 2020-12-15
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      相关资源
      最近更新 更多