简体   繁体   English

引导程序-卡无法正常工作

[英]Bootstrap - Cards not working properly

I am following the examole from the first example on this page https://mdbootstrap.com/components/cards/ (trying to get same output) 我正在遵循此页面上第一个示例的示例, https ://mdbootstrap.com/components/cards/(试图获得相同的输出)

 <!--Card--> <div class="card"> <!--Card image--> <img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20%282%29.jpg" alt="Card image cap"> <!--Card content--> <div class="card-body"> <!--Title--> <h4 class="card-title">Card title</h4> <!--Text--> <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">Button</a> </div> </div> <!--/.Card--> 

However, all i get is this ? 但是,我得到的只是这个吗? any suggestions 有什么建议么

在此处输入图片说明

I have added a different bootstrap link, hope this matches with your requirement 我添加了其他引导链接,希望它与您的要求匹配

Try this 尝试这个

 .card-body{ padding: 2rem; } 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous"> <div class="container"> <!--Card--> <div class="card"> <!--Card image--> <img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20%282%29.jpg" width="550rem" alt="Card image cap"> <!--Card content--> <div class="card-body"> <!--Title--> <h4 class="card-title">Card title</h4> <!--Text--> <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">Button</a> </div> </div> <!--/.Card--> </div> 

First of all, it's not pure bootstrap, you need add reference to mdb.min.css (you can download it from here ). 首先,它不是纯粹的引导程序,您需要添加对mdb.min.css引用(您可以从此处下载)。 Second, you need to limit the width of the div. 其次,您需要限制div的宽度。 like 300 px as an example (you could change it to whatever you like): 例如300 px(您可以将其更改为任意值):

.card{
 width:300px;
}

I tried it and can see the card is same as the website. 我尝试过,可以看到该卡与网站相同。

You didn't set any width in your parent div . 您没有在父div设置任何宽度。 that's why div automatically shows full width. 这就是div自动显示全宽的原因。 First you need to add width like below code or use col-md-* 首先,您需要像下面的代码一样添加宽度或使用col-md-*

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/css/mdb.min.css"> <!--Card--> <div class="card" style="width: 23rem;"> <!--Card image--> <img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20%282%29.jpg" alt="Card image cap"> <!--Card content--> <div class="card-body"> <!--Title--> <h4 class="card-title">Card title</h4> <!--Text--> <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">Button</a> </div> </div> <!--/.Card--> 

You have to follow the tutorial from getting started they are other css class that comes after content. 您必须从入门开始遵循教程,它们是内容之后的另一个CSS类。 Eg container-fluid etc. Ensure you follow the tutorial from beginning and ensure your have the library link properly to your page or download it and try it locally. 例如,容器流体等。请确保从一开始就遵循本教程,并确保将库正确链接到您的页面,或者下载该库并在本地尝试。 They are classes missing and card class is supposed to have the box-shadow property while container-fluid or content-fluid give the section the appropriate padding. 它们是缺少的类,卡片类应该具有box-shadow属性,而容器流体或内容流体为该部分提供适当的填充。 Hope this help 希望有帮助

Check the order of files including first of all jquery is required then bootstrap and after that mdb file should be include 检查文件的顺序,包括所有jquery首先是必需的,然后进行引导,然后应包含该mdb文件

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/js/mdb.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/css/mdb.min.css" rel="stylesheet"/> <div class='container-fluid'> <div class='section'> <!--Card--> <div class="card" style='width:23rem;'> <!--Card image--> <img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20%282%29.jpg" alt="Card image cap"> <!--Card content--> <div class="card-body"> <!--Title--> <h4 class="card-title">Card title</h4> <!--Text--> <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">Button</a> </div> </div> <!--/.Card--> </div> </div> 

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

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