html - 在 css 水平条形图之前和之后放置文本

标签 html css flexbox

这就是我正在尝试做的事情。我有 CSS 水平条形图。问题是我试图在之前和之后获取一些文本。请查看当前截图enter image description here

.forecasting {
  box-sizing: border-box;
  width: 100%;
  margin: 20px 0;
}

.forecasting p {
  padding: 0;
  letter-spacing: 1px;
  margin: 0 0 15px;
  color: #000;
  font-weight: bold;
}

.forecasting p:nth-child(2) {
  float: right;
  position: relative;
  top: -25px;
}

.forecast-bar {
  box-sizing: border-box;
  background: #fff;
  border: #0000CD 1px;
  border-style: solid;
}

.forecast-todate {
  width: 100%;
  height: 15px;
  background: #0000CD;
}
<div class="forecasting">
  <p>Name of person $30,777,854.19</p>
  <p>$30,777,854.19</p>

  <div class="forecast-bar">
    <div class="forecast-todate" style="width: 90%;"></div>
  </div>
</div>

我怎样才能先获取文本,中间获取条形图,最后获取文本。

最佳答案

这就是你要找的吗?基本上,我已将 flexbox 添加到主 div 中,将子元素排成一行,并使用 align-items: center 将它们水平居中

 .forecasting {
    box-sizing: border-box;
    width: 100%;
    display: flex;
    align-items: center;
 }

.forecasting p {
   padding: 0;
   letter-spacing: 1px;
   color: #000;
   font-weight: bold;
}

.forecast-bar {
    box-sizing: border-box;
    background: #fff;
    border: #0000CD 1px;
    border-style: solid;
    width: 80%;
    padding-right:20px;
    margin-right:10px;
}

.forecast-todate {
   width: 100%;
   height: 15px;
   background: #0000CD;
 }
 <div class="forecasting">
      <p>Name of person </p>

      <div class="forecast-bar" >
         <div class="forecast-todate" ></div>
      </div>
      <p>$30,777,854.19</p>
  </div>

关于html - 在 css 水平条形图之前和之后放置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67390929/

相关文章:

javascript - 单击太快时脚本滞后 [jQuery]

javascript - jQuery 表单验证不起作用?

html - 媒体查询不适用于 chrome 模拟器,但不适用于实际屏幕

Jquery 切换不工作

css - 使用 Apache mod_rewrite 禁用 IE pre SP2 的压缩

javascript - 如果用户聚焦光标,如何停止命令?

html - 将两行垂直堆叠的 Flex 元素与一个全高 Flex 元素相邻对齐

java - 在 CSS 中定位 JSF 2.0 组件

html - 显示一个(n) <li> 基于@media 查询格式化为一个 flexbox

html - 如何删除我的html页面两边的白边