【问题标题】:Need help creating basic baseball bases figure需要帮助创建基本的棒球基地图
【发布时间】:2021-08-30 13:19:19
【问题描述】:

我正在尝试创建一个指标,以指示哪些基地上有一个人。我正在使用 bootstrap react 的 Container、Row 和 Col 进行定位,并为三角形创建了自己的 CSS 类。但我遇到的问题是我不知道如何让它们相互接触,从而为底座的形状制作钻石。我也愿意接受任何其他方式。

电流输出

期望的输出

我的组件容器

<Container>
  <Row>
    <Col sm="auto">
        <div className="triangle-blank"></div>
        <div className="triangle-left"></div>
    </Col>
    <Col sm="auto">
        <div className="triangle-left"></div>
        <div className="triangle-right"></div>
    </Col>
    <Col sm="auto">
        <div className="triangle-right"></div>
        <div className="triangle-left"></div>
    </Col>
    <Col sm="auto">
        <div className="triangle-blank"></div>
        <div className="triangle-right"></div>
    </Col>
  </Row>
</Container>

我的 CSS 类

.triangle-left {
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-right: 25px solid #555;
  border-bottom: 20px solid transparent;
}

.triangle-right {
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-left: 25px solid #555;
  border-bottom: 20px solid transparent;
}

.triangle-up {
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-bottom: 25px solid #555;
}

.triangle-down {
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 25px solid #555;
}

.triangle-blank {
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-left: 25px solid transparent;
  border-bottom: 20px solid transparent;
}

CodeSandbox Link

【问题讨论】:

  • 请问您可以使用minimal reproducible example 编辑问题吗?当前的示例没有提供足够的信息来说明为什么要获得该输出
  • 我还能添加什么。我给出了该图所需的代码。除了样板反应组件布局和导入 {Container, Row, Col) from "react-bootstrap; 我在描述中说明了所有这些你想让我给你渲染页面所需的基本反应肉鸡板外,没有别的了?
  • 一个使用引导程序的示例,让我们运行它,这样我们就可以在没有图像的情况下自己查看输出?
  • 刚刚添加了一个 CodeSandbox 链接

标签: javascript html css reactjs react-bootstrap


【解决方案1】:

SVG 会起作用吗?

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0  640 200" preserveAspectRatio="xMinYMin meet">
   <rect id="svgEditorBackground" x="0" y="0" width="640" height="200" style="fill: none; stroke: none;" />
   <g id="e4__group">
      <path d="M-35.815383,-37.476921l-4,4l4,4l4,-4Z" style="fill:white; stroke:black; vector-effect:non-scaling-stroke;stroke-width:1px;" id="e1_shape" transform="matrix(8.13356 0 0 8.13356 372.893 316.834)" />
      <path d="M-40.492315,-32.676928l-4,4l4,4l4,-4Z" style="fill:white; stroke:black; vector-effect:non-scaling-stroke;stroke-width:1px;" id="e4_shape" transform="matrix(8.13356 0 0 8.13356 372.893 316.834)" />
      <path d="M-31.138467,-32.800005l-4,4l4,4l4,-4Z" style="fill:white; stroke:black; vector-effect:non-scaling-stroke;stroke-width:1px;" id="e2_shape" transform="matrix(8.13356 0 0 8.13356 372.893 316.834)" />
   </g>
</svg>

【讨论】:

  • 我不熟悉 。当玩家也在基地时,我需要能够突出显示基地。
  • 这是一个单独的问题,但可以做到。
【解决方案2】:

这是使用 react-bootstrap 和自定义 CSS 的正确解决方案

在我的 React 组件的 render() 中

const styles = {
    grid: {
        paddingLeft: 0,
        paddingRight: 0,
    },
    row: {
        marginLeft: 3,
        marginRight: 0,
    },
    col: {
        paddingLeft: 0,
        paddingRight: 0,
    },
    center: {
        paddingLeft: 0,
        paddingRight: 0,
    },
};

<Container style={styles.grid}>
    <Row style={styles.row}>
        <Col sm="auto" style={styles.col}>
            <div className="diamond second-base active"></div>
        </Col>
    </Row>
    <Row style={styles.col}>
        <Col sm="auto" style={styles.center}>
            <div className="diamond third-base"></div>
        </Col>
        <Col sm="auto" style={styles.col}>
            <div className="diamond first-base"></div>
        </Col>
    </Row>
</Container>

CSS 类

div.diamond.second-base {
  border: 13px solid transparent;
  border-bottom: 13px solid #CBCCCE;
  box-sizing: border-box;
  clear: both;
  color: #6C6D6F;
  font-family: inherit;
  font-size: 100%;
  font-stretch: inherit;
  font-style: inherit;
  font-variant-caps: inherit;
  font-variant-east-asian: inherit;
  font-variant-ligatures: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  height: 0;
  line-height: inherit;
  margin: 0 auto;
  padding: 0;
  position: relative;
  top: -2px;
  vertical-align: baseline;
  width: 0;
}

