No, there is no such thing as "repeat-content" or something similar in CSS. Your second snippet is the only way to achieve this effect now.
1, an element can only have at most one of any kind of pseudo-element at any time. (This means an element can have both a :before and an :after pseudo-element — it just cannot have more than one of each kind.)
A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to change the font of the first line of a paragraph. Note: In contrast to pseudo-elements, pseudo-classes can be used to style an element based on its state.
First, hover over the element you want to copy. Then, right-click on it and choose the option “Inspect”. On the left side is the HTML DOM tree, and on the right side, the CSS styles of the selected element. Having the right element selected on the HTML DOM tree, right-click on it and choose “Copy” > “Copy styles”.
No, you can't.
See Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQuery. To repeat what is described there, generated content is not part of the DOM.
In the words of the CSS2.1 spec,
Generated content does not alter the document tree.
Generated content only exists in the visual world of the rendering engine. Selecting is about selecting portions of the DOM. Generated content is not in the DOM, hence cannot be selected. For the same reason, generated counters or list item bullets cannot be selected.
Instead of actually selecting the generated content, you could simulate this with some javascript.
I stumbled over this David Walsh blog, where he provides code that fetches generated content.
Using that, you can append the generated content to the regular content to simulate selection of the generated content, then you can set the generated content with display:none
so that it doesn't appear twice. Like this:
FIDDLE
String.prototype.unquoted = function() {
return this.replace(/(^['"])|(['"]$)/g, '')
}
var element = document.getElementById('div1');
var content = window.getComputedStyle(
element, ':after'
).getPropertyValue('content');
element.innerHTML = element.innerHTML + content.unquoted();
console.log(content.unquoted());
div:after {
content: attr(data-generated);
display: none;
}
<div id="div1" data-generated=" world!">Hello</div>
Well, you'd probably never want to do this, but I left a long comment on the question explaining a particular constraint that I once had, where this could have been a solution.
NB: I do realize that this 'solution' doesn't really select the generated content itself, but decided to post this answer in case somebody out there ever needed a workaround.
Do not store content that should be visible and accessible in data
attributes, because assistive technology may not access them
Check These links :
http://www.karlgroves.com/2013/08/26/css-generated-content-is-not-content/ https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With