【问题标题】:How to don't scale down element如何不缩小元素
【发布时间】:2019-11-23 22:12:00
【问题描述】:

我需要用这些矩形制作滚动滑块,但是当窗口很小时,矩形会缩小。

我添加图片以便更好地理解。

我尝试设置 div 年的宽度和高度,但没有帮助。

.years-center {
    text-align: center;
    display: flex;
    overflow-x: scroll;
}

.years {
    display: inline-block;
    margin: 10px;
    width: 220px;
    height: 150px;
    background-color: #FFFFFF;
    margin-top: -60px;
    box-shadow: 0 0px 29px rgba(0,0,0,0.15);
}

.years-p {
    font-size: 80px;
    color: rgb(68, 68, 68);
    font-weight: 900;
    line-height: 0.252;
    text-align: center;
    padding-top: 45px;
}

.years-name {
    font-size: 21px;
    font-family: "Muli";
    color: rgb(68, 68, 68);
    font-weight: bold;
    line-height: 1.238;
    text-align: center;
    padding-top: 34px;
}
<div class="years-center">
    <div class="years years1">
        <p class="years-p">8</p>
        <p class="years-name">let na trhu</p>
    </div>
    <div class="years years2">
        <p class="years-p">10</p>
        <p class="years-name">profesionálů</p>
    </div>
    <div class="years years3">
        <p class="years-p">32</p>
        <p class="years-name">stálých klientů</p>
    </div>
    <div class="years years4">
        <p class="years-p">27</p>
        <p class="years-name">věkový průměr</p>
    </div>
</div>

下一个类似的问题在此处的部分中。 答案仅对第一个问题有帮助。

wrong right

HTML

     <div class="trusts-slider">
        <div class="company">
            <div><img src="img/duveruje/prima.png" alt="prima"></div>
            <div><img src="img/duveruje/hayashi.png" alt="hayashi"></div>
            <div><img src="img/duveruje/projekt.png" alt="projekt"></div>
            <div><img src="img/duveruje/heckl.png" alt="heckl"></div>
        </div>
        <div class="company second-company">
            <div><img src="img/duveruje/energy.png" alt="energy"></div>
            <div><img src="img/duveruje/ipconnect.png" alt="ipconnect"></div>
            <div><img src="img/duveruje/rts.png" alt="rts"></div>
            <div><img src="img/duveruje/cejka.png" alt="cejka"></div>
        </div>
    </div>

CSS

.trusts-slider {
    overflow-x: scroll;
}

.company {
    margin-left: 14%;
    margin-right: 14%;
    display: flex;
    justify-content: space-between;
    text-align: center;
    padding-bottom: 17px;
}

.company div {
    padding-top: 50px;
    background-color: white;
    width: 240px !important;
    height: 170px !important;
    box-shadow: 0 0px 29px rgba(0,0,0,0.06);
    margin-left: 10px;
    margin-right: 10px;
}

.second-company {
    padding-bottom: 69px;
}

【问题讨论】:

标签: html css


【解决方案1】:

white-space: nowrap; 可用于阻止元素响应父元素的宽度,但是当 display 设置为 flex 时不起作用。

这应该可以解决问题。

.years-center {
    white-space: nowrap; /* <--- added */
    text-align: center;
    display: block; /* <--- updated */
    overflow-x: scroll;
}

【讨论】:

  • 非常感谢,它工作。但是我有下一个类似的问题,但是这个解决方案不起作用。
  • 看来您这次尝试堆叠它们,在这种情况下,您需要从该父元素的样式中删除 white-space: nowrap;
  • 只有代码的答案很少有用。请您编辑并添加一些关于为什么此代码解决此问题的解释。干杯
  • 对不起,我不明白你认为我如何解决 2 的问题,你能把整个想法写下来吗?
猜你喜欢
  • 1970-01-01
  • 2015-04-22
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 2015-09-28
  • 1970-01-01
  • 2016-09-27
相关资源
最近更新 更多