Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a box with a title on its border in HTML? [closed]

Tags:

html

css

If there any way to make a box looks like the one here with HTML/CSS:

enter image description here

like image 748
user5955461 Avatar asked Feb 20 '16 13:02

user5955461


People also ask

How do I display text around a border in HTML?

For the four borders, we need four <fieldset> elements, each containing a <legend> element inside. We add the text that will appear at the borders inside the <legend> elements. To begin, we stack the <fieldset> elements on top of each other in a grid cell and give them borders.

How do you fill a box in HTML?

Put the text inside a header or <p> inside the <div></div> Then it will be inside the box.


2 Answers

You may be looking for the HTML fieldset and legend elements, which apply to forms.

From MDN:

<fieldset>

The HTML <fieldset> element is used to group several controls as well as labels (<label>) within a web form.

<label>

The HTML Label Element (<label>) represents a caption for an item in a user interface.

As mentioned before, the fieldset and legend elements are used when creating forms.

If you just want to put a label box on a border, you can use absolute positioning, like this:

HTML

<div id="container">
    <div id="label">I'm a Box</div>
</div>

CSS

#container {
    height: 100px;
    width: 300px;
    border: 1px solid black;
    position: relative;
}

#label {
    position: absolute;
    top: -10px;
    left: 20px;
    height: 20px;
    width: 100px;
    background-color: pink;
    border: 2px solid red;
    text-align: center;
}

The above code renders this:

enter image description here

DEMO

like image 84
Michael Benjamin Avatar answered Oct 02 '22 18:10

Michael Benjamin


you can use "position absolute", something like below:

.a {
  margin-top: 50px;
  height: 100px;
  width: 100%;
  border: 2px solid red;
}

.b {
  position: absolute;
  top: 40px;
  left: 20px;
  border: 2px solid red;
  height: 20px;
  width: 20%;
  background-color: white;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<div class="a">
  <div class="b">test</div>

</div>

</body>
</html>
like image 45
liusy182 Avatar answered Oct 02 '22 18:10

liusy182