html – 垂直和horinzontally对齐容器中的多个div子

前端之家收集整理的这篇文章主要介绍了html – 垂直和horinzontally对齐容器中的多个div子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我目前有以下代码

我试图垂直和水平对齐div框,以便出现更多的框,它仍然在容器中垂直和水平居中.例如:

enter image description here


适用于容器的4张卡片的示例

enter image description here


12个卡在容器中溢出的情况示例

enter image description here


使用不适合容器的卡片的示例
最佳答案
DEMO

HTML

CSS

  1. .container {
  2. position: relative;
  3. display:table;
  4. background: red;
  5. width:100%;
  6. height: 100%; /* auto is default,you can have ur height here */
  7. }
  8. .container-wrapper {
  9. display: table-cell;
  10. margin:auto;
  11. text-align:center;
  12. font-size:0;
  13. width:90%;
  14. height:90%;
  15. vertical-align:middle;
  16. }
  17. .card {
  18. display: inline-block;
  19. height:100px;
  20. width:100px;
  21. border: 1px solid #ddd;
  22. background: #eee;
  23. margin:10px;
  24. }

DEMO 2 with some height of the container

猜你在找的CSS相关文章