0

I inherited code that layers up a font heading - multiple divs draw the font - like this:

<div class = 'stage'>
    <div class = 'layer'></div>
    <div class = 'layer'></div>
    <div class = 'layer'></div>
    <div class = 'layer'></div>
</div> 

The text itself is defined in the css under "layer.after" as "content: "xyz!"".

My aim is to style the "!" in "XYZ" in a different font... if the content was in the HTML section I could just add a span.

But here, my text is defined in Content in css.... How can I style the last letter differently than the rest in this type of setup, or add a span to the css, or even a short script to change the last letter (!) to a different font? I've tried last letter selector to no avail.

3 Answers 3

1

Using pseudoclasses on pseudoelements is not allowed. Therefore what you want is not possible without changing existing code.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, it can be kind of achieved by applying pseudo elements to pseudo elements (like "intersecting" them). But this hack has too many limitations to be usable in practice.
1

Is there some actual text in HTML? If not you can use ::before for your text and ::after for "!" - JSFiddle

CSS

.layer::before { 
    content: 'xyz';
    color: blue;
    font-weight: bold;
}
.layer::after { 
    content: '!';
    color: red;
    font-weight: bold;
}

Comments

0

You'll need to use some script if changing the markup is not an option.

If you have jQuery available, try something like this:

$(function() {

  $(".stage .layer").each(function() {
    var content = $(this).html();
    content = content.substr(0, content.length - 1)
      + "<span>"
      + content.substr(-1)
      + "</span>";
    $(this).html(content);
  });


})

See http://codepen.io/ondrakoupil/pen/VLBoXR for live example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.