Align text centered only on mobile

我只是一个虾纸丫 提交于 2019-12-08 01:36:56

问题


I want the text to align centered on mobile only. On desktop the text should align right.

@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>

回答1:


you dont have to add two class for media css you can go through single only.

.centerMobileOnly{
  text-align: right;
}
@media (max-device-width: 800px) {
  .centerMobileOnly {
    text-align: center;
  }
}
<div>
  <h3 class="centerMobileOnly">02:00</h3>
</div>


来源:https://stackoverflow.com/questions/57806744/align-text-centered-only-on-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!