Skip to content

Avoid space around css pseudo elements #1834

Answered by mbostock
Martien asked this question in Q&A
Discussion options

You must be logged in to vote

Presumably the technique you’re using is Markdown within opening and closing HTML blocks, like this:

<div class="context">

aloha

</div>

In this case, you can’t prevent the whitespace from being introduced around the resulting paragraph elements. But, you could apply the pseudoelement to the first child instead of the container:

<style>

.context > :first-child::before {
  content: "…";
}

</style>

Alternatively, you can avoid Markdown and instead using a single HTML block. Then you can control the generated HTML more precisely and avoid the undesired whitespace. But you won’t be able to use Markdown within the container.

<div class="context"><p>aloha</p></div>

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Martien
Comment options

@mbostock
Comment options

Answer selected by Fil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants