Search code examples
javascripthtmlcssborder

How to add border to a text only and align center


I am new to Html & CSS. I want a heading which contains text like "Women safty". I want to warp the heading text with border. But when I apply border to text the border covers all the area in the width both left and right.I just want to add border around text only and the text needs to be in center.enter image description hereenter image description here


Solution

  • Using a span

    HTML

    <span>Women safty</span>
    

    CSS

    body {
        text-align: center;
    }
    span {
        border: solid;
    }
    

    Result

    enter image description here

    Using a div, h1 and p

    HTML

    <h1>Women safty</h1><br /><br />
    <div>Women safty</div><br /><br />
    <p>Women safty</p><br /><br />
    

    CSS

    body {
        text-align: center;
    }
    h1 {
        border: solid;
        display: inline;
    }
    div {
        border: solid;
        display: inline;
    }
    p {
        border: solid;
        display: inline;
    }
    

    Result

    enter image description here