简体   繁体   English

div从容器溢出

[英]Div overflowing from container

I'm working on an application and trying to design the User Interface. 我正在开发一个应用程序,并试图设计用户界面。 Having issues getting things going. 在使事情进展方面遇到问题。 The divs contains in my main view are extending past their container. 在我的主视图中,包含的div超出了其容器的范围。

This is most of the code: http://jsfiddle.net/9t3sn/ 这是大多数代码: http : //jsfiddle.net/9t3sn/

<div id="mainView">
    <div id="top">
        <div><label>Entity <select id="entityDropDown" ></select></label></div>
        <div id="removeEntity" class=""><a onclick="">&#10006;</a></div>
        <div><label>Entity Available <select id="entityAvailable" multiple></select></label></div>
        <div><label>Entity Assigned <select id="entityAssigned" multiple></select></label></div>
    </div>

    <div id="middle">
        <div id="entityInfo">
            <label>placeholder: <input type="text" id="domainID" disabled="true"/></label></br>
            <label>placeholder: <input type="text" id="entityName" /></label></br>
            <label>placeholder: <input type="text" id="userEmail" /></label></br>
            <label>Description: <textarea id="groupDesc" rows='3' cols="25"></textarea></label></br>
            <label>Group Templates: <select id="groupTemplates"></label></select></br>
        </div>
    </div>

    <div id="bottom">
        <div id="updateEntity" class=""><a>Update Entity Info</a></div>
    </div>
</div>

CSS: CSS:

#mdContainer{
    position: relative;
    border: 2px solid red;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    padding: 0px;
    margin: 0;
    box-sizing: border-box;
    -moz-box-sizing:border-box;
}
#mainView{
    position: relative;
    top: 0;
    bottom: 0;
    background: green;
    color: black;
    left: 140px;
    right: 0;
    padding-left: 0px;
}

#mdContainer #top,#mdContainer #middle,#mdContainer #bottom{
    height: auto;
    width: 100%;
    padding: 5px;

}

Remove width from #mdContainer #top, #mdContainer #middle, #mdContainer #bottom class. #mdContainer #top, #mdContainer #middle, #mdContainer #bottom类中删除宽度。 and set margin-left instead of left to the #mainView . 并设置margin-left而不是left到#mainView

 #mainView {
 position: relative;
 top: 0;
 bottom: 0;
 background: green;
 color: black;
 margin-left: 140px;
 right: 0;
 padding-left: 0px;
 }

#mdContainer #top, #mdContainer #middle, #mdContainer #bottom {
height: auto;
padding: 5px;
}

The reason is, div's are 100% width by default until you positioned, if you add width and padding, it will calculate as 100% of the container + 10px width 原因是,在您定位之前,div的默认宽度为100%,如果您添加宽度和填充,它将计算为容器的100%+ 10px宽度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM