简体   繁体   English

html div 循环时未关闭

[英]html div not closing when looped through

I need to show my posts from the database in a certain view but I am getting something else.我需要在某个视图中显示数据库中的帖子,但我得到了其他东西。

The outcome I need:我需要的结果: 在此处输入图像描述

The outcome I get:我得到的结果: 在此处输入图像描述

myhtml我的html

 @foreach($posts as $post) <div class="round-post"> <img src="/storage/{{$post->image}}" id = "img-posts" alt=""> <div class="caption"> <div class="model"> S20 Plus </div> <div class="price"> k400 </div> <div class="company- name"> <ul id = org-name-ul> <li class="fix-li"> bocxdddddddddddddddddddd</li> </ul> </div> <div class="company-logo"> <img src="images/brand-img/sm-logo.png" id = "brand-logo" alt=""> </div> <div class="below-img"> <img src="images/brand-img/sm-logo.png" id = "brand-logo" alt=""> <img src="images/cat-logo/phone-logo3.png" id = "cat-logo" alt=""> </div> <hr> <div class="round- details"> <ul> <li> <div class="info-list"> Storage: 8GB</div> </li> <li> <div class="info-list">Ram: 1GB</div> </li> <li> <div class="info-list">Fault: chargin pressure </div> </li> </ul> @endforeach

You can use bootstrap for styling.您可以使用引导程序进行样式设置。 If you can use bootstrap then use card -如果您可以使用引导程序,请使用卡 -

<div class="card" style="width: 18rem;">
  <img class="card-img-top" src="..." alt="Card image cap">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

In your case -在你的情况下 -

 @foreach($posts as $post)
    <div class="round-post card">
        <img src="/storage/{{$post->image}}" id = "img-posts" alt="" class="card-img-top">
        <div class="card-body">
            <div class="caption">
                <div class="model">  S20 Plus </div>
                <div class="price"> k400 </div>
                <div class="company- name">        
                    <ul id = org-name-ul>
                        <li class="fix-li"> bocxdddddddddddddddddddd</li>
                    </ul> 
                </div>
                <div class="company-logo">
                    <img src="images/brand-img/sm-logo.png" id = "brand-logo" alt="">    
                </div>
                <div class="below-img">
                    <img src="images/brand-img/sm-logo.png" id = "brand-logo" alt="">
                    <img src="images/cat-logo/phone-logo3.png" id  = "cat-logo" alt="">
                </div>
                <hr> 
                <div class="round- details">
                    <ul>
                        <li>  
                            <div class="info-list"> Storage: 8GB</div> 
                        </li>
                        <li> 
                            <div  class="info-list">Ram: 1GB</div> 
                        </li>
                        <li>  
                            <div  class="info-list">Fault: chargin pressure </div>  
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
@endforeach

Also, there are few <div> , they have no closing tag.此外, <div>很少,它们没有结束标记。 Please beautify your code for better understanding and readability.请美化您的代码,以便更好地理解和可读性。

Thanks.谢谢。

You are not closing the opening with the round-post class and so each following post is being nested inside the former - creating the effect you see.您没有使用round-post class 关闭开口,因此后面的每个柱子都嵌套在前者内 - 产生您看到的效果。

Your browser is smart enough to make up for the lack of closing tags, which is sometimes a gift and a curse!您的浏览器足够聪明,可以弥补关闭标签的不足,这有时是一种恩赐,也是一种诅咒!

I would also suggest that you look into properly formatting your HTML - perhaps it was just how it carried over to SO, but properly formatted HTML in your editor can help you spot mistakes like this much more easily!我还建议您考虑正确格式化您的 HTML - 也许这就是它转移到 SO 的方式,但在您的编辑器中正确格式化 HTML 可以帮助您更轻松地发现这样的错误!

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

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