How to style dt and dd so they are on the same line?

后端 未结 18 2263
滥情空心
滥情空心 2020-11-27 10:12

Using CSS, how can I style the following:

Mercury
Mercury (0.4 AU from the Sun) is the closest planet to th
18条回答
  •  余生分开走
    2020-11-27 10:46

    I have got a solution without using floats!
    check this on codepen

    Viz.

    dl.inline dd {
      display: inline;
      margin: 0;
    }
    dl.inline dd:after{
      display: block;
      content: '';
    }
    dl.inline dt{
      display: inline-block;
      min-width: 100px;
    }
    



    Update - 3rd Jan 2017: I have added flex-box based solution for the problem. Check that in the linked codepen & refine it as per needs. Thanks!

    dl.inline-flex {
      display: flex;
      flex-flow: row;
      flex-wrap: wrap;
      width: 300px;      /* set the container width*/
      overflow: visible;
    }
    dl.inline-flex dt {
      flex: 0 0 50%;
      text-overflow: ellipsis;
      overflow: hidden;
    }
    dl.inline-flex dd {
      flex:0 0 50%;
      margin-left: auto;
      text-align: left;
      text-overflow: ellipsis;
      overflow: hidden;
    }
    

提交回复
热议问题