html - div高度自动增加

标签 html css

我创建了一个 div。 包含另外三个 div。

HTML:

<div id="a">
    <div id="a1">
        <img src="p.png" alt="an image" height="50" width="200">
    </div>
    <div id="a2">
        <form method="post">
            <input type="text" class="textbox"/>
        </form>
    </div>
    <div id="a3"></div>
</div>

CSS:

#a
{
height:50px;
width:100%;
display: table;
position: fixed;
}

#a1
{    
width: 200px;
height: 100%;
display: table-cell;
}
#a2
{
height: 100%;    
background-color: #664499;
display: table-cell;
}
.textbox
{
height: 50px;
float: left;
margin: 0px;
border: 0px none;
}
#a3
{
width: 200px;
height: 100%;
background-color: #669999;
display: table-cell;
}

我的问题是,当我将任何标签放入 imginput 时,父 div 'a' 的高度会自动增加 3。

如果我删除该标签,它就会正常运行。尝试了最小高度选项,但对我不起作用。

我应该怎么做才能使包装器 div 'a' 不改变其高度?

最佳答案

试试这个

<div id="Inner_Right_Layout">
<table>
    <tr>
        <td><div class="usr_img_div">
                    <img src="~/Images/username.png"  />
                </div></td>
        <td><div class="usrnm_txtbx_div">
                    <input type="text" id="txtUserName" class="textprop"  /></td>
    </tr>
    <tr>
        <td><div class="usr_img_div">
                    <img src="~/Images/password.png"  />
                </div></td>
        <td><div class="usrnm_txtbx_div">
                    <input type="password" id="txtPassword" class="textprop" /></td>
    </tr>

         <tr>
        <td><div class="usr_img_div">
                    <img src="~/Images/password.png"  />
                </div></td>
        <td><div class="usrnm_txtbx_div">
                    <input type="password" id="txtPassword" class="textprop" /></td>
    </tr>
</table>

css 是

#Inner_Right_Layout {
background-color: #43BDA4;
height: 100%;
width: 100%;    
border: 0;
padding: 0;
margin: 0; 
}


#control_main_div {
height: 50%;
width: 70%;
margin-left: 0%;
margin-top: 0%;
border:1px solid black;
}

.username_div {
height: 15%;
width: 100%;
margin: 0px;
border:;1px solid blue; 
padding-bottom:5px;
}

.usr_img_div {
height: 10%;
width: 15%;
float: left;
border:;1px solid red;
}

.usrnm_txtbx_div {

width: 80%;
margin-left: 0%;
font-family: Ubuntu;
border:1px solid yellow;
margin-top:0%;

}
.textprop {
height: 80%;
width: 90%;
margin: 0;
padding: 0;
border: 0;
margin-left: 1px;
font-family: 'Ubuntu';
font-size: 16px;
font-weight: 100;
}

如果需要任何更改,请告诉我

关于html - div高度自动增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23560856/

相关文章:

jquery - 自定义滚动条跨浏览器

android - 是否可以在 WebView 中使用可绘制对象(不是图像)?

css - 我可以插入背景大小 : cover into the background shorthand?

html - 使用具有可变高度的 Bootstrap div 创建网格

html - 固定粘性标题

html - 关键帧动画的列表定位

javascript - 当父页面在边缘模式下运行时,iframe 页面的 IE 11 文档模式

javascript - 有没有办法使用 HTML 5/JS 来锁定音量变化?

css - Angularjs:为菜单中的每个页面定义不同的CSS

iphone - CSS Sprite 在 iphone 上搞砸了