Fasio_Vita
Fasio_Vita

Reputation: 11

CSS Transform displaces div child contents

When I animate divs without using transform, everything works as expected. When I add a transform to the containing div, the inner divs are displaced to the right of the containing div.

html,body
{
	padding: 0px;
	margin: 0px;
	width: 1920px;
	height: 1080px;
}
.container
{
	width: 1920px;
	height: 1080px;
	background-color: rgba(0,0,0,0.3);
	overflow: hidden;
	position: relative;
}
.bottom-container
{
	float: left;
	background-color: rgba(0,0,0,0.3);
	width: 1920px;
	height: 135px;
	align-content: center;
	position: relative;
}
.b-holder
{
	background-color: rgba(255,255,0,.4);
	justify-content: center;
	width: 800px;
	margin-left: auto;
	margin-right: auto;
	height: 135px;
	animation-name: b-holder-a;
	animation-duration: 10s;
	position: fixed;
	left: 560px;
	top: 945px;
	padding: 0px;
	text-align: center;
}
@-webkit-keyframes b-holder-a
{
	0%
	{
		top: 1080px;
		opacity: 0;
		-webkit-transform: rotateX(0deg);
	}
	20%
	{
		top: 945px;
		opacity: 1;
	}
	80%
	{
		top: 945px;
		opacity: 1;
	}
	100%
	{
		top: 1080px;
		opacity: 0;
	}
}
.b-left
{
	background-color: rgba(100,0,0,0.6);
	display: inline-block;
	margin: none;
	padding: none;
	height: 135px;
	width: 246px;
	position: fixed;
	left: 714px;
	animation-name: b-left-a;
	animation-duration: 10s;
	color: #fff;
}
@-webkit-keyframes b-left-a
{
	0%
	{
		left: 745px;
	}
	20%
	{
		left: 745px;
	}
	40%
	{
		left: 560px;
	}
	60%
	{
		left: 560px;
	}
	80%
	{
		left: 745px;
	}
	100%
	{
		left: 745px;
	}
}
.b-center
{
	background-color: rgba(0,100,0,.2);
	display: inline-block;
	width: 308px;
	margin: none;
	padding: none;
	height: 135px;
	position: fixed;
	left: 806px;
	color: #fff;
}
.b-right
{
	background-color: rgba(0,0,100,0.6);
	display: inline-block;
	margin: none;
	padding: none;
	float: right;
	height: 135px;
	width: 246px;
	position: fixed;
	left: 960px;
	animation-name: b-right-a;
	animation-duration: 10s;
	background-position: right;
	color: #fff;
}
@-webkit-keyframes b-right-a
{
	0%
	{
		left: 926px;
	}
	20%
	{
		left: 926px;
	}
	40%
	{
		left: 1114px;
	}
	60%
	{
		left: 1114px;
	}
	80%
	{
		left: 926px;
	}
	100%
	{
		left: 926px;
	}
}
<div class="container">
	<div class="bottom-container">
		<div class="b-holder">
			<div class="b-left">
				LEFT
			</div>
			<div class="b-right">
				RIGHT
			</div>
			<div class="b-center">
				CENTER
			</div>
		</div>
	</div>
</div>
If the transform is removed from b-holder-a all divs are positioned properly. What causes this to happen? How do I get the left right and center divs to stay absolutely positioned when a transform is added to the containing divs animation?

Note: this is specifically crafted for Chrome browsers

Upvotes: 0

Views: 152

Answers (1)

Fasio_Vita
Fasio_Vita

Reputation: 11

For some reason when a transform is added, the contents of the div use Absolute positioning instead of Fixed positioning. I solved this by changing the left values for each animation.

Upvotes: 1

Related Questions