引导程序-使卡水平滚动

时间:2019-03-26 10:14:28

标签: html css twitter-bootstrap

我正在尝试制作卡片转盘,但是在保持内容可读性方面遇到困难。这是我当前的代码:

.news-article {
    font-family: 'Muli', sans-serif;
    font-size: 0.725rem;
    font-weight: normal;
    line-height: 1.19;
    text-align: left;
    color: #333333;
}

.news-source{
    font-family: 'Muli', sans-serif;
    font-size: 0.675rem;
    font-weight: 800;
    line-height: 1.19;
    text-align: left;
    color: #333333;
}

.white-background{
    background-color: transparent !important;
    border-top: none !important;
}

.card-footer{
    background-color: #fff;
}

@media only screen and (max-width: 813px) {
    .white-background{
        background-color: transparent !important;
        border-top: none !important;
    }


    .article{
        width: 400px !important;
        height: 100px !important;
    }

    .news-box{
        overflow: hidden;
    }
}
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  </head>
  <body>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

    <div class="pt-3">
        <div class="row news-box no-margin flex-row flex-nowrap">
            <div class="card shadow-sm article col m-2">
                <div class="card-body">
                    <div class="news-article">
                        The Economic Times
                    </div>
                </div>
                <div class="card-footer white-background">
                    <div class="news-source">
                        The Economic Times
                    </div>
                </div>
            </div>
            <div class="card shadow-sm article col m-2">
                <div class="card-body">
                    <div class="news-article">
                        VcCircle
                    </div>
                </div>
                <div class="card-footer white-background">
                    <div class="news-source">
                        VcCircle
                    </div>
                </div>
            </div>
        </div>
    </div>

  </body>
</html>

我如何使其具有相同的卡宽度可滚动?

我为每张卡尝试使用col-md-4 col-sm-6 col-xs-6而不是col,但是它不起作用。

我需要宽度等于浏览器中的col-md-4PC's的宽度,但手机中必须具有col-xs-6

任何帮助将不胜感激。

谢谢。

2 个答案:

答案 0 :(得分:1)

我个人建议使用省略号,方法是将此代码添加到.news-article.news-source

overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

如果您想使用溢出,只需将.news-article.news-source设置为white-space: nowrap;并将overflow: auto;设置为article

解决方案01 (使用省略号)

.news-article,
.news-source {

    /* Ellipsis */

    overflow: hidden;
    white-space: nowrap;
    -ms-text-overflow: ellipsis;
    text-overflow: ellipsis;

    color: #333333;
    font-family: 'Muli', sans-serif;
    text-align: left;
}

.news-article {
    font-size: 0.725rem;
    font-weight: normal;
    line-height: 1.19;
}

.news-source {
    font-size: 0.675rem;
    font-weight: 800;
    line-height: 1.19;
}

.white-background {
    background-color: transparent !important;
    border-top: none !important;
}

.card-footer {
    background-color: #fff;
}

@media only screen and (max-width: 813px) {

    .white-background {
        background-color: transparent !important;
        border-top: none !important;
    }


    .article {
        width: 400px !important;
        height: 100px !important;
    }

    .news-box {
        overflow: hidden;
    }
}
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    </head>
    <body>
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

        <div class="pt-3">
            <div class="row news-box no-margin flex-row flex-nowrap">
                <div class="card shadow-sm article col m-2">
                    <div class="card-body">
                        <div class="news-article">
                            The Economic Times
                        </div>
                    </div>
                    <div class="card-footer white-background">
                        <div class="news-source">
                            The Economic Times
                        </div>
                    </div>
                </div>
                <div class="card shadow-sm article col m-2">
                    <div class="card-body">
                        <div class="news-article">
                            VcCircle
                        </div>
                    </div>
                    <div class="card-footer white-background">
                        <div class="news-source">
                            VcCircle
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </body>
</html>

解决方案02 (使用溢出)

.news-article,
.news-source {
    
    /* So that the text remains on one line */
    white-space: nowrap;

    color: #333333;
    font-family: 'Muli', sans-serif;
    text-align: left;
}

.news-article {
    font-size: 0.725rem;
    font-weight: normal;
    line-height: 1.19;
}

.news-source {
    font-size: 0.675rem;
    font-weight: 800;
    line-height: 1.19;
}

.white-background {
    background-color: transparent !important;
    border-top: none !important;
}

.card-footer {
    background-color: #fff;
}

@media only screen and (max-width: 813px) {

    .white-background {
        background-color: transparent !important;
        border-top: none !important;
    }

    .card {
        flex: 0 0 400px !important;
    }

    .news-box {
        overflow: auto;
    }
}
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    </head>
    <body>
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

        <div class="pt-3">
            <div class="row news-box no-margin flex-row flex-nowrap">
                <div class="card shadow-sm article col m-2">
                    <div class="card-body">
                        <div class="news-article">
                            The Economic Times
                        </div>
                    </div>
                    <div class="card-footer white-background">
                        <div class="news-source">
                            The Economic Times
                        </div>
                    </div>
                </div>
                <div class="card shadow-sm article col m-2">
                    <div class="card-body">
                        <div class="news-article">
                            VcCircle
                        </div>
                    </div>
                    <div class="card-footer white-background">
                        <div class="news-source">
                            VcCircle
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </body>
</html>

答案 1 :(得分:0)

您使用了错误的类属性,请将className更改为class。希望它能解决您的问题。谢谢