As a follow-up to this previous question, I'd like to add a title to a <pre>
box, indicating what kind of code is inside it (e.g. R
, sh
, perl
, ...). But I can't use a <div>
as in the previous question, because the <pre>
is generated by another tool (org-mode export). It looks like this:
<pre class="src src-R">
here <- is(the=code)
</pre>
So I'm hoping to create a src-R
class that adds an R
title to the <pre>
box, in pure CSS, or if that's not possible, using some additional Javascript.
Any pointers appreciated!
HTML <legend> tag is used to insert a title or caption to its parent element such as <fieldset>. The <legend> element must be the first child of <fieldset > element. By using <legend> tag with <form> elements, it is easy to understand the purpose of grouped form elements.
The <legend> tag defines a caption for the <fieldset> element.
You can do it using only CSS with .src-R:before
.
See: http://jsfiddle.net/thirtydot/myAhS/
.src-R:before {
content: 'R'
}
.src-Perl:before {
content: 'Perl'
}
.src:before {
position: absolute;
top: -10px;
background: #fff;
padding: 5px;
border: 1px solid #000
}
.src {
position: relative;
padding: 25px 9px 9px 9px;
border: 1px solid #000
}
:before
works in IE8+ and all modern browsers.
If you need IE7 or lower support, JavaScript will be needed.
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