简体   繁体   English

是否可能有一个带空白且没有包装且父级宽度为100%的Div?

[英]Is It Possible To Have A Div With White Space No Wrap And 100% Width of Parent?

I have a div within a parent that does horizontal scrolling. 我在做水平滚动的父母中有一个div。 I have css and jquery that makes it possible to do such, but I had to use white space no wrap to get the content to overflow horizontally. 我有css和jquery使得可以做到这一点,但是我不得不使用空格不换行来使内容水平溢出。 That all works fine if I define a set width for said div say 55rem for instance. 如果我为上述div定义一个设置宽度,例如55rem,那么一切都很好。 But my website is responsive, I can't adjust the width to every dimension... so I would like to use 100% width, but that overflows no matter what I tried. 但是我的网站反应灵敏,我无法将宽度调整为每个尺寸...因此我想使用100%的宽度,但是无论尝试什么,都会溢出。

I've looked around to see if I could find anything specifically talking about this, and I couldn't even find anything telling me it isn't possible for some reason. 我环顾四周,看看是否能找到任何专门谈论这个的东西,甚至找不到任何告诉我由于某种原因不可能实现的东西。 Maybe I didn't use the right keywords, I'm not sure. 我不确定,也许我没有使用正确的关键字。

For argument's sake, here is the grandparent. 为了争辩,这里是祖父母。

.dashboard_container {
display: table;
height: 100%;
width: 55rem;
margin: auto;
padding-top: 2rem;
}

Here is my parent. 这是我的父母。

.dashboard_post_container {
background: white;
position: relative;
display: inline-table;
-webkit-border-radius: .4rem;
-moz-border-radius: .4rem;
border-radius: .4rem;
margin-bottom: 2rem;
width: 100%;
overflow: hidden;
}

And the child. 还有孩子

.dashboard_suggestions {
width: 100%;
overflow-x: auto;
overflow-y: hidden;
-ms-overflow-style: -ms-autohiding-scrollbar;
-webkit-overflow-scrolling: touch;
white-space: nowrap;
}

Someone commented requesting an example so here is a fiddle: https://jsfiddle.net/08vwyg4b/ 有人评论要求提供示例,因此这里是一个小提琴: https : //jsfiddle.net/08vwyg4b/

You just need to change the child's width to 100% to see what I mean. 您只需要将孩子的宽度更改为100%,即可了解我的意思。

I want the child to be 100% width of the parent and grandparent... essentially. 我希望孩子的宽度是父母和祖父母的100%。 But I must use white space no-wrap to accomplish the main goal of what I'm doing. 但是我必须使用空白无包装来实现我正在做的主要目标。

It's familiar ( this link ) 很熟悉( 此链接

Just change display (to block) and width attribute 只需更改显示 (以阻止)和width属性

.dashboard_container {
    display: block;
    width: 50%; /*Resize for test responsive*/
    /*Your css*/
    }
.dashboard_post_container {
    display: block;
    width: auto;
    /*Your css*/
    }
.dashboard_suggestions {
    width: auto;
    /*Your css*/

    }

DEMO DEMO

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

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