0

I'm working on a CSS/HTML project and I have a problem with the borders of the text fields. In the browser, the borders are shorter than the text fields.

I tried changing the size of the border to fit the text field and it worked but I tried opening the browser (IE) on a bigger screen and I faced the same problem again.

Here is my code:

<tr>
  <td>First Name</td>
  <td>
    <div style="border:4px #26a570 solid;
               background-color:white; 
      width:37.5%; 
      height:15%">
      <input type="text" name="txtFirst" id="txtFirst" />
    </div>
  </td>
</tr>

I want the border to scale to the size of the text box in all the browser and screens.

maazadeeb
  • 5,922
  • 2
  • 27
  • 40
W.M
  • 11
  • 5

4 Answers4

1

First like @Nimsrules mentioned put your border around the input. Second use a viewport. this will make it scaleable. Your viewport has to be in the head. And instead of using % you can use vw for the width en vh for the height.

Example

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<tr>
    <td>First Name
</td>
    <td>
<div > 
    <input type="text" name="txtFirst" id="txtFirst" style="border:4px #26a570
 solid;background-color:white; width:37.5vw; height:15vh"/>
</div>
</td>
  </tr>

Fiddle

Here you can read more about viewports.

Also I wouldn't recommend inline css. It is better to use a css file. Read this for more information why it is not recommended.

xmaster
  • 1,042
  • 7
  • 20
0

You need to set the style on the input element,

It does not work because you had width:37.5%;set to the parent also.

  <table>
  
  <tr>
    <td>First Name
</td>
    <td>
<div> 
    <input style="width: 200px; border:4px #26a570
 solid;background-color:white; height:15%" type="text" name="txtFirst" id="txtFirst" />
</div>
</td>
  </tr>
  </table>
DigitalJedi
  • 1,577
  • 1
  • 10
  • 29
0

You can set border to the input field and check it on IE.

If it does not work then try to break out the border CSS you have applied, as

border-color: grey;

and

border-style:solid;

instead of single tagging, you can try this.

Hope it works!

Shweta
  • 661
  • 6
  • 11
0

Hi Firstly it is bad to write inline styles because editing can be a pain. You should set a class and write the styles in your CSS file :)

Here's your HTML

<table>
  <tr>
    <td>First Name</td>
    <td>
      <div> 
          <input class="input-wrapper" type="text" name="FirstName" />
      </div>
    </td>
  </tr>
</table>

Here's your CSS

input.input-wrapper{
  border:5px solid green;
}

And here's your INLINE style

<input style="border:5px solid green;" type="text" name="FirstName" />
13garth
  • 655
  • 1
  • 8
  • 22
  • is it possible to make it work using the inline CSS? because the project I'm working on has the HTML and CSS files separately, it is kind of hard to edit both I' haven't tried it before. and I don't want to miss things up. – W.M Jun 12 '19 at 10:27