I tried to arrange pre[data-code]:before
a width of 100%, but
when I enter a line of code that is long in the pre element and rolled over to the side, I saw the pre[data-code]:before
cut off and it does not look good.
Here is the code:
pre {
background-color: #233948;
font: bold 12px/15px Inconsolata, Monaco, Consolas, "Andale Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;
color: #333;
border: 1px solid #f1c40f;
overflow: auto;
word-wrap: normal;
white-space: pre;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
position: relative;
margin: 10px 0;
padding: 0 7px;
}
pre[data-code] {
padding: 3em 1em 7px;
}
pre[data-code]:before {
content: attr(data-code);
position: absolute;
top: 0;
left: 0;
width: 100%;
background-color: #95a5a6;
text-indent: 10px;
font: bold 12px/20px Arial, Sans-Serif;
color: #FFF;
padding: 7px 0;
}
pre[data-code="CSS"] {
color: #7DDECA;
border-color: #16a085;
}
pre[data-code="CSS"]:before {
background-color: #16a085;
}
<pre data-code="CSS">
pre{background-color:#233948;font:bold 12px/15px Inconsolata,Monaco,Consolas,"Andale Mono","Bitstream Vera Sans Mono","Courier New",Courier,monospace;color:#333;border:1px solid #f1c40f;overflow:auto;word-wrap:normal;white-space:pre;box-shadow:0 1px 2px rgba(0,0,0,0.2);position:relative;margin:10px 0;padding:0 7px}
</pre>
How to solve this problem?