【问题标题】:HTML CSS Styling boxHTML CSS 样式框
【发布时间】:2012-03-30 22:59:56
【问题描述】:

我正在尝试将框格式化为类似于“状态更新”的功能。 目前,这就是它的样子。

理想情况下,我希望框的右上角显示日期,右下角显示“回复”。从图片中可以看出,它并没有真正做到这一点。 非常感谢任何有关如何执行此操作的帮助。

我的 CSS 代码在这里。 http://jsfiddle.net/hKcmu/

非常感谢!

【问题讨论】:

    标签: html css styles


    【解决方案1】:

    添加

    position: relative;
    

    到你的包含 div 然后使用

    boxytest sup
    {
        position: absolute;
        right: 2px;
        top: 2px;
    }
    
    boxytest sub
    {
        position: absolute;
        right: 2px;
        bottom: 2px;
    }
    

    定位日期/回复。

    这是您更新后的Fiddle

    编辑

    你可以在 boxytest 上使用 padding 来处理文本太长的问题,

    这会为日期/回复的文本上下留出足够的空间

    boxytest
      {
        position: relative;
        .....
        padding: 20px 0;
      }
    

    这会在右边腾出空间

    boxytest
      {
        position: relative;
        .....
        padding: 20px 0;
        padding: 4px 120px 4px 0;
      }
    

    更新Fiddle

    【讨论】:

    • 谢谢。我更新了小提琴。 jsfiddle.net/hKcmu/4 如果消息太长,它会覆盖回复/日期。有没有办法让它不这样做?
    【解决方案2】:

    使用position: relativeposition: absolute 的组合:

    boxytest {
        /* all the other CSS */
        position: relative;
    }
    
    boxytest sup {
        position: absolute;
        top: 0;
        right: 0;
        height: 48%;
    }
    boxytest sub {
        position: absolute;
        bottom: 0;
        right: 0;
        height: 48%;
    }​
    

    JS Fiddle demo.

    【讨论】:

    • 谢谢!但是,如果我让第二个框包含回复/日期,由于文本较长,它会“覆盖”回复/日期。 jsfiddle.net/hKcmu/5 有什么办法可以解决这个问题?
    猜你喜欢
    • 2012-04-14
    • 2020-07-16
    • 2014-10-15
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多