Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create box with title/legend, in CSS

Tags:

css

org-mode

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!

like image 869
Ken Williams Avatar asked Aug 25 '11 14:08

Ken Williams


People also ask

How do you create a legend in HTML and CSS?

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.

What is bootstrap legend?

The <legend> tag defines a caption for the <fieldset> element.


1 Answers

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.

like image 162
thirtydot Avatar answered Sep 27 '22 16:09

thirtydot