将图片放在表单旁边(带行)

时间:2016-11-11 14:44:54

标签: html css

注意:使用bootstrap

这就是我想要的: Click to view the wanted result

代码:

<!DOCTYPE>
<html>

<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
</head>

<style>
.jumbotron
{
  margin-top: 20px;
}
.input-group, textarea
{
  margin-bottom: 10px;
}
</style>
<body>

  <div class = "container">
      <div class = "jumbotron text-center">
        <h2>Form</h2>
      </div>

        <form>
        <div class = "row">
          <div class = "col-md-4">
            <div class="input-group">
              <span class="input-group-addon" id="basic-addon1">First Name:</span>
              <input type="text" class="form-control" placeholder="First Name" aria-describedby="basic-addon1">
            </div>
          </div>

          <div class = "col-md-4">
            <div class="input-group">
              <span class="input-group-addon" id="basic-addon1">Last Name:</span>
              <input type="text" class="form-control" placeholder="Last Name" aria-describedby="basic-addon1">
            </div>
          </div>
        </div>

        <div class = "row">
          <div class = "col-md-2">
                <div class="input-group">
                   <span class="input-group-addon" id="basic-addon1">Age:</span>
                    <input type="text" class="form-control" placeholder="Age" aria-describedby="basic-addon1">
               </div>
              </div>

               <div class = "col-md-2">
                <div class="input-group">
                   <span class="input-group-addon" id="basic-addon1">Gender:</span>
                    <input type="text" class="form-control" placeholder="Gender" aria-describedby="basic-addon1">
               </div>
              </div>
            </div>

        <div class = "row">
          <div class = "col-md-4">
            <div class="input-group">
              <span class="input-group-addon" id="basic-addon1">Email Address:</span>
              <input type="text" class="form-control" placeholder="Email Address" aria-describedby="basic-addon1">
            </div>
            </div>

            <div class = "col-md-4">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Phone Number:</span>
                <input type="text" class="form-control" placeholder="Phone Number" aria-describedby="basic-addon1">
              </div>
            </div>
         </div>

         <div class = "row">
            <div class = "col-md-8">
              <textarea class="form-control" rows="3" placeholder = "Additional comments"></textarea>
            </div>
          </div>

          <div class = "row">
            <div class = "col-md-2">
              <button type="button" class="btn btn-default btn-lg">Submit</button>
            </div>
          </div>
        </form>
      </div>
  </body>
</html>

Demo fiddle

我正在尝试将图像放在我的表格旁边,如图1所示。

我尝试了各种方式:即。列,流体容器等列 使用这些方法导致文本框变短,形式和图像之间有很大的差距。

似乎行占据了容器的100%宽度,并且无法使用CSS

调整宽度

关于如何做到这一点的任何想法?

另外,我如何将表格中心化?似乎也不能使用与其他元素一起使用的方法

4 个答案:

答案 0 :(得分:0)

您只需要一个嵌套的行结构。外部列是表单结构和图像的包装器。包含表单的内部列本身总计为12.

<强> Fiddle

请注意,我已将所有列转换为XS用于演示,并且这两个短列不适合小屏幕尺寸。

.row > div {
    margin: 5px 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>    

<div class="container">
    <div class="jumbotron text-center">
        <h2>Form</h2>
    </div>

    <div class="row">
        <div class="col-xs-8">
            <form>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">First Name:</span>
                            <input type="text" class="form-control" placeholder="First Name" aria-describedby="basic-addon1">
                        </div>
                    </div>

                    <div class="col-xs-6">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">Last Name:</span>
                            <input type="text" class="form-control" placeholder="Last Name" aria-describedby="basic-addon1">
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-3">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">Age:</span>
                            <input type="text" class="form-control" placeholder="Age" aria-describedby="basic-addon1">
                        </div>
                    </div>

                    <div class="col-xs-3">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">Gender:</span>
                            <input type="text" class="form-control" placeholder="Gender" aria-describedby="basic-addon1">
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-6">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">Email Address:</span>
                            <input type="text" class="form-control" placeholder="Email Address" aria-describedby="basic-addon1">
                        </div>
                    </div>

                    <div class="col-xs-6">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">Phone Number:</span>
                            <input type="text" class="form-control" placeholder="Phone Number" aria-describedby="basic-addon1">
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-12">
                        <textarea class="form-control" rows="3" placeholder="Additional comments"></textarea>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-2">
                        <button type="button" class="btn btn-default btn-lg">Submit</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="col-xs-4">
            <img class="img-responsive" src="http://placehold.it/800x600" />
        </div>
    </div>
</div>

答案 1 :(得分:0)

您应该使用 Bootstrap的网格类,并将<form>部分和图片部分分为两部分。

请看 Codepen

希望这有帮助!

答案 2 :(得分:0)

我在这里告诉你fiddle working

.jumbotron {
  margin-top: 20px;
}

.input-group,
textarea {
  margin-bottom: 10px;
}

img{width:100%}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>

  <div class="container">
    <div class="jumbotron text-center">
      <h2>Form</h2>
    </div>

    <form>
      <div class="row">


        <div class="col-md-9">



          <div class="row">
            <div class="col-md-6">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">First Name:</span>
                <input type="text" class="form-control" placeholder="First Name" aria-describedby="basic-addon1">
              </div>
            </div>

            <div class="col-md-6">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Last Name:</span>
                <input type="text" class="form-control" placeholder="Last Name" aria-describedby="basic-addon1">
              </div>
            </div>
          </div>

          <div class="row">
            <div class="col-md-3">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Age:</span>
                <input type="text" class="form-control" placeholder="Age" aria-describedby="basic-addon1">
              </div>
            </div>

            <div class="col-md-3">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Gender:</span>
                <input type="text" class="form-control" placeholder="Gender" aria-describedby="basic-addon1">
              </div>
            </div>
          </div>

          <div class="row">
            <div class="col-md-6">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Email Address:</span>
                <input type="text" class="form-control" placeholder="Email Address" aria-describedby="basic-addon1">
              </div>
            </div>

            <div class="col-md-6">
              <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">Phone Number:</span>
                <input type="text" class="form-control" placeholder="Phone Number" aria-describedby="basic-addon1">
              </div>
            </div>
          </div>

          <div class="row">
            <div class="col-md-12">
              <textarea class="form-control" rows="3" placeholder="Additional comments"></textarea>
            </div>
          </div>

          <div class="row">
            <div class="col-md-4">
              <button type="button" class="btn btn-default btn-lg">Submit</button>
            </div>
          </div>
        </div>
        <div class="col-md-3">
        <img src="http://txtbits.com/wp-content/uploads/2015/07/bootstrap.png">
        </div>
      </div>
    </form>
  </div>

这里的事情是你应该明白Bootstrap使用12列的网格系统。当您声明一行时,您必须记住它有12个空白来填充您的列。

要实现与您类似的布局,您不应该尝试使用像图像那样需要多行高度的元素。尽管如此,最好创建两列,一列用于输入,另一列用于图像。然后在文件栏中,根据需要添加尽可能多的行,然后填写必要的列,始终记住必须填充12个空白。

答案 3 :(得分:-1)

您只需要占用一行和两列(或者您可以使用col-6手动添加除法),并且bootstrap将调整其宽度,而enter image description here则使用div,您可以添加一种形式,图像的每一面它将完美弹出。