【问题标题】:CSS for stacking columns one on top of the other用于将列堆叠在一起的 CSS
【发布时间】:2016-06-01 19:21:52
【问题描述】:

我希望有两列(左列与 right 对齐文本,右列与 left 对齐文本)文档的大小调整到一定宽度以下。发生这种情况时,我还希望将两个文本的对齐方式更改为 center

问题:如何使用纯 css(非 css3 或 JavaScript)实现此目的?

编辑:这是我第一次解决当宽度减小但对齐方式当然保持右/左时将列堆叠在一起的问题。

<div style="max-width: 500px;">
    <div style="min-width: 240px; display: inline-block; font-weight: bold; text-align: right;">Delivery date:</div>
    <div style="min-width: 240px; display: inline-block; text-align: left;">Tuesday 24 May</div>
</div>

【问题讨论】:

  • 你能把代码分享给我们吗?

标签: html css layout


【解决方案1】:

同样使用媒体查询

HTML

<div style="max-width: 500px;">
    <div style="min-width: 240px; display: inline-block; font-weight: bold;" class="text-right">Delivery date:</div>
    <div style="min-width: 240px; display: inline-block;" class="text-left">Tuesday 24 May</div>
</div>

CSS

text-left{
  text-align:left;
}
.text-right{
  text-align:right;
}
@media (max-width:991px){
  .text-left, .text-right{
     text-align:center;
  }
}

【讨论】:

  • 好答案,阿卡什,谢谢。事情是 - 我也不能使用@media。糟糕的是,我在最初的问题中没有提到这一点!
  • @David 谢谢,我认为没有其他方法。我可以知道你的建筑在哪个平台上你不能使用任何东西
  • 这将进入电子邮件,因此受到限制。我已经尝试过 Foundation 的电子邮件,但无济于事。
猜你喜欢
  • 1970-01-01
  • 2022-01-13
  • 2017-11-21
  • 2022-12-21
  • 2010-12-26
  • 1970-01-01
  • 2020-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多