简体   繁体   English

如何解决 CSS flexbox 中的 justify 内容问题? 间隔不能正常工作

[英]How do I fix my justify content issue in CSS flexbox? Space-between not working properly

EDIT: Turns out my code works.编辑:原来我的代码有效。 I just was using a smaller screen computer to view the code.我只是在使用屏幕较小的计算机来查看代码。 Once I moved it to a larger sized screen the space-between worked completely fine.一旦我将它移到更大尺寸的屏幕上,中间的空间就完全正常了。 I thought I was going crazy, but figured out the issue我以为我要疯了,但发现了问题

For some reason, my justify-content: space-between isn't separating my items.出于某种原因,我的 justify-content: space-between 没有分隔我的项目。 The h1, button, and select tags in the.controls class are all next to each other when they should be spaced out with space-between .controls class 中的 h1、button 和 select 标签在它们应该用空格隔开时都彼此相邻

Here is my HTML & CSS and under.controls class justify-content space between isn't spacing the items.这是我的 HTML & CSS 和 under.controls class justify-content space 之间没有间隔项目。 Note I also have 2 other sections in my HTML labeled snare and hihat, but the HTML above is only showing the kick section请注意,我的 HTML 中还有另外 2 个部分标记为军鼓和踩镲,但上面的 HTML 仅显示了底鼓部分

 * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: sans-serif; } i, svg { pointer-events: none; }.kick-pad, .snare-pad, .hihat-pad { width: 5rem; height: 5rem; margin: 1rem 0.5rem; cursor: pointer; }.hihat-track, .snare-track, .kick-track { display: flex; align-items: center; width: 70%; justify-content: space-between; margin-top: 4rem; }.sequencer { display: flex; min-height: 100vh; flex-direction: column; align-items: center; justify-content: center; }.kick, .snare, .hihat { display: flex; }.controls { display: flex; justify-content: space-between; align-self: center; flex: 1; margin: 0rem 2rem; }.controls button { padding: 1rem; border: none; background: rgb(88, 88, 88); color: white; font-size: 1rem; cursor: pointer; transition: all 0.5s ease; }.pad { transition: all 0.5s ease; }.play { padding: 1rem 2rem; font-size: 1.5rem; background: rgb(88, 88, 88); border: none; color: white; cursor: pointer; margin-top: 3rem; } select { padding: 1rem; font-size: 1rem; }
 <div class="sequencer"> <div class="kick-track"> <div class="controls"> <h1>Kick</h1> <button data-track="0" class="mute kick-volume"> <i class="fas fa-volume-mute"></i> </button> <select name="kick-select" id="kick-select"> <option value="./sounds/kick-classic.wav">Classic Kick</option> <option value="./sounds/kick-808.wav">808 Kick</option> <option value="./sounds/kick-heavy.wav">Kick Heavy</option> </select> </div> <div class="kick"> <div class="pad kick-pad b0"></div> <div class="pad kick-pad b1"></div> <div class="pad kick-pad b2"></div> <div class="pad kick-pad b3"></div> <div class="pad kick-pad b4"></div> <div class="pad kick-pad b5"></div> <div class="pad kick-pad b6"></div> <div class="pad kick-pad b7"></div> </div> </div>

Here is an image of what it current looks like and I don't know why they are stuck side by side even though I am using justify-content:space-between.这是当前外观的图像,即使我使用的是 justify-content:space-between,我也不知道为什么它们并排卡住。 在此处输入图像描述

I would recommend adding some kind of width to the class like我建议向 class 添加某种宽度,例如

.controls { width: 20vw; } .controls { width: 20vw; } or .controls { width: 100%; } .controls { width: 20vw; }.controls { width: 100%; } .controls { width: 100%; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM