drtj40036 2018-09-17 17:10
浏览 143

如何在foreach循环中添加html?

Basically what I need to do foreach three divs and show 5 services from the database.

I don't know how to do that. Can someone explain to me how? I try everything but just I have no idea how to do it. Second div should not be in row. Output be like on image link that I put below.

Thanks in advance.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">

    <div class="row">
        <div class="col-lg-12">
            <div class="row">

               <div class="col-lg-4">
                    <div class="row">
                        <div class="service-img service" style="background-image: url(images/image1.jpg); height: 300px; background-color: red;">
                            <figcaption>
                                <h3>Service Title Goes Here 1</h3>
                            </figcaption>
                            <a href="/detail.php"></a>
                        </div>
                    </div>
                    <div class="row">
                        <div class="service-img service" style="background-image: url(images/image2.jpg); height: 300px; background-color: green;">
                            <figcaption>
                                <h3>Service Title Goes Here 2</h3>
                            </figcaption>
                            <a href="/detail.php"></a>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 service-middle">
                    <div class="service-img service" style="background-image: url(images/image3.jpg); height: 600px; background-color: blue;">
                        <figcaption>
                            <h3>Service Title Goes Here 3</h3>
                        </figcaption>
                        <a href="/detail.php"></a>
                    </div>
                </div>

                <div class="col-lg-4">
                    <div class="row">
                        <div class="service-img service" style="background-image: url(images/image4.jpg); height: 300px; background-color: yellow;">
                            <figcaption>
                                <h3>Service Title Goes Here 4</h3>
                            </figcaption>
                            <a href="/detail.php"></a>
                        </div>
                    </div>
                    <div class="row">
                        <div class="service-img service" style="background-image: url(images/image5.jpg); height: 300px; background-color: pink;">
                            <figcaption>
                                <h3>Service Title Goes Here 5</h3>
                            </figcaption>
                            <a href="/detail.php"></a>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

</div>

</body>
</html>

This should look like this

  • 写回答

3条回答 默认 最新

  • dongzhan1878 2018-09-17 17:17
    关注

    Hmm, I can't test this out yet but try to put this css; What it does is, were setting the height of .service-img.service to 50%. Then on the selector .service-middle>.service-img.service we're adding 100% height.

    Do let me know if this worked and how it looked like on your screen. Thanks.

    PS: dont run snippet, just use the css, bootstrap is not included.

    .service-img.service {
      height: 50%;
    }
    
    .height100{
      height:100px;
    }
    
    .service-middle>.service-img.service{
      height:100% !important;
    }
    <div class="container">
    
      <div class="row">
        <div class="col-lg-12">
          <div class="row height100">
    
    
            <div class="col-lg-4">
              <div class="row">
                <div class="service-img service" style="background-image: url(images/image1.jpg); height: 300px; background-color: red;">
                  <figcaption>
                    <h3>Service Title Goes Here 1</h3>
                  </figcaption>
                  <a href="/detail.php"></a>
                </div>
              </div>
              <div class="row">
                <div class="service-img service" style="background-image: url(images/image2.jpg); height: 300px; background-color: green;">
                  <figcaption>
                    <h3>Service Title Goes Here 2</h3>
                  </figcaption>
                  <a href="/detail.php"></a>
                </div>
              </div>
            </div>
    
            <div class="col-lg-4 service-middle">
              <div class="service-img service" style="background-image: url(images/image3.jpg); height: 618px; background-color: blue;">
                <figcaption>
                  <h3>Service Title Goes Here 3</h3>
                </figcaption>
                <a href="/detail.php"></a>
              </div>
            </div>
    
            <div class="col-lg-4">
              <div class="row">
                <div class="service-img service" style="background-image: url(images/image4.jpg); height: 300px; background-color: yellow;">
                  <figcaption>
                    <h3>Service Title Goes Here 4</h3>
                  </figcaption>
                  <a href="/detail.php"></a>
                </div>
              </div>
              <div class="row">
                <div class="service-img service" style="background-image: url(images/image5.jpg); height: 300px; background-color: pink;">
                  <figcaption>
                    <h3>Service Title Goes Here 5</h3>
                  </figcaption>
                  <a href="/detail.php"></a>
                </div>
              </div>
            </div>
    
    
          </div>
        </div>
      </div>
    
    
    </div>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?