[Tex/LaTex] How to create a box with caption and label like a float


I want to create a box (in which I put extra information for the reader) that behaves like a float. In other words, it should have a caption (outside of the box that says Box 1: Here is my box caption) and label that I can refer to with \cref like any other float.

Most of the solutions using \fbox, \framebox, \usepackage{framed} are all creating the box, but not about the caption and the label.

How to accomplish a floating box?

Best Answer

First as a non-float. Then, as a float. EDITED to put caption outside of box. EDITED to introduce new float, InfoBox.

  \captionof{InfoBox}{Here is my caption\label{fg:A}}
  \caption{Here is my caption\label{fg:B}}  
In boxes \ref{fg:A} and \ref{fg:B}...

enter image description here