I need a line and should have an option to change the angle. The transform property works well but when the angle is increased the line size is decreased.
I need to retain the line size and should not be affected.
https://jsfiddle.net/4j8n45zz/
div {
width: 5px;
height: 220px;
background-color: yellow;
/* Rotate div */
-ms-transform: rotate(0deg);
/* IE 9 */
-webkit-transform: rotate(0deg);
/* Chrome, Safari, Opera */
transform: rotate(0deg);
}
<div></div>
The default transform-origin of the transformation is set on the middle of your <div>. So if you increase the angle the <div> will be rotate on the mid point and a part of your line is outside the site. To solve this you have to set the transform-origin to a corner ([top, bottom] [right, left]).
See the following example (https://jsfiddle.net/4j8n45zz/1/):
div {
display:block;
width:5px;
height: 220px;
background-color: yellow;
/* Rotate div */
-ms-transform: rotate(30deg); /* IE 9 */
-webkit-transform: rotate(30deg); /* Chrome, Safari, Opera */
transform: rotate(30deg);
transform-origin: bottom left;
}
<div></div>
Related
Note: There are similar questions (and may be outdated) which do not address the Firefox issue.
I'm using CSS3 to scale down an entire web page by 50%.
#media screen and (max-width: 320px) {
body {
-moz-transform: scale(0.5); /* Moz-browsers */
zoom: 0.5; /* Other non-webkit browsers */
}
}
This works fine in Chrome but Firefox scales it down seemingly 2 times horizontally and vertically.
Is there a new cross-browser solution for properly scaling down?
Cross browser CSS should look like this (IE from ver. 9)
The code is tested in FF 45.0.1 and works fine.
body {
-webkit-transform: scale(0.5);
-moz-transform: scale(0.5);
-ms-transform: scale(0.5);
-o-transform: scale(0.5);
transform: scale(0.5);
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-ms-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
}
div {
width: 50vw;
height: 50vh;
background: red;
font-size: 40px;
}
<div>
Hello world - font size 40px
</div>
See a fiddle to demonstrate my issue:
div:hover{
-webkit-transform: rotateX(90deg);
transform: rotateX(90deg);
-webkit-transform-origin: center bottom;
transform-origin: center bottom;
}
div {
-webkit-transition-duration: 1s; /* Safari */
transition-duration: 1s;
}
http://jsfiddle.net/Lbq3K/
I would like to flip a div with the bottom line completely fixed throughout the movement. I've been googling around a lot, but couldn't find a solution. As you can see in the fiddle, when you hover your mouse over the div, the bottom line of the border moves away from the <hr> line at the bottom, and gets rotated back afterwards. I would like to have the rotation with a completely fixed bottom border, like I'd flip a calendar page. I've tried transform-origin to fix the rotation, but it apparently isn't working. Is there a way to do this just CSS?
if you put your transform origin on your DIV properties instead of in your DIV:hover it works.
In code:
use this:
div:hover{
-webkit-transform: rotateX(90deg);
transform: rotateX(90deg);
}
div {
-webkit-transition-duration: 1s; /* Safari */
transition-duration: 1s;
-webkit-transform-origin: center bottom;
transform-origin: center bottom;
}
instead of this:
div:hover{
-webkit-transform: rotateX(90deg);
transform: rotateX(90deg);
-webkit-transform-origin: center bottom;
transform-origin: center bottom;
}
div {
-webkit-transition-duration: 1s; /* Safari */
transition-duration: 1s;
}
Have you ever heard about perspective-origin?
I'm not sure about it, but I think
div {
...
perspective-origin:100% 100%;
}
should work fine for you. My testing was successful.
perspective-origin defines the point from which the viewer is looking at the element.
Hi i want to rotate the image by 90 deg and align the image inside the div borders. ie the outer div should expand automatically depending upon the height of the image. I have attached the JSFIDDLE with this.
<div style="float:left;border:1px solid #000;">
<span style="float:left;transform:rotate(90deg); transform:50% 50% 0;">
<img src="http://dimox.net/wp-images/css-border-radius.jpg"/>
</span>
</div>
You can use CSS3 to rotate the element 90deg (on modern browsers) - if you want to move the div as well you can apply the rotate to the div itself:
div img {
-moz-transform: rotate(90deg) translateX(150px);
-webkit-transform: rotate(90deg) translateX(150px);
-o-transform: rotate(90deg) translateX(150px);
-ms-transform: rotate(90deg) translateX(150px);
transform: rotate(90deg) translateX(150px);
}
http://jsfiddle.net/L7pNa/3/
Or if you just want it to have a border - you can use a box shadow for that instead and remove the div markup.
please try this code.
<div style="float:left;border:1px solid #000;overflow: auto;">
<span style="float:left; -ms-transform: rotate(90deg); /* IE 9 */ -webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */ transform: rotate(90deg);">
<img src="http://dimox.net/wp-images/css-border-radius.jpg">
</span>
</div>
I am trying to create a page layout with a rectangular div on the left side that's rotated 10 degrees, expands with the size of the browser, and doesn't show its edge on the top, left, and bottom. Meaning, the page should appear to be split in the middle on a slant.
My code so far creates the div properly, but when I expand the page you begin to see the edges.
http://jsfiddle.net/jpQvL/1/
HTML
<div id="wrapper">
<div id="right"></div>
</div>
CSS
html, body {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
position:relative;
height: 100%;
}
#right {
background: #000;
transition: all 0.5s ease-in-out 0s;
width: 50%;
position: fixed;
min-height: 110%;
transform: rotate(10deg);
top: -73px;
}
The problem is that the tranform property needs render prefixes. You have to add these lines:
-webkit-transform: rotate(10deg);
-moz-transform: rotate(10deg);
-o-transform: rotate(10deg);
-ms-transform: rotate(10deg);
transform: rotate(10deg);
take a look at this
or use one of many prefix-free scripts like this one
This should be a very simple problem you would think. I have a box with some title text that I want to rotate -90 degrees. I would like it to be absolutely positioned so that the end of the word is nudged into the top left corner. I can get this to align to the bottom easily enough, but the problem is that with variable length text it seems impossible to have it consistently stay within the container when aligning to the top because things like {top: 0} operate on the title before the transform. For my purposes this only needs work in Firefox. I can use javascript if that is the only solution, but you would think this could be done with just CSS.
You should use transform-origin to adjust the transformation point, along with some creative use of positioning properties.
http://jsfiddle.net/thirtydot/JxEfs/1/
CSS:
#box {
padding: 30px;
position: relative;
border: 1px solid blue;
}
#box > div {
border: 1px solid red;
position: absolute;
top: 0;
right: 100%;
white-space: nowrap;
-webkit-transform: rotate(270deg);
-webkit-transform-origin: right top;
-moz-transform: rotate(270deg);
-moz-transform-origin: right top;
-ms-transform: rotate(270deg);
-ms-transform-origin: right top;
-o-transform: rotate(270deg);
-o-transform-origin: right top;
transform: rotate(270deg);
transform-origin: right top;
}
HTML:
<div id="box">
hello
<div>rotated!</div>
</div>
Can also work without right:100%
Just rotate 270 deg around left top and then translate it back at new 100% width.
transform: rotate(-90deg) translate(-100%, 0);
transform-origin: 0 0;
http://jsfiddle.net/zW7SP/