复杂的Flexbox布局

发布于 2025-02-04 06:52:57 字数 1197 浏览 0 评论 0原文

我总是在flexbox上挣扎。这次也不例外,试图解决这个稳定的小时并阅读许多类似的问题,但是这些都没有给我正确的想法,即如何处理我的布局。我希望你们中的某些人可以帮助我解决如何做到这一点:)

我正在创建一个迷人行者。它所需的外观就像:

”在此处输入图像描述“

“在此处输入图像描述”

目前看起来像这样:

”

这是我当前的CSS文件:

.MiniPlayer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    display: flex;
    flex-direction: row;

img{
    width: auto;
    height: 90%;
    max-height: 100px;
    max-width: 100px;
    flex-direction: column;
}

.Title{
    flex-direction: column;
    flex-wrap: wrap;
}

.Name{
    flex-direction: column;
    flex-wrap: wrap;
}

.MediaButton{
    flex-direction: row;
}

.Slider{
    flex-direction: column;
    flex-wrap: wrap;
    flex-grow: 4;
}

I always struggle with flexboxes. This time is no exception trying to solve this for a solid hour and read a lot of similar questions but none of these gave me the right idea on how to do it with my layout. I hope that some of you could help me out with how to do this :)

I'm creating a MiniPlayer. The desired look of it is like that:

enter image description here

enter image description here

At the moment it looks like this:

enter image description here

This is my current css file:

.MiniPlayer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    display: flex;
    flex-direction: row;

img{
    width: auto;
    height: 90%;
    max-height: 100px;
    max-width: 100px;
    flex-direction: column;
}

.Title{
    flex-direction: column;
    flex-wrap: wrap;
}

.Name{
    flex-direction: column;
    flex-wrap: wrap;
}

.MediaButton{
    flex-direction: row;
}

.Slider{
    flex-direction: column;
    flex-wrap: wrap;
    flex-grow: 4;
}

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

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

发布评论

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

评论(2

失去的东西太少 2025-02-11 06:52:58

发现我会按照最初的要求添加flexbox解决方案。

* {
  text-align: center;
}

.img,
.title,
.name,
.btn,
.slider {
  border: solid black 2px;
}

.wrapper {
  border: solid 1px orange;
  padding: 1em;
  display: flex;
}

.wrapper-2 {
  margin-left: 1em;
  width: 75%;
  display: flex;
  flex-direction: column;
}

.img {
  width: 25%;
}

.title,
.name {
  width: 50%;
  margin-bottom: 1em;
}

.btn {
  width: 25%;
  margin-bottom: 1em;
}

.space-between {
  display: flex;
  justify-content: space-between;
}
<div class="wrapper">
  <div class="img">img</div>
  <div class="wrapper-2">
    <div class="title">title</div>
    <div class="space-between">
      <div class="name">name</div>
      <div class="btn">btn</div>
    </div>
    <div class="slider">slider</div>
  </div>
</div>

Figured I would add a flexbox solution as initially requested.

* {
  text-align: center;
}

.img,
.title,
.name,
.btn,
.slider {
  border: solid black 2px;
}

.wrapper {
  border: solid 1px orange;
  padding: 1em;
  display: flex;
}

.wrapper-2 {
  margin-left: 1em;
  width: 75%;
  display: flex;
  flex-direction: column;
}

.img {
  width: 25%;
}

.title,
.name {
  width: 50%;
  margin-bottom: 1em;
}

.btn {
  width: 25%;
  margin-bottom: 1em;
}

.space-between {
  display: flex;
  justify-content: space-between;
}
<div class="wrapper">
  <div class="img">img</div>
  <div class="wrapper-2">
    <div class="title">title</div>
    <div class="space-between">
      <div class="name">name</div>
      <div class="btn">btn</div>
    </div>
    <div class="slider">slider</div>
  </div>
</div>

辞旧 2025-02-11 06:52:58

强烈建议您在网格中执行此操作。通过制作许多笨拙的新容器,可以使用网格拥有更好的布局控件。

如果您对网格不太满意,则可以使用 css grid Generator < /a>为您完成工作 - 工作正常。

.parent {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-gap: 5px;
}

.parent div {
  border: 1px solid black;
}

.div1 {
  grid-area: 1 / 1 / 5 / 3;
}

.div2 {
  grid-area: 4 / 3 / 5 / 7;
}

.div3 {
  grid-area: 3 / 6 / 4 / 7;
}

.div4 {
  grid-area: 1 / 3 / 2 / 6;
}

.div5 {
  grid-area: 2 / 3 / 3 / 6;
}
<div class="parent">
  <div class="div1">img</div>
  <div class="div2">slider</div>
  <div class="div3">pause</div>
  <div class="div4">title</div>
  <div class="div5">name</div>
</div>

Would highly recommend doing this in grid. It is possible by making a lot of clumsy new containers, but you have much better layout control with grid.

If you're not too comfortable with grid, you can use a CSS Grid Generator to do the work for you - works just fine.

.parent {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-gap: 5px;
}

.parent div {
  border: 1px solid black;
}

.div1 {
  grid-area: 1 / 1 / 5 / 3;
}

.div2 {
  grid-area: 4 / 3 / 5 / 7;
}

.div3 {
  grid-area: 3 / 6 / 4 / 7;
}

.div4 {
  grid-area: 1 / 3 / 2 / 6;
}

.div5 {
  grid-area: 2 / 3 / 3 / 6;
}
<div class="parent">
  <div class="div1">img</div>
  <div class="div2">slider</div>
  <div class="div3">pause</div>
  <div class="div4">title</div>
  <div class="div5">name</div>
</div>

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