div.diamond.second-base:after {
  border: 13px solid transparent;
  border-top: 13px solid #CBCCCE;
  content: "";
  height: 0;
  left: -13px;
  position: absolute;
  top: 13px;
  width: 0;
}

div.diamond.second-base.active {
  border: 13px solid transparent;
  border-bottom: 13px solid #0066CC;
  box-sizing: border-box;
  clear: both;
  color: #6C6D6F;
  font-family: inherit;
  font-size: 100%;
  font-stretch: inherit;
  font-style: inherit;
  font-variant-caps: inherit;
  font-variant-east-asian: inherit;
  font-variant-ligatures: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  height: 0;
  line-height: inherit;
  margin: 0 auto;
  padding: 0;
  position: relative;
  top: -2px;
  vertical-align: baseline;
  width: 0;
}

div.diamond.second-base.active:after {
  border: 13px solid transparent;
  border-top: 13px solid #0066CC;
  content: "";
  height: 0;
  left: -13px;
  position: absolute;
  top: 13px;
  width: 0;
}

div.diamond.third-base {
  border: 13px solid transparent;
  border-bottom: 13px solid #CBCCCE;
  box-sizing: border-box;
  color: #6C6D6F;
  float: left;
  font-family: inherit;
  font-size: 100%;
  font-stretch: inherit;
  font-style: inherit;
  font-variant-caps: inherit;
  font-variant-east-asian: inherit;
  font-variant-ligatures: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  height: 0;
  line-height: inherit;
  margin: 0 4px 0 0;
  padding: 0;
  position: relative;
  top: -13px;
  vertical-align: baseline;
  width: 0;
}

div.diamond.third-base:after {
  border: 13px solid transparent;
  border-top: 13px solid #CBCCCE;
  content: "";
  height: 0;
  left: -13px;
  position: absolute;
  top: 13px;
  width: 0;
}

div.diamond.third-base.active {
  border: 13px solid transparent;
  border-bottom: 13px solid #0066CC;
  box-sizing: border-box;
  color: #6C6D6F;
  float: left;
  font-family: inherit;
  font-size: 100%;
  font-stretch: inherit;
  font-style: inherit;
  font-variant-caps: inherit;
  font-variant-east-asian: inherit;
  font-variant-ligatures: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  height: 0;
  line-height: inherit;
  margin: 0 4px 0 0;
  padding: 0;
  position: relative;
  top: -13px;
  vertical-align: baseline;
  width: 0;
}

div.diamond.third-base.active:after {
  border: 13px solid transparent;
  border-top: 13px solid #0066CC;
  content: "";
  height: 0;
  left: -13px;
  position: absolute;
  top: 13px;
  width: 0;
}

div.diamond.first-base {
  border: 13px solid transparent;
  border-bottom: 13px solid #CBCCCE;
  box-sizing: border-box;
  color: #6C6D6F;
  float: right;
  font-family: inherit;
  font-size: 100%;
  font-stretch: inherit;
  font-style: inherit;
  font-variant-caps: inherit;
  font-variant-east-asian: inherit;
  font-variant-ligatures: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  height: 0;
  line-height: inherit;
  margin: 0;
  padding: 0;
  position: relative;
  top: -13px;
  vertical-align: baseline;
  width: 0;
}

div.diamond.first-base:after {
  border: 13px solid transparent;
  border-top: 13px solid #CBCCCE;
  content: "";
  height: 0;
  left: -13px;
  position: absolute;
  top: 13px;
  width: 0;
}

div.diamond.first-base.active {
  border: 13px solid transparent;
  border-bottom: 13px solid #0066CC;
  box-sizing: border-box;
  color: #6C6D6F;
  float: right;
  font-family: inherit;
  font-size: 100%;
  font-stretch: inherit;
  font-style: inherit;
  font-variant-caps: inherit;
  font-variant-east-asian: inherit;
  font-variant-ligatures: inherit;
  font-variant-numeric: inherit;
  font-weight: inherit;
  height: 0;
  line-height: inherit;
  margin: 0;
  padding: 0;
  position: relative;
  top: -13px;
  vertical-align: baseline;
  width: 0;
}

div.diamond.first-base.active:after {
  border: 13px solid transparent;
  border-top: 13px solid #0066CC;
  content: "";
  height: 0;
  left: -13px;
  position: absolute;
  top: 13px;
  width: 0;
}

解决方案链接:codeSandBox

【讨论】:

    猜你喜欢
    • 2012-10-10
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    相关资源
    最近更新 更多