简体   繁体   English

如何在span标签内定位第二行文本

[英]How to target the second line of text within a span tag

I have a wordpress theme whose list is in the following format, 我有一个wordpress主题,其列表格式如下,

<ul class="ozy-custom-list wpb_content_element ">
 <li>
  <span class="oic oic-dot" style="color:#2f75aa"></span>
  <span>Personalised Services</span>
 </li>
 <li>
  <span class="oic oic-dot" style="color:#2f75aa">
  </span><span>Complete support – from Port to Destination</span>
 </li>
</ul>

The first span is for the bullet and the second contains the text that goes after the bullet. 第一个跨度用于子弹,第二个跨度用于子弹后的文本。

Now in the case of the second li element the text goes to the next line and below the bullet. 现在,在第二个li元素的情况下,文本转到下一行并在项目符号下方。 I would like to add some padding to the second line so it doesn't do below the bullet. 我想在第二行添加一些填充,以便它在项目符号下方不起作用。

Here's a picture to show whats happening, 这是一张图片,显示发生了什么事,

在此处输入图片说明

How can I target the second line (ie "destination") ? 如何定位第二行(即“目标”)?

You can fix that by displaying the dot-span as an inline-block. 您可以通过将点跨度显示为嵌入式块来解决此问题。 Then you can give it a fix width and move it with a negative margin: 然后,您可以为其设置固定宽度并以负边距移动它:

.oic-dot {
    display: inline-block;
    width: 15px;
    margin-left: -20px;
}

I made you this lookalike demo . 我给你做了这个相似的演示

You will probably need to play a bit with the width and margin to adjust it to your website. 您可能需要稍微调整一下宽度和边距,以使其适应您的网站。

If you want to select 2nd line you can use following: 如果要选择第二行,可以使用以下命令:

li+li span+span:first-line{
  color: black;
}
li+li span+span{ /*second line*/
  display: block;
  float: left;
  color: red;
}

JSFiddle: https://jsfiddle.net/ws5rk0sx/ JSFiddle: https ://jsfiddle.net/ws5rk0sx/

If you only need to align all lines equally use just: 如果您只需要使所有线条均等对齐,请使用:

li+li span+span{
  display: block;
  float: left;
}

You want the "text-indent" css property: 您需要“ text-indent” css属性:

li span {
     padding-left: 1.5em;
     text-indent:-1.5em;
}

Text-indent indents the first line, so we push it backwards, but only after we pushed the ENTIRE text to the right. Text-indent缩进使第一行缩进,因此我们将其向后推,但仅在将整个文本推向右侧后才可以。

Yes, you can use the following: 是的,您可以使用以下方法:

li:last-child > span:last-child {
    ...
}

It would probably help however to give your ul an id, so that you could use: 但是,给您的ul一个id可能会有所帮助,以便您可以使用:

#ulid > li:last-child > span:last-child {
    ...
}

Without messing up any other UL's on the page. 不会弄乱页面上的任何其他UL。 If it wasn't the last li in the ul you can use nth type instead of last-child for the li tag ^^ 如果不是ul中的最后一个li,则可以使用nth类型代替li标签的最后一个子元素^^

I've created a JsFiddle here 我在这里创建了一个JsFiddle

I've applied the below css to the span: 我已将以下CSS应用于范围:

.text-span{
    display:block;
    margin-left:5px;
}

If you prefer not to set a class on the element you could also use: 如果您不想在元素上设置类,则还可以使用:

ul > li span:nth-of-type(2){
    display:block;
    margin-left:5px;
}

您可以简单地使用无边框表格;)第一个colm包含子弹,第二个colm包含信息...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM