Text changes line on space

2019-03-02 11:58发布

I have a list, which leaves some spaces for indentation purposes and also provides dashed underlying. However the display properties used for this list do no match, causes the text to change line when a space is found. Here is a Fiddle.

The CSS:

.dashed {
    display: block;
    width: 100%;
    height: 90%;
    border-bottom: dashed 2px #54687a;
}
li {
    display: table-row;
}
li span {
    display: table-cell;
    padding-right: 1em;
}

I tried to keep only one display property, but that failed. Anyone has a fix for this please?


Let's speak with images!

What happens now - it's the problem:

enter image description here

Desired result:

enter image description here

5条回答
啃猪蹄的小仙女
2楼-- · 2019-03-02 12:24

UPDATED - Final css should be like

ul li span {
    background: url("../img/arrow.png") 0 50% no-repeat;
    background: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/arrow.svg") 0 50% no-repeat;
    list-style-type: none;
    padding-left: 12px;
}
.dashed {
  border-bottom: 2px dashed #54687a;
  display: block;
  width: 58%;
  margin-bottom:10px;
}
li {
    display: table-row;
    padding-bottom:5px;
}
li span {
    display: inline-block;
    padding-right: 1em;
    width:23%;
}

Check the UPDATED demo - http://jsfiddle.net/cmfL2643/21/

查看更多
Lonely孤独者°
3楼-- · 2019-03-02 12:29

Remove the dashed class, and add these styles:

li span:after {
  content: '';
  position: absolute;
  display: block;
  width: 90%;
  margin-left: -12px;               /* compensate for padding-left: 12px; */
  border-bottom: dashed 2px #54687a;
}

Fiddle

查看更多
我命由我不由天
4楼-- · 2019-03-02 12:31

I just updated your fiddle

I added in your CSS

ul li span {
    background: url("../img/arrow.png") 0 50% no-repeat;
    background: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/arrow.svg") 0 50% no-repeat;
    list-style-type: none;
    padding-left: 12px;
    display: inline-block; // added or it can be inline
}
查看更多
兄弟一词,经得起流年.
5楼-- · 2019-03-02 12:32

Are you trying to get it so that everything is in one line, like this?

Name: Charis Spiropoulos

If so, try this:

li span  {
    display: inline-block;
    padding-right: 1em;
}
查看更多
【Aperson】
6楼-- · 2019-03-02 12:49

You'll likely have better luck with display: block; on the list items and display: inline-block; on the span. table-cell is causing the line to wrap around.

li {
    display: display;
    padding: 10px 0px; /* modify as desired */
}
li span {
    width: 50px;    /* Set width as needed so the names line up, even if the span text is different lengths */
    display: inline-block;
    padding-right: 1em;
}

http://jsfiddle.net/daCrosby/cmfL2643/18/

查看更多
登录 后发表回答