我希望文本仅在移动设备上居中对齐。在桌面上,文本应右对齐。
@media only screen and (min-device-width: 320px) and (max-device-width: 800px) {
.centerMobileOnly {
text-align: center !important;
}
}
@media only screen and (min-device-width: 600px) {
.rightDesktopOnly {
text-align: right !important;
}
}
<div>
<h3 class="rightDesktopOnly centerMobileOnly">02:00</h3>
</div>
答案 0 :(得分:1)
您不必为媒体css添加两个类,而只能通过单个类。
.centerMobileOnly{
text-align: right;
}
@media (max-device-width: 800px) {
.centerMobileOnly {
text-align: center;
}
}
<div>
<h3 class="centerMobileOnly">02:00</h3>
</div>