简体   繁体   English

Div不会根据屏幕尺寸进行渲染

[英]Div is not rendering according to screen size

In my app, I want everything to render according to screen size. 在我的应用程序中,我希望所有内容都根据屏幕大小呈现。

But a div is not rendering ; 但是div没有渲染;

Here is code : 这是代码:

<div id="tools" class="open">
.....
</div>

css : css:

#tools{
   position: absolute;
   top: 0;
   right: 0;
   bottom: 0;
   width: 5%;
   overflow: hidden;
   background: #ffffff;
}

It doesn't render according to screen size. 它不会根据屏幕尺寸进行渲染。 Please provide me some feasible solution for this 请为此提供一些可行的解决方案

EDIT : 编辑:

Some tools icon is used in above div. 上面div中使用了一些工具图标。 So whatever screen size is used, size of image icon remains same. 因此,无论使用什么屏幕尺寸,图像图标的尺寸都保持不变。 it doesnt render according to screen size 它不会根据屏幕尺寸进行渲染

If by "rendering" you understand that the div is not showing, that is because you need to specify its height . 如果通过“渲染”了解到div没有显示,那是因为您需要指定其height Furthermore, avoid using the ID for CSS identification. 此外,请避免将ID用于CSS识别。 Use its class instead. 请改用其类。

CSS: CSS:

.open {
    position:absolute; 
    top:0; 
    right:0;
    bottom:0;
    width:5%;
    height:10%;
    overflow:hidden;
    background:#999999;
}

Instead of the height:10% , specify whatever height fits your needs. 代替height:10% ,指定任何适合您需要的高度。

Working fiddle here 在这里工作

Try this: 尝试这个:

#tools {
    position:absolute; 
    top:0; 
    right:0;
    width:5%;
    overflow:hidden; 
    background:red;
}

html, body {
    width: 100%;
    height: 100%;
}

Fiddle 小提琴

You have given "width:5%;". 您给出了“ width:5%;”。 This might be a reason that your div is not showing a proper width according to the screen. 这可能是您的div根据屏幕显示的宽度不正确的原因。 Make it "width:100%". 将其设置为“宽度:100%”。

Also, you have defined {position:absolute; 另外,您还定义了{position:absolute; top:0; 顶:0; right:0; 对:0; bottom:0;}. bottom:0;}。 If top is 0 then why have you given bottom as 0?? 如果top为0,那么为什么要赋予bottom为0? It is not required. 不需要。 You can remove it. 您可以删除它。

I think, the problem is not the size of the div you using. 我认为,问题不在于您使用的div的大小。 But the size of icon , which is not changing according to size of div. 但是icon的大小不会根据div的大小而变化。 either you using very small image or given fix width to them. 您可以使用非常小的图像或给定的固定宽度。 try this with images . 尝试用图像。 amke them with good standard size according to your app. 根据您的应用,以合适的标准尺寸将其销毁。 and write this. 并写下来

.class{max-width:100%}

This with re-size them according to div size 根据div大小重新调整大小

The problem can't come from this div because no fixed dimensions are defined. 由于未定义固定尺寸,因此问题不会出自此div。 So the problem comes from a parent div. 所以问题出在父div上。 You have to check if all its parent div don't have fixed values. 您必须检查其所有父div是否都没有固定值。

It works perfectly fine just need to add some color so you can see it 它工作得很好,只需要添加一些颜色就可以看到它

http://jsfiddle.net/A2JjN/2/ http://jsfiddle.net/A2JjN/2/

background:red;
font-size:50px;

For anyone who is confused about why one might use top:0; bottom:0; 对于那些对为什么可能使用top:0; bottom:0;感到困惑的人top:0; bottom:0; top:0; bottom:0; then read this post CSS 100% height with absolute positioning top 0 bottom 0 然后阅读这篇文章CSS 100%高度,绝对定位顶部0底部0

I got my solution. 我找到了解决方案。 I just give width in pixels instead of % and it worked. 我只是以像素为单位而不是%提供宽度,它可以工作。

#tools{
   position: absolute;
   top: 0;
   right: 0;
   bottom: 0;
   width: 50px;
   overflow: hidden;
   background: #ffffff;
}

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

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