简体   繁体   English

旋转div但可防止窗口边界溢出

[英]Rotate div but prevent overflow at window borders

I want to rotate a div by say 7deg. 我想将div旋转7度。 This div though should fill the entire space left, right and to the bottom. 不过,该div应该填充左侧,右侧和底部的整个空间。 Like this: 像这样:

 _____________________
|                     | <- body
|                  __-| <- rotated div border
|            __----   |
|      __----         |
|__----               | <- rotated div
|                     |
|                     |
|---------------------| <- window bottom
|        scroll       | 
|          |          |
|          v          | <- still rotated div filling the space
|_____________________|

You should be able to scroll down and you should not be able to scroll to the right. 您应该可以向下滚动,而不能向右滚动。

Is there a html/css solution? 有没有html / css解决方案? Or maybe I need jquery or something? 或者,也许我需要jquery之类的东西?

Edit: The rotated div doesn't actually need to fill all the space down to the bottom. 编辑:旋转的div实际上并不需要填满所有空间直到底部。 There could be a second (overlapping) not rotated div doing this. 可能有第二个(重叠)未旋转的div这样做。

Without knowing precisely what this is for it's difficult to divine what you want, but making a couple of assumptions then no it isn't possible. 如果不确切知道这是什么,很难知道您想要什么,但是做出几个假设,那么就不可能了。

Having re-read any amount of rotation would require you to scale up the rotated div to fill the full width. 重新读取任何旋转量后,您都需要按比例放大旋转后的div以填满整个宽度。 The precise amount of scaling required would depend on the height of the div; 所需的精确缩放比例将取决于div的高度; a calculation that isn't possible with CSS. CSS无法进行的计算。

I like your diagram! 我喜欢你的图! I reproduced it in this jsfiddle *, but I'm not sure whether that's exactly what you want. 我在jsfiddle *中复制了它,但是我不确定那是否正是您想要的。 I just made the inner div wider than the containing div, and then set overflow: hidden; 我只是使内部div宽于包含div的div,然后将overflow: hidden;设置为overflow: hidden; . This is a pretty messy solution, it won't work if you have important stuff in the lower part of the div. 这是一个非常凌乱的解决方案,如果您在div的下部有重要内容,它将无法正常工作。 You might be better off using some javascript to jigger the scale, etc... 您可能最好使用一些JavaScript来缩放比例,等等。

You can inspect the css: 您可以检查CSS:

.container {
    background-color: blue;
    height: 500px;
    width: 300px;
    overflow:hidden;
}

.inner {
  background-color: #FF0000;
  height: 100%;
  position: relative;
  top: 100px;
  transform: rotate(7deg);
  transform-origin: 0 0 0;
  width: 150%;
  padding: 10px;
}

I'm just learning about transforms myself, so I hope this is at least a little helpful. 我只是在学习自我转换,所以我希望这至少对您有所帮助。

* and here it is with a scroll bar on the right side only : fiddle . *并且这里在右侧具有滚动条: 小提琴 This is achieved by having one outer div with overflow:hidden and another with overflow:auto and appropriate width/height. 这可以通过使一个外部div具有overflow:hidden和另一个具有overflow:auto和适当的宽度/高度来实现。

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

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