How do I style part of the pseudo element content: "..."

sdvnksv

I am inserting a FontAwesome icon along with some text from the data attribute in a div pseudo element:

<div data-date="Mar 01, 2016"></div>

div:before {
  content: "\f073" attr(data-date);
  font-family: "FontAwesome", sans-serif;
}

https://jsfiddle.net/cn0vhns9/

Now what I want is to increase the size of the icon and put the text right under it with some margin. While putting the text content under the icon seems achievable (if I fix the width of the pseudo element), I can't think of the way to increase the size of the icon without increasing the size of the text content as well. Any ideas?

Anton

It is possible even in your case. Please, see the updated fiddle at https://jsfiddle.net/cn0vhns9/3/. You will have to style the icon as a pseudo-element (::first-letter, or alternatively :first-letter with just a single semicolon for compatibility reasons).

My answer only demonstartes the problem with different font-size.

CSS

div:before {
  content: "\f073" attr(data-date);
  font-family: "FontAwesome", sans-serif;
  padding: 20px;
  color: black;
  font-size: 20px;
}

div::first-letter {
  font-size: 40px;
  font-family: "FontAwesome", sans-serif;
}

HTML

<div data-date="Mar 01, 2016">

</div>

However, I consider this solution to be a bit hacky. Most likely I would separate the icon and the date and place each of them into a separate HTML tag if possible.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I style the content in a child element?

From Dev

IE 11 considers pseudo content as part of element content

From Dev

How do I resize an image in a pseudo-element?

From Dev

How do I vertically center a pseudo element image in CSS?

From Dev

How do I make pseudo element :before stay active?

From Dev

How do I override CSS set on a pseudo element?

From Dev

How do I update the StatusBar Style as part of a custom transition

From Dev

How do I update the StatusBar Style as part of a custom transition

From Dev

Pseudo element content with JQuery

From Dev

Can I use AngularJs Directives to apply a style to a pseudo Element

From Dev

Can I use AngularJs Directives to apply a style to a pseudo Element

From Dev

How do I restrict style to affect content only in modal?

From Dev

how do I recreate the sencha style gesture scroll for lists and content?

From Dev

How do I cut off part of an element, but keep it available in the DOM?

From Dev

How do I get web browser element's css style?

From Java

How do I apply a style to all children of an element

From Dev

How do I style the gold-email-input Polymer element?

From Dev

How do I access an element of a parent template style in XAML?

From Dev

How do I set the style.top property of an element in JavaScript?

From Dev

Pseudo-Element state - How to append a style to the state of after/before?

From Dev

How do I use pseudo-elements to display content after the main item?

From Java

How do I add / insert a before or after pseudo element into Chrome's Inspector?

From Dev

How do I show :before pseudo-element with negative absolute position in IE

From Java

What is the ::content/::slotted pseudo-element and how does it work?

From Dev

How to inserted HTML tag from pseudo-element content:

From Dev

How to inserted HTML tag from pseudo-element content:

From Dev

How to remove element after pseudo-content with jQuery

From Dev

How do I change the HTML content of a dynamically generated element in Jquery

From Dev

How do I remove an element but not its content with javascript?

Related Related

  1. 1

    How do I style the content in a child element?

  2. 2

    IE 11 considers pseudo content as part of element content

  3. 3

    How do I resize an image in a pseudo-element?

  4. 4

    How do I vertically center a pseudo element image in CSS?

  5. 5

    How do I make pseudo element :before stay active?

  6. 6

    How do I override CSS set on a pseudo element?

  7. 7

    How do I update the StatusBar Style as part of a custom transition

  8. 8

    How do I update the StatusBar Style as part of a custom transition

  9. 9

    Pseudo element content with JQuery

  10. 10

    Can I use AngularJs Directives to apply a style to a pseudo Element

  11. 11

    Can I use AngularJs Directives to apply a style to a pseudo Element

  12. 12

    How do I restrict style to affect content only in modal?

  13. 13

    how do I recreate the sencha style gesture scroll for lists and content?

  14. 14

    How do I cut off part of an element, but keep it available in the DOM?

  15. 15

    How do I get web browser element's css style?

  16. 16

    How do I apply a style to all children of an element

  17. 17

    How do I style the gold-email-input Polymer element?

  18. 18

    How do I access an element of a parent template style in XAML?

  19. 19

    How do I set the style.top property of an element in JavaScript?

  20. 20

    Pseudo-Element state - How to append a style to the state of after/before?

  21. 21

    How do I use pseudo-elements to display content after the main item?

  22. 22

    How do I add / insert a before or after pseudo element into Chrome's Inspector?

  23. 23

    How do I show :before pseudo-element with negative absolute position in IE

  24. 24

    What is the ::content/::slotted pseudo-element and how does it work?

  25. 25

    How to inserted HTML tag from pseudo-element content:

  26. 26

    How to inserted HTML tag from pseudo-element content:

  27. 27

    How to remove element after pseudo-content with jQuery

  28. 28

    How do I change the HTML content of a dynamically generated element in Jquery

  29. 29

    How do I remove an element but not its content with javascript?

HotTag

Archive