Bootstrap 4 卡没有响应,它只是将它对齐成 1 直行

IT技术 twitter-bootstrap meteor reactjs bootstrap-4
2021-05-05 09:17:06

Bootstrap 4 卡没有响应,它只是将它排成一排。我如何使它响应?当我调整浏览器的大小时,卡片不会重新排列,它在带有react的流星中保留为一行。我想以某种方式重新排列并在调整浏览器宽度时转到下一行。

在此处输入图片说明

BrowseCourseCard = React.createClass ({

    propTypes: {
        courseId: React.PropTypes.string.isRequired,
        title: React.PropTypes.string.isRequired,
        shortDes: React.PropTypes.string.isRequired,
    },

    render() {

        const courseLink = "/browsecourses/" + this.props.courseId

        return(
            <div className="card">
                <img className="card-img-top" src="img/storeImage.png" alt="Card image cap"/>
                <div>
                    <h4 className="card-title">{this.props.title}</h4>
                    <p className="card-text">{this.props.shortDes}</p>
                    <a className="btn btn-primary" href={courseLink}> More Details &raquo; </a>
                    <p className="card-text"><small className="text-muted"> Downloaded 5003 times </small></p>
                </div>
            </div>
        )
    }
})

BrowseCourses = React.createClass({

    mixins: [ReactMeteorData],

    getMeteorData() {
        const sub = Meteor.subscribe('getAllCourses')

        return {
            ready: sub.ready(),
            allCourses: Col_AllCourses.find().fetch()
        }
    },

    render() {

        if (!this.data.ready) {
          return <div>Loading...</div>
        }

        console.log(this.data.allCourses)
        let displayCourses = this.data.allCourses.map((data) => {
            return <BrowseCourseCard key={data._id} courseId={data._id} title={data.title} shortDes={data.short_des}/>
        })

        return (
            <div className="container-fluid">
                <div className="card-deck-wrapper">
                    <div className="card-deck">
                        {displayCourses}
                    </div>
                </div>
            </div>
        )
    }
})
1个回答

我认为你不能因为你正在使用这个card-desk类。这个类设置display: table. 前面的意思是你得到了叠卡或display: table两者之间没有。

一些技术描述,其改变display: tabledisplay: blockdisplay: inline-block请参阅:是否可以使 display:table-cell 布局响应?

因此,请考虑将您的卡片包装在“正常”网格中:

<div class="container"> 


  <div class="row">
    <div class="card col-xs-12 col-md-6 col-lg-3">
      <img class="card-img-top" data-src="..." alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
    <div class="card col-xs-12 col-md-6 col-lg-3">
      <img class="card-img-top" data-src="..." alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
     <!-- Add the extra clearfix for only the required viewport -->
    <div class="clearfix hidden-sm-down hidden-lg-up"></div>
    <div class="card col-xs-12 col-md-6 col-lg-3">
      <img class="card-img-top" data-src="..." alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
    <div class="card col-xs-12 col-md-6 col-lg-3">
      <img class="card-img-top" data-src="..." alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
      </div>
    </div>
    </div>

</div>

</div>

上面的代码并不能保证你的卡片有相同的高度,你可以设置卡片的高度,或者使用Responsive column resets

或者,您可以尝试.card-columns使用媒体查询更改列数:

.card-columns {
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
} 
@media (min-width: 992px)  {
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
}
其它你可能感兴趣的问题