0

I am trying to get input box like below:

enter image description here

I am new to CSS so I just want to achieve how to put text in border of input box OR I have to make a div with border and put text into border of div.

Here is my current go, I know it not good one but in between

    input {
  display:block;
  width:100%;
  margin:10px 0;
  padding:10px;
  
}

I did that but unable to wrap text with border, any suggestion would be appreciable.

Sandeep Tiwari
  • 2,042
  • 3
  • 24
  • 47

2 Answers2

5

Try this

<fieldset>
    <legend>Name</legend>
    <input type="text" name="name" id="name" placeholder="Enter your Name">
</fieldset>


<style>
    fieldset > input{
        border: none;
        outline: none;
        width: 100%;
    }
</style>

Edit:

The fieldset by itself add the border, the legend tag add the name text above the input, and then you will just edit the input element removing the border and the outline properties, to don't ruin the design when focused showing multiple borders, and adjust the width to fit the fieldset and don't look so weird when adding text (see below).

<fieldset>
    <legend>Name</legend>
    <input type="text" name="name" id="name" placeholder="Enter your Name" value="a thousand of values hehe, see the text won't fit the fieldset">
</fieldset>


<style>
    fieldset > input{
        border: none;
        outline: none;
    }
</style>
2

label{
  display:block; 
  position:relative; 
  bottom:-10px; 
  width:fit-content; 
  left:10px; 
  padding:0px 5px; 
  background-color:white;
}
input{
  border:2px solid gray; 
  height: 30px; 
  width:300px;
  padding:5px 10px;
  font-weight:bold;
}
    <form >
        <label for="name">Name</label>
        <input type="text" placeholder="Enter Your Name" name="name" >
    </form>