0

I Need to have a div tag with two rows of text boxes.

The first row has 3 input text boxes with width and height calculated based on percentage.

Likewise in second row i need 2 input text boxes. As i have two input boxes, the area should be broken into 2 blocks of 50% each.

I am new to CSS and HTML.

I have tried a bit of code. but, didn't work!

#div1
{
    position: absolute;
}
#div1 text
{
    display:inline;
    float:left;
    margin:33%
}
#div2
{
    position: relative;
}
#div2 text
{
    display:inline;
    float:left;
    margin:50%
}
</style>
</head>
<body>
    <div id="div1">
        <input type="text" name="txtbox1" class="clstxtbox1"/>
        <input type="text" name="txtbox2" class="clstxtbox1" />
        <input type="text" name="txtbox2" class="clstxtbox1" />
    </div>
    <div id="div2">
        <input type="text" name="txtbox1" class="clstxtbox2" />
        <input type="text" name="txtbox2" class="clstxtbox2" />
    </div>
</body>

Can anyone help me

1
  • there are 3 answers and you did not accept one.do you accept one answer or do you add an image in your mind ? Commented Dec 22, 2016 at 11:07

3 Answers 3

2

You can use css3 flexbox:

HTML:

<div class="input-holder">
  <input type="text" name="txtbox1" class="clstxtbox1"/>
  ...
  ...
  <input type="text" name="txtbox2" class="clstxtbox1" />
</div>

CSS:

.input-holder {
  display: flex;
}

.input-holder input {
  flex-grow: 1;
}

.input-holder {
  margin-bottom: 10px;
  display: flex;
}

.input-holder input {
  flex-grow: 1;
}
<div class="input-holder">
  <input type="text" name="txtbox1" class="clstxtbox1"/>
  <input type="text" name="txtbox2" class="clstxtbox1" />
  <input type="text" name="txtbox2" class="clstxtbox1" />
</div>
<div class="input-holder">
  <input type="text" name="txtbox1" class="clstxtbox2" />
  <input type="text" name="txtbox2" class="clstxtbox2" />
</div>

Here is another variant:

HTML:

<div class="input-holder">
  <div>
    <input type="text" name="txtbox1" class="clstxtbox1"/>
  </div>
  ...
  ...
  <div>
    <input type="text" name="txtbox2" class="clstxtbox1" />
  </div>
</div>

CSS:

.input-holder {
  display: flex;
}

.input-holder div {
  flex-grow: 1;
}

.input-holder div input {
  display: block;
  width: 100%;
}

.input-holder {
  margin-bottom: 10px;
  display: flex;
}

.input-holder div {
  padding: 5px;
  flex-grow: 1;
}

.input-holder div input {
  display: block;
  width: 100%;
}
<div class="input-holder">
  <div>
    <input type="text" name="txtbox1" class="clstxtbox1"/>
  </div>
  <div>
    <input type="text" name="txtbox2" class="clstxtbox1" />
  </div>
  <div>
    <input type="text" name="txtbox2" class="clstxtbox1" />
  </div>
</div>
<div class="input-holder">
  <div>
    <input type="text" name="txtbox1" class="clstxtbox2" />
  </div>
  <div>
    <input type="text" name="txtbox2" class="clstxtbox2" />
  </div>
</div>

Sign up to request clarification or add additional context in comments.

19 Comments

can you tell me , how to add this hidden snippet
In first line of snippet <!-- begin snippet: js hide: true console: true babel: false --> Change hide: true as false.
@JishnuVS Have you got it?
@MuhammadUsman you have got it man but iwant the 2 row textbox to occupy the width of first .
|
0

I guess you can use table tags inside your div tags.

Your answer can look somewhat like below,

<body>
  <div id="div1">
    <table>
      <tr>
        <td>
          <input type="text" name="txtbox1" class="clstxtbox1" />
        </td>
        <td>
          <input type="text" name="txtbox2" class="clstxtbox1" />
        </td>
        <td>
          <input type="text" name="txtbox2" class="clstxtbox1" />
        </td>
      </tr>
    </table>
  </div>
  <div id="div2">
    <table>
      <tr>
        <td>
          <input type="text" name="txtbox1" class="clstxtbox2" />
        </td>
        <td>
          <input type="text" name="txtbox2" class="clstxtbox2" />
        </td>
        <tr>
    </table>
  </div>
</body>

Later you can adjust the length and width of the td tags according to your wish. Hope this helps.

1 Comment

i dont want to display in table
0

.second_row{
  margin-top:20px;
}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 
 <div class="container">
 <div class="row">
<div class="col-md-4 col-sm-4 col-xs-4">
<input class="form-control" type="text" name="txtbox1" class="clstxtbox1"/>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<input class="form-control" type="text" name="txtbox2" class="clstxtbox2"/>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<input class="form-control" type="text" name="txtbox3" class="clstxtbox3"/>
</div>
 </div>
 
 
 <div class="row second_row">
<div class="col-md-6 col-sm-6 col-xs-6">
<input class="form-control" type="text" name="txtbox1" class="clstxtbox1"/>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<input class="form-control" type="text" name="txtbox2" class="clstxtbox2"/>
</div>

</div>
 

Hope this helps.

3 Comments

Hi can i know how to do in css
you can do using flexbox as @MuhammadUsman has given. if you don't want to use much CSS the you can use bootstrap CSS Library.
Ok I am not exposed to bootstrap now my requirement was to do with css if you asked an requirement for muhammed if you can resolve it well and good

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.