为什么我不能在boostrap中设置procent值

发布于 2025-02-01 10:50:38 字数 938 浏览 0 评论 0原文

我想用(薄棒)制作一个酒吧,但是当我使用bootstrap时,我无法完全控制尺寸。

<template>
  <div class="container-fluid mx-auto">
    <div class="row">
      <div class="square rounded-pill"></div>
      <div class="square rounded-pill"></div>
      <div class="square rounded-pill"></div>
      <div class="square rounded-pill"></div>
    </div>
  </div>
</template>

<script>
export default {
  setup() {},
};
</script>

<style scoped>
.container-fluid {
  border: 3px solid black;
  width: 100%;
  height: 20%;
}

.row {
  display: flex;
  justify-content: space-evenly;
  align-items: center !important;
}

.square {
  width: 10vw;
  height: 3vh;
  background-color: red;
}
</style>

我想将.container-fluid高度设置为50%,但我不能,我想设置.square width and Heightth in%,而我不能,我不能,并且无法设置所有项目都不想对齐中心。 如何描述%和对齐项目中心的尺寸?

I want to make a bar with (thin bar) but as I am using bootstrap, I can't fully control sizes;

<template>
  <div class="container-fluid mx-auto">
    <div class="row">
      <div class="square rounded-pill"></div>
      <div class="square rounded-pill"></div>
      <div class="square rounded-pill"></div>
      <div class="square rounded-pill"></div>
    </div>
  </div>
</template>

<script>
export default {
  setup() {},
};
</script>

<style scoped>
.container-fluid {
  border: 3px solid black;
  width: 100%;
  height: 20%;
}

.row {
  display: flex;
  justify-content: space-evenly;
  align-items: center !important;
}

.square {
  width: 10vw;
  height: 3vh;
  background-color: red;
}
</style>

I want to set the .container-fluid height to 50% but I cant, I want to set .square width and height in % and I can't, and above all the items dont want to align center, in .row justifycontent works, but align items: center don`t?
How can I describe the sizes in % and align items center?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼亦尘 2025-02-08 10:50:38

我建议您在基于视口单元中的任何Bootstrap元素的 width 高度。这些是vhvwvminvmax。百分比无法按照您想要使用它们的方式工作。例如,1VH的值等于1%。请参阅下面的摘要。

对于Align-Items部分,您要实现什么?您想垂直对齐什么?

.container-fluid {
  height: 50vh;
  background-color: lightgrey;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</head>

<body>
  <div class="container-fluid">Lorem ipsum</div>
</body>

</html>

I suggest you to set the width and height of any Bootstrap element in viewport-based units. These are vh, vw, vmin and vmax. Percentages doesn't work the way you want to use them. For example, a value of 1vh is equal to 1% of the viewport height. See the snippet below.

For the align-items part, what are you trying to achieve? What do you want to align vertically?

.container-fluid {
  height: 50vh;
  background-color: lightgrey;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</head>

<body>
  <div class="container-fluid">Lorem ipsum</div>
</body>

</html>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文