简体   繁体   English

Div盒垂直内联

[英]Div boxes vertically inline

I don't know, how to solve my following css problem, perhaps anybody can help: 我不知道,如何解决我的以下css问题,也许任何人都可以提供帮助:

css问题 I don't know the height of the items, but the width should be 33%. 我不知道物品的高度,但宽度应为33%。 If the max-height of the parent Div box ist reached, the next element should float to the right. 如果达到父Div框的最大高度,则下一个元素应该向右浮动。

Thanks. 谢谢。

Use Flexbox columns. 使用Flexbox列。

https://jsfiddle.net/kirandash/azqjg2kb/ https://jsfiddle.net/kirandash/azqjg2kb/

HTML: HTML:

<ul>
  <li>a</li>
  <li>b</li>
  <li>c</li>
  <li>d</li>
  <li>e</li>
  <li>f</li>
</ul>

CSS: CSS:

ul {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  height: 306px;
  width: 200px;
}
li {
  width: 100px;
  height: 100px;
  background:red;
  color: white;
  text-align: center;
  font-size: 50px;
  line-height: 100px;
  font-weight: bold;
  border: 1px solid white;
  list-style: none;
}

I have created an unordered list which is set as a flex container with a column direction, and allowed wrapping. 我创建了一个无序列表,它被设置为具有列方向的Flex容器,并允许包装。

https://jsfiddle.net/kirandash/azqjg2kb/ https://jsfiddle.net/kirandash/azqjg2kb/

Hope this helps you. 希望这对你有所帮助。 I'm not sure about the structure you have. 我不确定你的结构。 I just created with dummy structure 我刚刚创建了虚拟结构

  .flex-container { display: flex; flex-direction: column; flex-wrap: wrap; justify-content: flex-start; align-content: flex-start; align-items: flex-start; width: 600px; max-height: 250px; } .flex-item { order: 0; flex: 1 1 auto; align-self: flex-start; width: 33.33%; text-align: center; border: 1px solid #777; margin-bottom: 10px; } 
 <div class="flex-container"> <div class="flex-item"> Element 1<br><br><br><br></div> <div class="flex-item">Element 2</div> <div class="flex-item">Element 3</div> <div class="flex-item">Element 4</div> <div class="flex-item">Element 5</div> <div class="flex-item">Element 6</div> <div class="flex-item">Element 7</div> <div class="flex-item">Element 8</div> </div> 

You can try CSS columns. 你可以尝试CSS列。 They are a little bit tricky to use for anything complex but would do what you are asking for. 对于任何复杂的东西来说它们都有点棘手,但它们可以满足您的要求。

Here is a pen but the most important part is outlined below. 这是一支笔,但最重要的部分概述如下。 On the container element, declare the amount of columns, since you want each item to be 33% width, I've put 3 columns. 在容器元素上,声明列数,因为你希望每个项目的宽度为33%,我已经放了3列。 column-gap is the space between each column. column-gap是每列之间的空间。 After that it's important to put each child element to width: 100% as this is percent width of the column, and display: inline-block . 之后,将每个子元素放到width: 100%是很重要的width: 100%因为这是列的宽度百分比,并display: inline-block

.container {
  max-height: 400px;
  columns: 3;
  column-gap: 1rem;
}

.box {
  width: 100%;
  display: inline-block;
}

Read more here 在这里阅读更多

Browser support is here 浏览器支持在这里

.inline{width:100px;background:yellow;white-space:nowrap;display:inline;} .inline {宽度:100像素;背景:黄色;空白:NOWRAP;显示:内联;}

Content forContent forContent for 内容forContent forContent for

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

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