Is there a CSS selector for text nodes?

前端 未结 2 1643
时光取名叫无心
时光取名叫无心 2020-11-22 00:21

What I would like to do (not in IE obviously) is:

p:not(.list):last-child + :text {
  margin-bottom: 10px;
}

Which would give a text node a

相关标签:
2条回答
  • 2020-11-22 00:53

    You cannot target text nodes with CSS. I'm with you; I wish you could... but you can't :(

    If you don't wrap the text node in a <span> like @Jacob suggests, you could instead give the surrounding element padding as opposed to margin:

    HTML

    <p id="theParagraph">The text node!</p>
    

    CSS

    p#theParagraph
    {
        border: 1px solid red;
        padding-bottom: 10px;
    }
    
    0 讨论(0)
  • 2020-11-22 01:15

    Text nodes cannot have margins or any other style applied to them, so anything you need style applied to must be in an element. If you want some of the text inside of your element to be styled differently, wrap it in a span or div, for example.

    0 讨论(0)
提交回复
热议问题