gpt4 book ai didi

css - bootstrap 对齐不同列中的行

转载 作者:行者123 更新时间:2023-12-04 07:20:05 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Align child elements of different blocks

(3 个回答)


10 个月前关闭。




使用以下布局:

  • 绿色:行
  • 紫色:栏目
  • 蓝色、橙色、灰色:分别为一行

  • 果岭可以叠加在较小的屏幕上。我怎样才能实现这种布局?
    目前我没有果岭,所以我不能堆叠,但我可以对齐那些蓝色、橙色和灰色的行。
    enter image description here
    enter image description here
        <div class="row blue">
    <div class="col blue-col"></div>
    <div class="col blue-col"></div>
    <div class="col blue-col"></div>
    <div class="col blue-col"></div>
    <div class="col blue-col"></div>
    </div>
    <div class="row orange">
    <div class="col orange-col"></div>
    <div class="col orange-col"></div>
    <div class="col orange-col"></div>
    <div class="col orange-col"></div>
    <div class="col orange-col"></div>
    </div>
    <div class="row gray">
    <div class="col gray-col"></div>
    <div class="col gray-col"></div>
    <div class="col gray-col"></div>
    <div class="col gray-col"></div>
    <div class="col gray-col"></div>
    </div>
    编辑:
    蓝色和橙色有不同的高度。

    最佳答案

    这段代码有帮助吗? (忽略“jkd”,它们是我用来给出高度的占位符,您可以将它们替换为您需要的任何测量值)

    <body>
    <div class = "container">
    <div class = "row" id = "green-row" style = "border:3px solid green;">
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div>
    </div>
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div> </div>
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div> </div>
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div> </div>
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div> </div>
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div> </div>
    <div id = "purple-row" class = "col-md-2 col-sm-3 mt-5 text-center" style = "border:2px solid purple; margin: 5px 5px 5px 5px">
    <div id = "blue-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: blue">
    jkd
    </div>
    <div id = "orange-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: orange">
    jkd
    </div>
    <div id = "gray-row" class = "col-md-12 mt-5 text-center" style = "margin: 5px 5px 5px 5px; background-color: gray">
    jkd
    </div> </div>
    </div>
    </div>
    <style>
    #purple-row{
    transform: translateX(50%);
    }
    </style>

    您还可以添加这段代码以使所有元素具有相同的高度:
            <script>
    var all = document.getElementsByName("purple-row");
    // alert(all.length)
    maxHeight = 0
    for (var i=0, max=all.length; i < max; i++) {
    // alert(all[i].style.borderColor)
    if(all[i].offsetHeight > maxHeight){
    maxHeight = all[i].offsetHeight;
    }
    }
    alert(maxHeight)
    for (var i=0, max=all.length; i < max; i++) {
    all[i].style.height = maxHeight + "px";
    }

    </script>

    关于css - bootstrap 对齐不同列中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68554698/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com