Search code examples
cssformsstylesheetlegendfieldset

How to set fieldset border from legend bottom?


I have fieldset and legend. fieldset border is coming in the middle of the legend like below alt text

But I want border like below

alt text

Border line should come below legend.

I am using below css.

.fieldSet
{
    width: 97%; 
    margin-left: 10px;
    border-color: #003366;
}

.legendStyle
{
    border-style:none;
    background-color: #003366;
    font-family: Tahoma, Arial, Helvetica;
    font-weight: bold;
    font-size: 9.5pt;
    Color: White;
    width:30%;
    padding-left:10px;

}

Solution

  • try this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title></title>
        <style type="text/css">
        fieldSet
        {
            width: 97%; 
            margin-left: 10px;
            border:0;
            margin:0;
        }
    
        legend
        {
    
            border-style:none;
            background-color: #003366;
            font-family: Tahoma, Arial, Helvetica;
            font-weight: bold;
            font-size: 9.5pt;
            Color: White;
            width:30%;
            padding-left:10px;
    
        }
    
        fieldset div { border:1px solid #003366; position:relative; top:-6px }
    
        </style>
    </head>
    <body>
    
        <fieldset>
            <legend>Employee Information</legend>
            <div>
                <label for="x">some label</label>
                <input type="text" name="x" />
            </div>
        </fieldset>
    
    </body>
    </html>