【问题标题】:Form not staying within a DIV (Works in IE 9 but not Chrome or IE11)表单不在 DIV 中(适用于 IE 9,但不适用于 Chrome 或 IE11)
【发布时间】:2015-05-14 17:38:03
【问题描述】:

我在 CSS 中创建了一个基于网格的布局(使用 this 文章 j4n.co 创建于 6/2014,所以我不认为 CSS 已经过时,但我可能会错了。)

总的来说,它显示得很好,但是当我尝试在 DIV 中放置表单时遇到了问题。下面是几个sn-ps代码:

HTML:(取自 PHP,但 the problem recreates 如下)

<div class="row">
<div class="group">Group Name</div>
<div class="col-1">
    <p class="item">Item Name
        <br>
        <form enctype="multipart/form-data" action="upload.php" method="POST" class="pullup">
            <input type="hidden" name="itemID" value="' . htmlspecialchars($itemID) . '"></input>
            <input type="hidden" name="userIDnum" value="' . htmlspecialchars($userIDnum) . '"></input>
            <input type="hidden" name="groupName" value="' . htmlspecialchars($group_name) . '"></input>
            <input type="hidden" name="itemName" value="' . htmlspecialchars($item_name) . '"></input>
            <input type="file" name="uploadFile"></input>
            <br>Name:
            <input type="text" name="displayName"></input>
            <br>
            <input type="submit" name="submit" value="Submit"></input>
        </form>
        <br>
    </p>
</div>

CSS:

.grid-container {
   width: 100%;
   max-width: 1200px;}

.group {
   background-color: #FFDCDC;
   width: 16.66%;
   padding: 5px 5px 5px 5px;}

/*-- our cleafix hack -- */
.row:before, .row:after {
   content:"";
   display: table;
   clear:both;}

[class*='col-'] {
   float: left;
   min-height: 1px;
   width: 16.66%;
   /*-- our gutter -- */
   padding: 12px;
   background-color: #FFDCDC;}

.col-1 {
   width: 16.66%;}

.outline, .outline * {
   outline: 0px solid #dddddd;}

p.item {
   height: 200px;}

/*-- some extra column content styling --*/
[class*='col-'] > p {
   background-color: #FFC2C2;
   padding: 0;
   margin: 0;
   text-align: center;
   color: white;}

form.pullup {
   outline: 5px solid #000000;
   display: table-cell;}

JSFiddle 显示我的问题。我希望深色轮廓的表格位于深红色框内。

来自“可能已经有你答案的问题”
This OP 没有跟进他/她的问题。我尝试了thisthis 问题的解决方案,但没有成功。

类似问题中,我没有看到任何似乎相关的内容。如果有一个我错过的问题可能对我有帮助,请指出来!

谢谢!

【问题讨论】:

    标签: html css forms google-chrome internet-explorer


    【解决方案1】:

    我认为你的问题是&lt;input type="file" name="uploadFile"&gt;&lt;/input&gt;

    它太大了,无法放入较小的容器中。所以表格的尺寸太大了。

    编辑:

    默认文件输入很难设置样式。使用 uniform 之类的东西来创建一个适合该框的文件输入。

    ps:项目应该是div 而不是p-Tag

    编辑 2:更新 fiddle 并添加:

    input[type="file"] {
      max-width: 110px;
    }
    

    工作正常,如果您不需要上传按钮旁边的文本。否则就穿制服。

    【讨论】:

    • 感谢您的建议。我将 col-1 宽度更改为 100%,但它在 JSFiddle 中仍然不起作用。我还尝试更改输入的宽度。你能让它工作吗?
    • 它不能工作,因为元素太大了。你可以使用overflow: hidden; 之类的东西,但我认为这不是你想要的。
    • 谢谢,Der。接受其他答案后看到您的编辑。感谢关于制服和 CSS 的建议。 +1
    【解决方案2】:

    问题是表单标签不允许在 p 标签内,因为 p 标签不应该包含任何块元素。简单的解决方案是将 .item 标记更改为 div 并更新您的 CSS。

    查看this fork of your fiddle

    <div class="row">
    <div class="group">Group Name</div>
    <div class="col-1">
        <div class="item">Item Name
            <br>
            <form enctype="multipart/form-data" action="upload.php" method="POST" class="pullup">
                <input type="hidden" name="itemID" value="' . htmlspecialchars($itemID) . '"></input>
                <input type="hidden" name="userIDnum" value="' . htmlspecialchars($userIDnum) . '"></input>
                <input type="hidden" name="groupName" value="' . htmlspecialchars($group_name) . '"></input>
                <input type="hidden" name="itemName" value="' . htmlspecialchars($item_name) . '"></input>
                <input type="file" name="uploadFile"></input>
                <br>Name:
                <input type="text" name="displayName"></input>
                <br>
                <input type="submit" name="submit" value="Submit"></input>
            </form>
            <br>
        </div>
    </div>
    </div>
    

    【讨论】:

    • 谢谢,弗拉德。这非常有效。没有意识到 p 标签不能包含块元素,所以也感谢您的解释!
    猜你喜欢
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多