如何在CSS中布局?[关闭]

evrscar2  于 2024-01-09  发布在  其他
关注(0)|答案(1)|浏览(144)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
昨天就关门了。
这篇文章是在3小时前编辑并提交审查的。
Improve this question


的数据
我尝试使用CSS网格与2列,但框C将结束在下面的B像这样



有什么建议吗?

编辑(已解决)

其解决方法是:

  • min-content网格的第一行高度
  • 使用order属性重新排序子项目
  • 框B具有2行跨距
  • 在框C上设置色谱柱起点

盒子A、B、C可以是任意高度

  1. .container {
  2. display: grid;
  3. }
  4. .box-a {
  5. height: 500px
  6. }
  7. .box-b {
  8. height: 600px;
  9. }
  10. .box-c {
  11. height: 200px;
  12. }
  13. @media(min-width: 1024px) {
  14. .container {
  15. grid-template-columns: repeat(2, minmax(0, 1fr));
  16. grid-template-rows: min-content 1fr;
  17. }
  18. .box-a {
  19. order: 2;
  20. }
  21. .box-b {
  22. order: 1;
  23. grid-row: span 2 / span 2;
  24. }
  25. .box-c {
  26. order: 3;
  27. grid-column-start: 2;
  28. }
  29. }

字符串
在此演示:https://codepen.io/linus-ang-the-sans/pen/jOJrMKY

u0njafvf

u0njafvf1#

您可以使用媒体查询来实现这一点:在这个例子中,如果设备的宽度超过768像素,它将显示移动的视图,否则桌面一个。

  1. .row-flex {
  2. display: flex;
  3. }
  4. .flex {
  5. display: flex;
  6. flex-direction: column;
  7. width: calc(50% - 6px);
  8. gap: 12px;
  9. padding: 4px;
  10. box-sizing: border-box;
  11. flex-wrap: wrap;
  12. color: white;
  13. }
  14. .a {
  15. height: 300px;
  16. display: flex;
  17. justify-content: center;
  18. align-items: center;
  19. background-color: red;
  20. color: white;
  21. }
  22. .b {
  23. height: 700px;
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. background-color: green;
  28. color: white;
  29. }
  30. .b-mobile {
  31. display: none;
  32. }
  33. .c {
  34. height: 200px;
  35. display: flex;
  36. justify-content: center;
  37. align-items: center;
  38. background-color: blue;
  39. }
  40. @media only screen and (max-width: 768px) {
  41. .flex {
  42. min-width: 100%;
  43. }
  44. .flex:first-of-type {
  45. display: none;
  46. }
  47. .b {
  48. display: none;
  49. }
  50. .b-mobile {
  51. display: flex;
  52. }
  53. }

个字符

展开查看全部

相关问题