【问题标题】:How can I set height of Row/Cols with % in React-Bootstrap/MDBReact?如何在 React-Bootstrap/MDBReact 中使用 % 设置行/列的高度?
【发布时间】:2020-04-10 23:11:06
【问题描述】:

所以基本上我在使用 React-Bootstrap 中的 % 设置行/列的高度时遇到了一点问题。我有一个 8 列的行(我要在此处添加一些按钮、图标、图像和文本字段),它们都必须具有相同的高度。

我确实尝试过仅使用 % 和 height 和 maxHeight 但显然没有成功。我认为 px 毫无意义,因为它会显示在不同分辨率的屏幕上,所以我担心它会搞砸。我确实下载了 MDBreact 并使用了 'className="h-25 d-inline-block"' 但它也没有工作。

     <Container md={12} style={{backgroundColor: "red", margin:"0px", maxWidth: "100%", maxHeight: "85%", height: "85%"}}>

           <Row>
           <Col className="h-25 d-inline-block" style={{backgroundColor: "yellow"}}>Machine 11</Col>
            <Col style={{backgroundColor: "pink"}}> Machine 21</Col>
            <Col style={{backgroundColor: "blue"}}> Machine 31</Col>
            <Col style={{backgroundColor: "purple"}}> Machine 41</Col>
            <Col style={{backgroundColor: "gray"}}> Machine 51</Col>
            <Col style={{backgroundColor: "red"}}> Machine 61</Col>
            <Col style={{backgroundColor: "pink"}}> Machine 71</Col>
            <Col style={{backgroundColor: "magenta"}}> Machine 81</Col>
                </Row>


    </Container>

我确实希望列的高度同样设置为 20/25%(已经制作了 3 行 + 导航栏),但实际上我什么也没得到,除了我用像素来做,但它没有抓住重点。

【问题讨论】:

  • @Goteil 我在下面成功回答了你的问题吗?
  • 是的!谢谢!

标签: reactjs react-bootstrap mdbreact


【解决方案1】:

您将容器的高度设置为 85%,因此其父容器必须具有特定高度。如果容器的父容器没有特定的高度,则必须设置容器高度。

您还需要将每行的高度设置为“h-25”。

这里是一个使用 HTML 的例子(在 react 中效果是一样的)。

/* styling just to show element dimensions */
.container {
  border: 1px dashed green;
  margin-top: 8px;
}
.col {
  border: 1px solid #ccc;
  background-color: #e0e0e0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>

<!-- same as <Container style={{height: 200px}}> -->
<div class="container" style="height: 200px">

  <!-- same as <Row className="h-25"> -->
  <div class="row h-25">
    <div class="col">row1-col-1</div>
    <div class="col">row1-col-2</div>
    <div class="col">row1-col-3</div>
  </div>

  <div class="row h-25">
    <div class="col">row2-col-1</div>
    <div class="col">row2-col-2</div>
    <div class="col">row2-col-3</div>
  </div>

  <div class="row h-25">
    <div class="col">row2-col-1</div>
    <div class="col">row2-col-2</div>
    <div class="col">row2-col-3</div>
  </div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-04
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多