作者:小鱼2502907687 | 来源:互联网 | 2023-06-03 18:45
imtryingtomakethis:我正试着这样做:Theblackdivmustbewithsomebackground-color,butwithawi
i'm trying to make this:
我正试着这样做:
The black div must be with some background-color, but with a width of 100%. The red div must be with a maximum width of 900px, but with ability to shrink for a minimum of 300px(not less than that). Ignore blue div, did it by mistake. The greed divs, must be of maximum 150px, but able to shrink for a minimum of 100px(not less than that). And the orange div, must fill all this space(600px if green divs 150px(max), and if green divs 100px(min), then it should shrink for a minimum of 100px;).
黑色div必须带有一些背景色,但宽度为100%。红色div必须最大宽度为900px,但能够缩小至少300px(不小于该值)。忽略蓝色div,错误地做了。贪婪div必须最大150px,但能够缩小至少100px(不小于)。并且橙色div必须填满所有这些空间(600px,如果绿色div为150px(最大),如果绿色div为100px(min),那么它应该缩小至少100px;)。
I have a huuuuge problem makin' this to work. I just can't figure it out how to make this shrinkin' think to work properly :/ All I was tryin' is to play with max-width, min-width and width it self, but every single time something is not working as i wish it to work. The only think is working fine, is the black div. Simply by making it 100% width and height size.
我有一个huuuuge问题makin'这个工作。我只是无法弄清楚如何使这个缩小'认为正常工作:/我所有尝试'是最大宽度,最小宽度和宽度自己玩,但每次都有一些不起作用我希望它能发挥作用。唯一的想法是工作正常,是黑色div。只需将其100%宽度和高度尺寸。
I'm trying to make this with css and html only, and of course with cross-browsing as possible
我只想用css和html来做这个,当然还有尽可能的交叉浏览
2 个解决方案
Not sure if I fully understand what you wanted, but something like this?
不确定我是否完全理解你想要的东西,但这样的东西呢?
jsfiddle
HTML
Word
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud"
Sed ut perspiciatis unde omnis iste natus errorsit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur
CSS
#black {
width: 100%;
height: 50px; /* just for example */
background-color: #000;
text-align: center; /* center red div, because it is inline block */
}
#red {
overflow: hidden;
min-height: 100%;
min-width: 300px;
max-width: 900px;
display: inline-block; /* inline block, so it's width will be based on content inside him */
background-color: red;
/* text-align: left; if you don't want have centered text */
}
.first {
float: left;
}
.second {
float: right;
}
.green {
max-width: 150px;
min-width: 100px;
min-height: 100%;
background-color: green;
padding-bottom: 100%;
margin-bottom: -100%;
}
#orange {
background-color: orange;
min-height: 100%;
overflow: hidden;
max-width: 600px;
min-width: 100px;
padding-bottom: 100%;
margin-bottom: -100%;
}
If one of those green divs is empty, it will probably not work.
如果其中一个绿色div是空的,它可能不起作用。
This in red
这是红色的
overflow: hidden;
and this in green ones and orange
这是绿色和橙色
padding-bottom: 100%;
margin-bottom: -100%;
makes that they'll have always same height.
使他们总是有相同的高度。
This in black
这是黑色的
text-align: center;
makes that red one will be centered because it is inline-block.
使红色的一个将居中,因为它是内联块。
And making middle div (orange) as last one in html with overflow: hidden
in css, makes it to expand the space between those green divs.
并在html中将中间div(橙色)作为最后一个使用溢出:隐藏在css中,使其扩展这些绿色div之间的空间。
EDIT
Edited my code because I read the question wrong
编辑我的代码,因为我读错了