[英]2 div side by side using css - one move
How can I place two div side by side One of them is moving continuously up and down and containing img 如何将两个div并排放置,其中之一是连续上下移动并包含img
I tried this : 我尝试了这个:
<div>
<div style="margin:30px;width:100px;height:250px;position:relative;float:left;background-color:red;">A</div>
<div style="margin:30px;width:100px;height:50px;position:relative;float:left;background-color:blue;">B</div>
</div>
Can I make the B div move up and down ? 我可以让B div上下移动吗?
Since you have tagged this question with CSS and not Jquery/Javascript am using CSS keyframes animations. 由于您已使用CSS标记了此问题,而Jquery / Javascript没有使用CSS关键帧动画。 It is not supported in IE<=9 .
IE <= 9不支持它。
div.boxB { -webkit-animation: move 5s linear infinite; -moz-animation: move 5s linear infinite; animation: move 5s linear infinite; } @-webkit-keyframes move { 0% { margin-top: 30px; } 25% { margin-top: 100px; } 50% { margin-top: 180px; } 75% { margin-top: 100px; } 100% { margin-top: 30px; } } @-moz-keyframes move { 0% { margin-top: 30px; } 25% { margin-top: 100px; } 50% { margin-top: 180px; } 75% { margin-top: 100px; } 100% { margin-top: 30px; } } @keyframes move { 0% { margin-top: 30px; } 25% { margin-top: 100px; } 50% { margin-top: 180px; } 75% { margin-top: 100px; } 100% { margin-top: 30px; } }
<div> <div style="margin:30px;width:100px;height:200px;position:relative;float:left;background-color:red;">A</div> <div class="boxB" style="margin:30px;width:100px;height:50px;position:relative;float:left;background-color:blue;">B</div> </div>
you can do it in two ways: 您可以通过两种方式做到这一点:
display:block
display:block
float:right
float:right
到右边float:right
You can use display: inline-block and move your B div up and down with top and bottom. 您可以使用display:inline-block并上下移动B div。
<div> <div style="30px 0 0 0;width:100px;height:250px;position:relative;display: inline-block;background-color:red;">A</div> <div style="30px 0 0 0;width:100px;height:50px;position:relative;display: inline-block;background-color:blue;top: 90px;">B</div> </div>
you can have it side by side by making the right,bottom and left margins to 0px. 您可以将右,底和左边界设为0px并排放置。
<div> <div style="margin:30px 0 0 0;width:100px;height:250px;position:relative;float:left;background-color:red;">A</div> <div style="margin:30px 0 0 0;width:100px;height:50px;position:relative;float:left;background-color:blue;">B</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.