html - Div 不维护另一个 div 内的最小宽度,HTML

标签 html css

我有三类 div 容器。一种是外容器 宽度:1200px,内部 div 行,每个行都有内部 div 的 所需尺寸为 280 像素。我的问题是当我创建元素时 使用 DOM,CountryInnerDiv 元素的大小会根据其内部内容而变化。

这是我到目前为止所拥有的:

 .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显示:内联;这样做.CountriesInnerDiv{ min-width:280px;<br/> display:inline-block;<br/> border:1px solid black; }

关于html - Div 不维护另一个 div 内的最小宽度,HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38833349/

相关文章:

javascript - 是否可以在 HTML 文档中找到所有评论并将它们包装在一个 div 中?

html - float 图像溢出父 div

jquery - 页脚向上滑动过渡 Jquery 或 CSS3

css - 使用 VUE 应用程序去除主页上的白色细边框

css - 设置标签的 CSS 规则以匹配另一个标签

html - 2 个人造列,中间是液体,html/body 上没有 bg 的粘性页脚?

javascript - 通过 Javascript 单击时 PrimeFaces 单选按钮样式不更新

javascript - Mobile Safari 和 x-offset

java - 如何在 REST Jersey Web 应用程序中创建、管理、关联 session

javascript - 图片悬停上的 CSS 文本不起作用