I have a proposal for some minor tweaks in CSS that fixes problems that don’t come up often, but are really obnoxious when they do.
The attr()
tag can be useful in some situations. Example:
a::after {content:"(" attr(href) ")";font-style:oblique;}
This displays the content of the href
attribute in parenthesis directly after the content of the anchor.
However, there is no way (at least to my knowledge) to get the content of an attribute from the parent of an element.
Let’s say that I want the attr()
function to return the value of the attribute of the <div>
element.
<style>p div span::after {content:attr(attribute) "";}</style>
<p text-data-thing=" world!"><div attribute=" there!"><span>Hello,</span></div></p>
Nothing happens because it attempted to find the value of an attribute that doesn’t exist. (span[attribute]
)
I propose this syntax as a solution: div span::after {content:attr($, attribute) "";}
And if I want to get the value of the <p>
tag’s text-data-thing
attribute:
div span::after {content:attr($$, text-data-thing) "";}
Here are 4 other minor additions:
- Conditional Statement Pseudo Class
- Editing Attributes
- Editing Text Content of Tags
- Using
attr()
Function for more than editingcontent:;
of Pseudo Elements
<input type="text" id="input" />
<div id="has3">Contains String "3"</div>
<textarea id="txt"></textarea>
<span id="changeColor" bg="lime"></span>
CSS code:
#has3:if(not #input[value*="3"] exists) {color:red;}
#has3:if(#input[value*="3"] exists) {color:green;}
#changeColor {content:property-value(#has3, color) "";}
#changeColor {background-color:attr(bg);}
@attribute-content #txt, "value" {content:attr(#input, value) "";}
What do you think should be in CSS or what would you change/add to my ideas?