I need to do something like this in css, how to achieve it (look attachment)?
Do I need to use after, before to do something like this or can I do it using only border to do this? Can someone help me with this
Regards
I need to do something like this in css, how to achieve it (look attachment)?
Do I need to use after, before to do something like this or can I do it using only border to do this? Can someone help me with this
Regards
A straightforward solution is to embed the HTML that goes in the square in a <fieldset>
and use <legend>
for the text over the border. Optionally with
before and after the <legend>
text for extra spacing.
fieldset { border-radius: 15px }
legend {
text-transform: uppercase; /* [OPTIONAL] */
margin: 0 auto; /* [OPTIONAL], to center the LEGEND */
}
<fieldset>
<legend> legend </legend>
<p>Some <p> with text.</p>
<div>Some <div> with text.</div>
</fieldset>
This might help get you started:
<div>
with a border<span>
with a white background.border{
border: 3px solid black;
width: 50vw;
height: 50vh;
}
.text{
display: inline-block;
text-align:center;
position: relative;
top: -0.6rem;
left: 50%;
padding: 0 0.5rem;
transform: translateX(-50%);
background-color: white;
}
<div class="border">
<span class="text">SOME TEXT</span>
</div>
position: relative
You can set the wrapper div position relative. As for the title div, set the position to absolute with left, and right values.
Here's the code example.
.wrapper {
border: 1px solid;
border-radius: 10px;
position: relative;
margin: 2rem;
max-width: 400px;
width: 100%;
padding: 1rem;
}
.title {
font-size: 1.5rem;
font-weight: 600;
background-color: white;
position: absolute;
left: 50%;
top: -1rem;
transform: translateX(-50%);
padding: 0 1rem;
}
<div class="wrapper">
<div class="title">
My Heading
</div>
<div>
<p>
my description text
</p>
</div>
</div>