Div不保持最小宽度内的另一个Div, HTML



我有三个div容器类。一个是外部容器宽度:1200px,内分格,每一行都有内分格希望大小为280像素。我的问题是,当我创建元素时使用DOM,即countryesinnerdiv元素的大小取决于它们内部的内容。

到目前为止我写的是:

 .CountriesOuterDiv1{
    width: 1200px;    
    }

    .CountriesInnerDiv{
    min-width:280px;    
    display:inline;  
    border:1px solid black;
    }

    .RowDiv {
    width:100%; 
    } 
Here is the relevant Javascript:
function AddTable() {
var TableDiv = document.getElementById("CountriesOuterDiv");
var i,j;
var NumCountries = 5;
var NumSectors = 5;

for (i = 0; i < NumCountries; i++) {
var RowDiv = document.createElement("div")
RowDiv.className = "RowDiv";
RowDiv.id = "Row"+i;

for (j = 0; j < NumSectors + 1; j++) {
var CountryData = document.createElement("div");
var SectorString = String(i+1)+"_"+String(j);
CountryData.className =  "CountriesInnerDiv";
CountryData.id = "CountryData"+SectorString; 
if (!((i ==0 && j == 0) ||  (i==0 && j ==1))) {
    CountryData.style.display = "none";
    }


if (j == 0 || (i == 0 && j == 1)) {


var CountryDataSelect = document.createElement("select"); 
var AddButton = document.createElement("button");
AddButton.id = "AddButton" + SectorString;
AddButton.innerHTML = "+";
if (j != 0) {    
AddButton.setAttribute('onclick','AddOrDeleteDiv("add", "' + SectorString + '");');
}
else {
if (i != NumCountries - 1) {    
AddButton.setAttribute('onclick','AddCountry("' + SectorString + '")');    
}
if (i != 0) {
var DeleteCountry = document.createElement("button");
DeleteCountry.id = "DeleteButton" + SectorString; 
DeleteCountry.innerHTML = "-";
DeleteCountry.setAttribute('onclick', 'DeleteCountry("' + SectorString + '")'); 
}
}

CountryData.appendChild(CountryDataSelect);
    if (i != NumCountries - 1) { 
CountryData.appendChild(AddButton);
    }
if (i!=0) {
    CountryData.appendChild(DeleteCountry);  
}
RowDiv.appendChild(CountryData);  
}   

else if (j == NumSectors) {

var CountryDataSelect = document.createElement("select");

var DeleteButton = document.createElement("button");
DeleteButton.id = "DeleteButton" + SectorString;  
DeleteButton.innerHTML = "-";
DeleteButton.setAttribute('onclick','AddOrDeleteDiv("delete", "' + SectorString + '");');
CountryData.appendChild(CountryDataSelect);
CountryData.appendChild(DeleteButton);    

}

else {

var CountryDataSelect = document.createElement("select"); 
var AddButton = document.createElement("button");
var ADString = "add";
AddButton.setAttribute('onclick','AddOrDeleteDiv("add", "' + SectorString + '");');
AddButton.id = "AddButton" + SectorString;
AddButton.innerHTML = "+";    
var DeleteButton = document.createElement("button");
DeleteButton.id  = "DeleteButton" + SectorString;  
DeleteButton.innerHTML = "-";    
DeleteButton.setAttribute('onclick','AddOrDeleteDiv("delete", "' + SectorString + '");');
CountryData.appendChild(CountryDataSelect);
CountryData.appendChild(AddButton);
CountryData.appendChild(DeleteButton);    
}
RowDiv.appendChild(CountryData);
TableDiv.appendChild(RowDiv);
}//End of inner for    


}//End of outer for     

}//end of function

设置div display:inline;.CountriesInnerDiv{ min-width:280px;
display:inline-block;
border:1px solid black; }

基本上,你所经历的是,最有可能的是,当窗口很小时,内部元素的最小尺寸太大,无法容纳父元素…嗯. .我们的内部不能比外部大……除非你使用

overflow: scroll;

这将使父元素可滚动,这样你就可以通过滚动看到子元素了。

还是……

.parent{min-width: 280px}

最新更新