html - 如何使用 CSS 水平堆叠元素?

标签 html css

我想创建一个自定义音频播放器,基本上:

  • 播放按钮
  • 一个灵活的栏,即适应播放器宽度
  • 播放器右侧的一组按钮,即下载按钮等

对于前两个部分我没有问题(参见 fiddle ),但是对于第二个按钮组我有问题。

我尝试用float:right 放置组,但在这种情况下它被踢出了播放器。然后我尝试为 flexible 栏添加一个 float 属性,但在这种情况下我必须指定它的宽度并且它变得不再灵活。

这是我想要实现的示例图像: enter image description here

这是我目前所拥有的:

HTML:

<div class="player" style="width:500px">
  <div class="group">
    <a class="button" href="#"></a> 
  </div>
  <div class="flexible">
    <div class="bar"></div>
  </div>
  <div class="clear"></div>
</div>

CSS:

.player 
{
    height:24px;
    background-color: #222222;
}

.player .group 
{    
    float:left;
}

.player .group .button,
.player .group2 .button
{
    display: inline-block;
    width:24px;
    height:24px;
    background-color:#444444;
}

.player .group2 
{
    float:right;
}

.player .flexible
{
    box-sizing:border-box;
    overflow:hidden;
}

.player .flexible .bar 
{
    margin : 8px;
    height : 8px;
    background-color:#225599;     
}

JSFiddle: https://jsfiddle.net/grh7sahq/3/

你有什么建议吗?

谢谢

最佳答案

我了解到您希望中心部分具有灵 active 。你可以使用 display: flex。显示它的非常基本的 CSS:

.player{
  background: black;
  height: 100px;
  display: flex;
}

.button{
  background: blue;
  height: 100px;
  width: 24px;
  display: block;
}

.flexible{
  flex: 1;
}
<div class="player" style="width:500px">
  <div class="group">
    <a class="button" href="#"></a> 
  </div>
  <div class="flexible">
    <div class="bar"></div>
  </div>
  <div class="group2">
    <a class="button" href="#"></a>
  </div>
</div>
<br/>

<div class="player" style="width:150px">
  <div class="group">
    <a class="button" href="#"></a> 
  </div>
  <div class="flexible">
    <div class="bar"></div>
  </div>
  <div class="group2">
    <a class="button" href="#"></a>
  </div>
</div>

关于html - 如何使用 CSS 水平堆叠元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38607069/

相关文章:

javascript - 构建动态且响应迅速的图像拼贴

c# - 如何通过 GetElementByClass 选择一个类并以编程方式单击它

javascript - 为什么制作异步 :false cause the CSS to not render?

html - Firefox 中的 CSS box-shadow 显示微弱的顶部边框/阴影

javascript - 保持身份验证状态 Firebase + Chrome 扩展

javascript - 如何使用 Fuel UX Pillbox 作为 HTML 表单中的元素?

css - 自动打破跨度并保持右对齐

css - 如何让背景图片贴在布局底部?

javascript - 绑定(bind)函数作为属性传递 React

javascript - 将图像置于文本之上