简体   繁体   English

如何根据其内容使div最小宽度

[英]How to make a div minimum width based on its content

I have a div with table inside. 我有一个div,里面有桌子。 The div is full in width, but whenever I resized the screen, the div will reduce its size then its content will overlapped the div. div的宽度已满,但是每当我调整屏幕大小时,div就会减小其大小,然后其内容就会与div重叠。

Now, I want the minimum width of the div based on the contents(table). 现在,我希望基于内容(表)的div的最小宽度。 My main div is class="search". 我的主要div是class =“ search”。 Here is the link for my codes: 这是我的代码的链接:

 .search { border: 2px solid #FDBF3B; background-color: #FFEBC1; padding: 10px; margin: 5px 0; } .search table { border: none; } .search .header { margin-bottom: 5px; border-bottom: 1px solid #FDBF3B; padding-bottom: 2px; color: #000F1F; font-weight: bold; overflow: hidden; } .search .buttons { margin-top: 5px; border-top: 1px solid #FDBF3B; padding-top: 8px; white-space: nowrap; } .inner { padding: 7px; min-height: 480px; z-index: 1; overflow: auto; } 
 <DIV class=inner> <DIV class=search sizset="false" sizcache017720493147691946="40 33 1"> <DIV class=header>Search Options </DIV> <TABLE sizset="false" sizcache017720493147691946="40 33 1"> <TBODY sizset="false" sizcache017720493147691946="40 33 1"> <TR> <TD></TD> <TD class=LABEL> <SPAN id=LBL_NAME>Name:</SPAN> </TD> <TD> <INPUT name=NAME style="BACKGROUND-COLOR: #ffffff" type=text size=15 maxLength=10 data-dpmaxz-eid="4"> </TD> </TR> <TR> <TD></TD> <TD class=LABEL> <SPAN id=LBL_ADDRESS>Address:</SPAN> </TD> <TD> <INPUT name=ADDRESS style="BACKGROUND-COLOR: #ffffff" type=text size=40 maxLength=50 data-dpmaxz-eid="5"> </TD> </TR> </TBODY> </TABLE> <DIV class=buttons> <INPUT name=SEARCH class=BUTTON type=button value=Search> <INPUT name=SEARCH class=BUTTON type=button value=Clear> <INPUT name=CREATE class=BUTTON type=button value=Create> </DIV> </DIV> </DIV> 

apply min-width to parent div and manage overflow in body. 将最小宽度应用于父div并管理正文中的溢出。 Whenever you reduce widnow width lesser then search div's width, there will be a scroll in body. 每当您减小widnow的宽度,然后再搜索div的宽度时,主体中就会出现滚动。

    .body{
       overflow: scroll;
    }
    .search {
       min-width:380px;
    }

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

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