简体   繁体   English

HTML / CSS:在div中设置对象的宽度和高度?

[英]HTML/CSS : Set width & height of object in a div?

I have ran into a problem when trying to load html files into a div tag, using the code below; 我尝试使用以下代码将html文件加载到div标签中时遇到问题;

<div id ="content" ></div>
<script>
function load_home(){
    document.getElementById("content").innerHTML='<object type="text/html" data="home.html"></object>';
}
</script>

The problem is that the content gets loaded as seen below; 问题是内容被加载,如下所示; 在此处输入图片说明

The content doesn't fill the width or height of the screen. 内容未填满屏幕的宽度或高度。

Any tips for making the loaded html file, fill the body width and height? 制作加载的html文件,填充正文的宽度和高度的任何技巧吗?

Try to set its position: absolute; 尝试设置其position: absolute; and top:0;left:0;bottom:0;right:0;width: 100%;height: 100%; top:0;left:0;bottom:0;right:0;width: 100%;height: 100%;

Why is the right side of your div empty? 为什么div的右侧为空? Check whether you have applied width restrictions. 检查是否已应用宽度限制。 However,you can use width:100% so that the div fills the whole box. 但是,您可以使用width:100%,以便div填充整个框。 You might have to put your script inside another div and set the value of that div to 100%. 您可能需要将脚本放入另一个div并将该div的值设置为100%。

Set the width and height parameters if the object tag: 如果对象标记设置宽度和高度参数:

...
document.getElementById("content").innerHTML='<object type="text/html" data="home.html" style="width:100%; height: 100%;"></object>';
...

edit: With respect to the JSFiddle http://jsfiddle.net/zYw3S/12/ adding 编辑:关于JSFiddle http://jsfiddle.net/zYw3S/12/添加

#content{
    background-color: #FFFFFF;
    border-radius: 10px;
    margin-top: 10px;
    height: 70vh;
}

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

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