使用 getElementById 将站点加载到 div 中,不占用 100% 的宽度
Loading site with getElementById into a div not taking 100% of width
我正在使用 bootstrap 构建一个站点,并且正在使用 javascript:
在我的页面中加载另一个站点
<div id ="content"></div>
<script>
function myFunction() {
document.getElementById("content").innerHTML='<object type="text/html" data="1.html" ></object>';
}
<script>
它的工作就像我想要的一样,除了内容没有占用 100% div,我想我可以用 css 修复它,但它什么也没做:
#content{
margin: 0 auto;
width:100%; /*it changes the size of the div but not the content*/
background: red;
height: 100%;
}
这是正在发生的事情的图片,在原始 1.html 中,面板占据了文档的 100%。
<div id ="content"></div>
<script>
function myFunction() {
document.getElementById("content").innerHTML='<object type="text/html" id="obj" data="1.html" ></object>';
}
window.onload=function(){
document.getElementById("obj").style.width = "100%";
}
</script>
您可以将此添加到您的 css
#content object{
width: 100%;
}
我正在使用 bootstrap 构建一个站点,并且正在使用 javascript:
在我的页面中加载另一个站点<div id ="content"></div>
<script>
function myFunction() {
document.getElementById("content").innerHTML='<object type="text/html" data="1.html" ></object>';
}
<script>
它的工作就像我想要的一样,除了内容没有占用 100% div,我想我可以用 css 修复它,但它什么也没做:
#content{
margin: 0 auto;
width:100%; /*it changes the size of the div but not the content*/
background: red;
height: 100%;
}
这是正在发生的事情的图片,在原始 1.html 中,面板占据了文档的 100%。
<div id ="content"></div>
<script>
function myFunction() {
document.getElementById("content").innerHTML='<object type="text/html" id="obj" data="1.html" ></object>';
}
window.onload=function(){
document.getElementById("obj").style.width = "100%";
}
</script>
您可以将此添加到您的 css
#content object{
width: 100%;
}