根据左侧 div 设置右侧 div 的宽度

Set width of the right div based on left div

我有一个标记,其中我有一个容器,假设宽度为 100%,我在这个容器中有两个 child 元素。第一个 child 的宽度基于此 div 中的文本,然后下一个 div 应该有一个(容器宽度的宽度)-(第一个 child 元素).

请参阅下图进行说明:

在本例中,白框的宽度为 100%,宽度基于其文本内容。绿色 div 应具有(白框宽度)-(红框宽度)。

如何在 CSS 中设置绿色宽度?这是我到目前为止尝试过的:

.ContentItemMenu {
  width: 100%;
  height: 50px;
  /* background-color: bisque; */
  border-bottom: 1px solid #c3c3c3;
}

.ContentTitle {
  width: auto;
  padding: 0 20px;
  height: 100%;
  float: left;
  font-size: 25px;
  font-family: opensansBold;
  text-align: left;
  line-height: 50px;
  background-color: #5144F0;
}

.SubContentTabs {
  width: 100%;
  height: 100%;
  float: left;
  background-color: aquamarine;
}
<div class="ContentItemMenu">
  <div class="ContentTitle">Some text</div>
  <div class="SubContentTabs"></div>
</div>

我是 css 的新手,所以如果需要更多说明,请告诉我。

使用 flexbox - 将 display: flex 添加到 ContentItemMenu 并将 flex: 1 设置为 SubContentTabs - 请参见下面的演示:

.ContentItemMenu {
  display: flex; /* ADDED */
  width: 100%;
  height: 50px;
  /* background-color: bisque; */
  border-bottom: 1px solid #c3c3c3;
}

.ContentTitle {
  width: auto;
  padding: 0 20px;
  height: 100%;
  float: left;
  font-size: 25px;
  font-family: opensansBold;
  text-align: left;
  line-height: 50px;
  background-color: #5144F0;
}

.SubContentTabs {
  width: 100%;
  height: 100%;
  float: left;
  background-color: aquamarine;
  flex: 1; /* ADDED */
}
<div class="ContentItemMenu">
  <div class="ContentTitle">Some text</div>
  <div class="SubContentTabs"></div>
</div>
<br/>
<div class="ContentItemMenu">
  <div class="ContentTitle">Some text here, this is a long text</div>
  <div class="SubContentTabs"></div>
</div>