Bootstrap 4卡没有响应,它只是连续排成一排

时间:2016-02-25 07:14:54

标签: twitter-bootstrap meteor reactjs bootstrap-4

Bootstrap 4卡没有响应,只是将它对齐成一排。如何使其响应?当我调整浏览器的大小时,卡片不会重新排列它会在流星中保持一行反应。我希望以重新排列的方式制作它,并在调整浏览器宽度时转到下一行。

enter image description here

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 个答案:

答案 0 :(得分:1)

我认为你不能因为你正在使用card-desk类。此类设置display: table。前面的意思是你有堆叠卡或display: table之间没有任何内容。

描述了一些技术,将display: table更改为display: block display: inline-block。请参阅:Is it possible to make display:table-cell layout responsive?

因此,请考虑将您的卡片包装在正常的#34;格:

<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;
}