【问题标题】:How to align two input fields of two different forms inline, when div is shown?显示 div 时,如何内联对齐两种不同形式的两个输入字段?
【发布时间】:2014-10-20 17:34:39
【问题描述】:

我在jsp中有两种形式。

我希望两个表单中的输入字段居中对齐并且单行。

我还隐藏了一个 div,它在单击输入字段 studentName 时显示。如果单击输入字段 regNo,则需要隐藏 div。默认情况下,div 需要隐藏

现在,当我在输入字段名称中输入内容时,两个输入字段的对齐方式发生了很大变化

jsp代码

<div id="mycontainer">  
    <form method="get" action="number" id="number">
    <!--    <div id="regNoErrorMsgNumber">Only numbers are allowed</div> -->
            <div style="text-align: center;" >
                    <!-- //TODO: Only number, no spaces, no special symbol and 12 digit check-->                

                             <input  width="20" type="text" data-validation="numbers" id="regNo" name="regNo" size="30" maxLength="50" placeholder="Enter Register Number"> <b>OR</b>       

            </div>

    </form>           

    <form method="post" action="name" id="name">                 
                <input  type="text" id="studentName" name="studentName" size="30" maxLength="50" placeholder="Enter Student Name" > 


            <c:set var="salary" scope="session" value="${param.studentName}"/>

        <div id="dropDown" style="display:none">
            <div id="studentNameError">
                <c:if test="${searchBy.hasError}">
                    <c:out
                        value="There are more than 100 results by this name. We suggest you to filter by College Name and/or Department Name" />
                </c:if>
                <br />
            </div>

            <div>
                <b>Filter students by College :</b> <select id="byCollege" name="byCollege">
                    <c:forEach items="${uniqueCollList}" var="uniqueCollList">
                        <option value="${uniqueCollList}">${uniqueCollList}</option>
                    </c:forEach>
                </select>
            </div>
            <br />

            <div>
                <b>Filter students by Department :</b> <select id="byDept" name="byDept">
                    <c:forEach items="${uniqueDeptList}" var="uniqueDeptList">
                        <option value="${uniqueDeptList}">${uniqueDeptList}</option>
                    </c:forEach>
                </select>
            </div>
            <br />
        </div>          
    </form>                 
</div>

css代码

#mycontainer, h1, h3 {
            text-align:center;
        }
        form{
            display:inline-block;
        }       

JS代码

$('#dropDown').hide();
    $(document).ready(function(){
        $('#inputFields').click(function(event){
            if (document.getElementById('regNo').value !=""){           

                $("#number").submit();

            }else if(document.getElementById('studentName').value !=""){
                $("#name").submit();
            }
        });
    });    
    $(document).ready(function(){
          $('#regNo').click(function(event){              
             $('#studentName').val(''); 
             $('#dropDown').hide();
          });
          $('#studentName').click(function(event){            
             $('#regNo').val(''); 
             $('#dropDown').show();
          });

    });

这里是代码http://jsfiddle.net/7zwvcs4n/

【问题讨论】:

    标签: html css


    【解决方案1】:

    添加垂直对齐:顶部;到表单的css

        #mycontainer, h1, h3 {
            text-align:center;
        }
        form{
            vertical-align:top;
            display:inline-block;
            max-width: 49%;
            text-align:left;
        }
    

    我更新了你的小提琴http://jsfiddle.net/7zwvcs4n/2/

    【讨论】:

    • 不。还是行不通。这就是它的显示方式postimg.org/image/bp64exwvp
    • 您的屏幕太小 :) 您需要另一个最大宽度:49%; (或者,如果您希望右列更宽,请使用两种不同的宽度)我编辑了我的答案。
    • 哇。这是工作。 postimg.org/image/nbm53622r 但是我怎样才能让学生过滤器在输入注册号输入字段下方开始。
    • 我不确定您的代码现在看起来如何,但在这个小提琴中,它可以工作。我不得不添加另一个 text-align:left jsfiddle.net/7zwvcs4n/2
    • 是否可以将两个过滤器下拉从输入注册号下方开始,输入字段。
    猜你喜欢
    • 2023-03-06
    • 2014-11-29
    • 2018-02-16
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    • 2019-04-23
    • 2019-11-07
    相关资源
    最近更新 更多