所有文本都显示在 div 之间的顶部

发布于 2025-01-20 14:44:55 字数 1115 浏览 0 评论 0原文

我想在box-left divs上方的Akita INU和Cockapoo标签中,而是大多数标签都堆叠在Divs之间的中间。我试图将两个Divs放在一个Div中,但它不起作用。

.box-left {
  clear: all;
  float: left;
  border: 1px solid black;
  width: 600px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}

.box-right {
  float: right;
  border: 1px solid black;
  width: 600px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}
  <div class="label">Akita Inu</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

  
  <div class="label">Cockapoo</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

  <div class="label">Corgi</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

  <div class="label">Shiba Inu</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

I want to make the Akita Inu and Cockapoo labels just above box-left divs but instead most of the labels just stacked in the middle between divs. I tried to put two divs in one div like but it didn't work.

.box-left {
  clear: all;
  float: left;
  border: 1px solid black;
  width: 600px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}

.box-right {
  float: right;
  border: 1px solid black;
  width: 600px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}
  <div class="label">Akita Inu</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

  
  <div class="label">Cockapoo</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

  <div class="label">Corgi</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

  <div class="label">Shiba Inu</div>
  <div class="box-left"></div>
  <div class="box-right"></div>

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

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

发布评论

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

评论(4

俏︾媚 2025-01-27 14:44:55
.box-container{
  display:flex;
  justify-content: space-between;
  min-width: 600px;
  min-height: 200px;
}
.box {
  width: 300px;
  height: 200px;
  margin-top: 15px;
  margin-bottom: 15px;
  border: 2px solid black;

}
 <div class="label">Akita Inu</div>
 <div class="box-container">
  <div class="box"></div>
  <div class="box"></div>
</div>
  
  <div class="label">Cockapoo</div>
 <div class="box-container">
  <div class="box"></div>
  <div class="box"></div>
</div>

如果我了解您将要做什么,我认为它将与风格变化非常有效。

.box-container{
  display:flex;
  justify-content: space-between;
  min-width: 600px;
  min-height: 200px;
}
.box {
  width: 300px;
  height: 200px;
  margin-top: 15px;
  margin-bottom: 15px;
  border: 2px solid black;

}
 <div class="label">Akita Inu</div>
 <div class="box-container">
  <div class="box"></div>
  <div class="box"></div>
</div>
  
  <div class="label">Cockapoo</div>
 <div class="box-container">
  <div class="box"></div>
  <div class="box"></div>
</div>

If I understand what you're about to do, I think it will work very well with the style change.

溺ぐ爱和你が 2025-01-27 14:44:55

不要使用浮子。它们是一种过时且麻烦的技术。相反,使用内联容器或 flexbox

.box-wrapper {
  display: inline-block;
  width: 600px;
}

.label {
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
}

.box-left {
  border: 1px solid black;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}
<div class="box-wrapper">
  <div class="label">Akita Inu</div>
  <div class="box-left"></div>
  <div class="box-right"></div>
</div>

<div class="box-wrapper">
  <div class="label">Cockapoo</div>
  <div class="box-left"></div>
  <div class="box-right"></div>
</div>

Don't use floats. They're an outdated and troublesome technique. Instead, use inline-block containers or flexbox.

.box-wrapper {
  display: inline-block;
  width: 600px;
}

.label {
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
}

.box-left {
  border: 1px solid black;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}
<div class="box-wrapper">
  <div class="label">Akita Inu</div>
  <div class="box-left"></div>
  <div class="box-right"></div>
</div>

<div class="box-wrapper">
  <div class="label">Cockapoo</div>
  <div class="box-left"></div>
  <div class="box-right"></div>
</div>

不顾 2025-01-27 14:44:55

为此使用Flex。通常应该避免浮子和绝对。

.label {
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
}

.box-left,
.box-right {
  border: 1px solid black;
  width: 600px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}

.container {
  display: flex;
}
<div class='container'>
  <div>
    <div class="label">Akita Inu</div>
    <div class="box-left"></div>
  </div>
  
  <div>
    <div class="label"> </div>
    <div class="box-right"></div>
  </div>
</div>

<div class='container'>
  <div>
    <div class="label">Cockapoo</div>
    <div class="box-left"></div>
  </div>

  <div>
    <div class="label"> </div>
    <div class="box-right"></div>
  </div>
</div>

Use flex for this. Floats and absolutes should generally be avoided.

.label {
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
}

.box-left,
.box-right {
  border: 1px solid black;
  width: 600px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}

.container {
  display: flex;
}
<div class='container'>
  <div>
    <div class="label">Akita Inu</div>
    <div class="box-left"></div>
  </div>
  
  <div>
    <div class="label"> </div>
    <div class="box-right"></div>
  </div>
</div>

<div class='container'>
  <div>
    <div class="label">Cockapoo</div>
    <div class="box-left"></div>
  </div>

  <div>
    <div class="label"> </div>
    <div class="box-right"></div>
  </div>
</div>

不气馁 2025-01-27 14:44:55

添加clear: to .box-left将其放在上面的浮动项目下方。要将标签放在上方的Divs下方,请将其应用于.label

.label {
  clear: both;
}

.box-left {
  clear: both;
  float: left;
  border: 1px solid red;
  width: 250px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}

.box-right {
  float: right;
  border: 1px solid blue;
  width: 250px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}
<div class="label">Akita Inu</div>
<div class="box-left"></div>
<div class="box-right"></div>


<div class="label">Cockapoo</div>
<div class="box-left"></div>
<div class="box-right"></div>

<div class="label">Corgi</div>
<div class="box-left"></div>
<div class="box-right"></div>

<div class="label">Shiba Inu</div>
<div class="box-left"></div>
<div class="box-right"></div>

Add clear: both to .box-left to put it below the floated item above it. And to put the labels below the divs above them, apply the same to .label

.label {
  clear: both;
}

.box-left {
  clear: both;
  float: left;
  border: 1px solid red;
  width: 250px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}

.box-right {
  float: right;
  border: 1px solid blue;
  width: 250px;
  height: 250px;
  margin-top: 15px;
  margin-bottom: 15px;
}
<div class="label">Akita Inu</div>
<div class="box-left"></div>
<div class="box-right"></div>


<div class="label">Cockapoo</div>
<div class="box-left"></div>
<div class="box-right"></div>

<div class="label">Corgi</div>
<div class="box-left"></div>
<div class="box-right"></div>

<div class="label">Shiba Inu</div>
<div class="box-left"></div>
<div class="box-right"></div>

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