I don't know that my question is much different than the question in the possible duplicate. However, the answer in the possible duplicate does not work (even the jsFiddle provided as the answer does not seem to even rotate the text). The answer on this thread actually solved my problem.
I'm trying to get a div to resize when the text inside is rotated 90 degrees. Right now, the div stays the same width even though the text becomes "thinner" by rotating it.
I've got something like this:
html, body {
height: 100%;
margin:0px;
}
.pane {
width: auto;
float:left;
height: 100%;
border: 1px solid black;
}
.vertical {
display: block;
transform-origin: top right 0;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
<div class="pane"><span class="vertical clearfix">This is text</span></div>
<div class="pane"><span>This is another Pane</span></div>
You can see a sample plunk here.
I'm trying to avoid using hardcoded heights or widths if possible.
when you use transform or position:relative; the initial space used by the element remains the same, it is only drawn different at screen.
Here if you want your rotated box to only use the width of one line height, you need to set this width and let content overflow.
translate can be used to replace content in sight
white-space:nowrap to keep text on a single line
and eventually, because of the rotated value used and the width reduced, you may use direction to push overflow in the opposite direction .
html,
body {
height: 100%;
margin: 0px;
}
.pane {
width: auto;
float: left;
height: 100%;
border: 1px solid black;
}
.vertical {
display: inline-block;
text-align: left;
float: right;
padding-right: 1em;
width: 0.25em;
white-space: nowrap;
direction: rtl;
transform-origin: top left;
transform: rotate(-90deg) translate(-100%);
}
<div class="pane">
<span class="vertical">This is text</span>
</div>
<div class="pane">
<span>This is another Pane</span>
</div>
Else you may use min-width , and a negative margin that virtually reduce elements width to none;
I would go for this one more simple and solid
html,
body {
height: 100%;
margin: 0px;
}
.pane {
width: auto;
min-width:1.2em;
float: left;
height: 100%;
border: 1px solid black;
}
.vertical {
display:inline-block;
padding-right:0.25em;
margin-right:-999px;
transform-origin: top left;
transform: rotate(-90deg) translate(-100%);
}
<div class="pane">
<span class="vertical">This is text</span>
</div>
<div class="pane">
<span>This is another Pane</span>
</div>
<div class="pane">
<span class="vertical">This is some more text</span>
</div>
Related
I'm using some CSS I found in the wild to make flip cards. I've made a few adjustments in an attempt to make them fluidly responsive. My attempt is here:
https://jsfiddle.net/u18rhf6q/
css:
.flip-card-wrapper {
width: 50%;
height: auto;
}
.flip-card {
background-color: transparent;
width: 100%;
height: 100%;
perspective: 1000px;
}
.flip-card img {
width: 100%;
height: auto;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-card-wrapper:hover .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-card-front {
color: black;
}
.flip-card-back {
background-color: #c1272d;
color: white;
transform: rotateY(180deg);
}
html
<div class="flip-card-wrapper" >
<div class="flip-card" >
<div class="flip-card-inner">
<div class="flip-card-front">
<img src="https://dummyimage.com/600x600/000/fff" alt="Avatar" >
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
</div>
What I hope to happen is if I adjust the width of flip-card-wrapper, the contents would expand relative to that width and the flip would continue. However, it only works if I also supply a height to flip-card-wrapper. Since the front and back are both absolute, I can't a height to bubble up. Any ideas?
One possibility for keeping your card height responsive might be to set a padding-bottom or padding-top on your flip-card-inner class. Since those heights are based on the parent's width when you use a percentage, padding-bottom: 100%; should create a perfect square. If you want to play around with the sizing, there's a good overview of aspect ratio boxes at https://css-tricks.com/aspect-ratio-boxes/.
I think this is a math question more than anything else, who knew I'd need to know geometry for CSS.
I have an upright background image inside a rotated container. The image has to cover the container perfectly, and the container itself needs be stuck to the wall so that the user doesn't see the rotation on the side. I want to have dynamic control over the sizing of this element, so I would like everything to be done with percentages.
The blue line is the "wall".
Since the image is upright it has to be quite a bit bigger than its container. I found the formula for this here. That's what it looks like:
So the dimensions are in percentages, what I haven't figured out how to calculate is the various positionings. Without the pixel values I added it looks like this:
So how do I calculate these distances?
Here is my CodePen, it's in SCSS, all the math is done in the code.
body {
padding: 2em 5em;
}
.wrapper {
border-left: 3px solid blue;
}
.wrapper .container {
opacity: 0.7;
width: 300px;
background-color: red;
border-radius: 0 40px 40px 0;
overflow: hidden;
transform: rotate(10deg);
margin-left: -42px;
}
.wrapper .container .sizing-wrapper {
width: 100%;
padding-top: 150%;
position: relative;
}
.wrapper .container .img {
position: absolute;
top: 0;
left: 0;
background: url("http://placekitten.com/300/450") no-repeat right top;
background-size: cover;
height: 110.0573842629%;
width: 124.5280657351%;
transform: rotate(-10deg) ranslateY(-31px) translateX(-32px);
}
<div class="wrapper">
<div class="container">
<div class="sizing-wrapper">
<div class="img"></div>
</div>
</div>
</div>
I shared my question on Facebook and Amit Sheen came up with a solution I initially dismissed of using transform-origin. Now that I've seen it work I'm not sure why I thought it wouldn't.
The fixed CodePen
To make sure the container is cut by the wall at the right place we need to rotate it from the top left corner by using transform-origin: 0 0.
And we need to center the image inside the container:
.img {
top: 50%;
left: 50%;
transform: rotate(-$deg) translateY(-50%) translateX(-50%);
transform-origin: 0 0;
}
I'm still curious what the mathematical solution to my question is, because I'm sure there is one, but for actual use this is probably better...
body {
padding: 2em 5em;
}
.wrapper {
border-left: 3px solid blue;
}
.wrapper .container {
opacity: 0.7;
width: 300px;
background-color: red;
border-radius: 0 40px 40px 0;
overflow: hidden;
transform: rotate(10deg);
transform-origin: 0 0;
}
.wrapper .sizing-wrapper {
width: 100%;
padding-top: 150%;
position: relative;
}
.wrapper .img {
position: absolute;
top: 50%;
left: 50%;
background: url("http://placekitten.com/300/450") no-repeat right top;
background-size: cover;
height: 110.0573842629%;
width: 124.5280657351%;
transform: rotate(-10deg) translateY(-50%) translateX(-50%);
transform-origin: 0 0;
}
<div class="wrapper">
<div class="container">
<div class="sizing-wrapper">
<div class="img"></div>
</div>
</div>
</div>
I'm not sure what the proper terminology is for this effect. I want to say its a blend mode or clipping path thing. What I want to do is when the text get scrolled over (or under) another element to have the text change its color. See the example image below..
So the text is light gray by default then when it scrolls underneath (or over, not sure which way it should be stacked) that gray bar the text goes black.
I know I've seen this done before but just can't remember what the property used was called.
I think what you are looking for is mix-blend-mode but Browser Support still pretty bad Fiddle.
body {
height: 1000px;
}
.text {
text-transform: uppercase;
position: absolute;
top: 80%;
font-size: 50px;
font-weight: bold;
text-align: center;
width: 100%;
color: gray;
z-index: 2;
left: 0;
mix-blend-mode: difference;
}
.box {
width: 60%;
position: fixed;
transform: translate(-50%, 0);
z-index: 1;
left: 50%;
top: 0;
height: 100px;
background: #AAAAAA;
}
<div class="box"></div>
<div class="text">Lorem ipsum</div>
Do you mean something like this?:
<div style="position:absolute; top:0; left:0; bottom:0; right:0; overflow:auto;">
<div style="height:1000px; background-color:#ccc">
<br/><br/>EXAMPLE<br/>EXAMPLE<br/>EXAMPLE
</div>
</div>
<div style="position:absolute; top:0; left:0; height:50px; right:16px; background-color:white; opacity:0.5">
</div>
Example: https://jsbin.com/bexafinuti/edit?html,output
That feature can be made with css opacity. Content become grayed when scrolled under absolute positioned div with white background and half opacity
This question is based on this answer: https://stackoverflow.com/a/23876839/994141
I read many threads on this subject, and it seemed to me the best answer because I would like to avoid setting a width.
But the content at the center isn't well centered but based on the content on the left and on the right.
Proof: https://jsfiddle.net/p7kfuont/ ('b' is not centered on the first line)
Is there a way to improve this code (inline-block and float) without setting widths?
Is this what you're trying to achieve?
.container {
display: table;
table-layout: fixed;
border-collapse: collapse;
width: 100%;
text-align: center;
}
.container > div {
display: table-cell;
border: 1px solid red;
}
<div class="container">
<div class="left">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
<div class="center">b</div>
<div class="right">c</div>
</div>
<div class="container">
<div class="left">a</div>
<div class="center">b</div>
<div class="right">c</div>
</div>
If you want the b to be strictly in the middle you can add this:
.container {
position: relative;
}
.container .center {
position: absolute;
left: 50%;
transform: translateX(-50%); /*add this if you want the element centered*/
-ms-transform: translateX(-50%); /* IE 9 */
-webkit-transform: translateX(-50%); /* Chrome, Safari, Opera */
}
the transform: translateX(-50%) will set the center of your element in the center, while without it you will have the left edge of your element in the center.
jsFiddle
I've not been able to find anything on this topic, oddly; I figured it'd be a pretty common issue!
What I've got is a parent div with a border-radius to make the div circular. Nested in that div, I've got several child divs that I would like:
Positioned directly on the visible circular borders (as opposed to the invisible square "border" that surrounds the div -- this jsFiddle hopefully will clarify what I'm trying to say here).
In addition, I'd like to be able to precisely position the child divs along different points of this border (so, something like "position childDiv1 at the 90deg position [or the 105deg position, 120deg, 135deg, etc.] of the circular parent div" instead of having to use top and left or assign absolute pixel values or something).
Still an amateur trying to figure out CSS positioning, so I'm not even sure if any of this is possible, haha. Looking forward to any input you guys can provide!
You can use css3 transform and transform-origin to achieve this
<div id="parent">
<div class="child" id="child1"></div>
<div class="child" id="child2"></div>
<div class="child" id="child3"></div>
<div class="child" id="child4"></div>
</div>
#parent {
position: relative;
width: 300px;
height: 300px;
border: 1px dotted #000;
border-radius: 150px;
}
.child {
position: absolute;
width: 30px;
height: 30px;
background-color: #666;
left: 135px;
}
#child1{
transform: rotate(90deg);
transform-origin:50% 150px;
}
#child2{
transform: rotate(105deg);
transform-origin:50% 150px;
}
#child3{
transform: rotate(120deg);
transform-origin:50% 150px;
}
#child4{
transform: rotate(135deg);
transform-origin:50% 150px;
}
http://jsfiddle.net/zSdsg/20/
http://jsfiddle.net/zSdsg/15/
(updated to show that top:0 does not protrude the circle.)
Or http://jsfiddle.net/zSdsg/17/, which just looks a lot cooler :}
EDIT: I think I misunderstood your question. I will update or delete my answer depending on...my answer.
http://jsfiddle.net/zSdsg/14/
would something like this be what your looking for?
#parent {
position: relative;
width: 300px;
height: 300px;
border: 1px dotted #000;
border-radius: 150px;
}
#child {
position: absolute;
width: 30px;
height: 30px;
background-color: #666;
}
#child2 {
position: absolute;
top:35px;
left:40px;
width: 30px;
height: 30px;
background-color: red;
border-radius: 150px;
}
<div id="parent">
<div id="child"></div>
<div id="child2"></div>
</div>