Bootstrap 移动设备和桌面设备上的卡片大小不同
Bootstrap Card size different on mobile and desktop
我的桌面上有 Bootstrap 卡片 (bootstrap4),如下所示:
我的手机视图是这样的:
我的html代码是:
<div class="card-deck">
<div class="center card" style="width: 100%;">
<a href="{{ path('qrcodemanual') }}"><img id="qrcheck" class="card-img-top" src="{{ asset('images/mobile_qr_code.png') }}" alt="QR-Code"></a>
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}
{% if qrcodeEnrollStatus == 1 %}
<span class="badge badge-success float-right">{{ '/'|trans }} </span>
{% else %}
<span class="badge badge-secondary float-right">{{ '/'|trans }} </span>
{% endif %}
</h5>
<p class="card-text">{{ 'userhome.qrcode.text'|trans }}</p>
<a href="{{ path('qrcodemanual')}}" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
<div class="center card" style="width: 100%;">
<img class="card-img-top" src="{{ asset('images/OTP.png') }}" alt="OTP">
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}
{% if smsEnrollStatus != null %}
<span class="badge badge-success float-right">{{ '/'|trans }} </span>
{% else %}
<span class="badge badge-secondary float-right">{{ '/'|trans }} </span>
{% endif %}
</h5>
<p class="card-text">{{ '/'|trans }}</p>
<a href="{{ path('smsmanual')}}" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
</div>
<br>
<h5>Other options:</h5>
<br>
<div class="card-deck">
<div class="center card" style="width: 100%;">
<img class="card-img-top" src="{{ asset('images/OTP.png') }}" alt="OTP">
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}
{% if emergencyEnrollStatus == 1 %}
<span class="badge badge-success float-right">{{ '/' |trans }} </span>
{% else %}
<span class="badge badge-secondary float-right">{{ '/' |trans }} </span>
{% endif %}
</h5>
<p class="card-text">{{ '/'|trans }}</p>
<a href="{{ path('emergencypasswordmanual')}}" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
<div class="center card" style="width: 100%;">
<img class="card-img-top" src="{{ asset('images/OTP.png') }}" alt="OTP">
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}</h5>
<p class="card-text">{{ '/'|trans }}</p><br>
<a href="/" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
</div>
我希望桌面视图中的卡片更小。如何在保持移动视图原样的同时执行此操作?
现在当我改变宽度时,移动视图也会受到影响。
您可以使用@media 来控制某些 CSS 仅用于桌面显示,如下所示:
<style>
@media only screen and (min-width : 768px) {
.card {
display: block !important;
width: 25rem !important;
flex:none !important;
}
}
</style>
我的桌面上有 Bootstrap 卡片 (bootstrap4),如下所示:
我的手机视图是这样的:
我的html代码是:
<div class="card-deck">
<div class="center card" style="width: 100%;">
<a href="{{ path('qrcodemanual') }}"><img id="qrcheck" class="card-img-top" src="{{ asset('images/mobile_qr_code.png') }}" alt="QR-Code"></a>
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}
{% if qrcodeEnrollStatus == 1 %}
<span class="badge badge-success float-right">{{ '/'|trans }} </span>
{% else %}
<span class="badge badge-secondary float-right">{{ '/'|trans }} </span>
{% endif %}
</h5>
<p class="card-text">{{ 'userhome.qrcode.text'|trans }}</p>
<a href="{{ path('qrcodemanual')}}" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
<div class="center card" style="width: 100%;">
<img class="card-img-top" src="{{ asset('images/OTP.png') }}" alt="OTP">
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}
{% if smsEnrollStatus != null %}
<span class="badge badge-success float-right">{{ '/'|trans }} </span>
{% else %}
<span class="badge badge-secondary float-right">{{ '/'|trans }} </span>
{% endif %}
</h5>
<p class="card-text">{{ '/'|trans }}</p>
<a href="{{ path('smsmanual')}}" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
</div>
<br>
<h5>Other options:</h5>
<br>
<div class="card-deck">
<div class="center card" style="width: 100%;">
<img class="card-img-top" src="{{ asset('images/OTP.png') }}" alt="OTP">
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}
{% if emergencyEnrollStatus == 1 %}
<span class="badge badge-success float-right">{{ '/' |trans }} </span>
{% else %}
<span class="badge badge-secondary float-right">{{ '/' |trans }} </span>
{% endif %}
</h5>
<p class="card-text">{{ '/'|trans }}</p>
<a href="{{ path('emergencypasswordmanual')}}" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
<div class="center card" style="width: 100%;">
<img class="card-img-top" src="{{ asset('images/OTP.png') }}" alt="OTP">
<div class="card-body">
<h5 class="card-title">{{ '/'|trans }}</h5>
<p class="card-text">{{ '/'|trans }}</p><br>
<a href="/" class="btn btn-primary">{{ '/'|trans }}</a>
</div>
</div>
</div>
我希望桌面视图中的卡片更小。如何在保持移动视图原样的同时执行此操作?
现在当我改变宽度时,移动视图也会受到影响。
您可以使用@media 来控制某些 CSS 仅用于桌面显示,如下所示:
<style>
@media only screen and (min-width : 768px) {
.card {
display: block !important;
width: 25rem !important;
flex:none !important;
}
}
</style>