如果只是文本,请尝试
text-align
如果您只使用文本,那么您需要对CSS进行的唯一更改是:
#cont-left {
text-align: right;
}
如果不是的话怎么办:那么是时候
flex
如果要使用的文本多于应使用的文本
display: flex;
这样你就可以
justify-content: flex-end;
(将内容调整到末尾)。您需要将这些应用于容器
#cont-left
和
#cont-right
. 为了
右下角
使用
justify-content: flex-start;
但是,当应用这些值时,
#test
和
#test2
将不再占用其父级的宽度,因此,您将需要移动
background-color
到父级divs或set
width: 100%;
下面我已经修改了代码段以包括
弯曲
变化。
$("#run").on("click", function() {
$("#cont-left, #cont-right").toggleClass("hide");
});
#cont-right {
position: absolute;
top: 0px;
right: 0px;
width: 200px;
overflow: hidden;
transition: all 0.5s ease-in-out;
display: flex;
justify-content: flex-start;
background: yellow;
}
#cont-left {
position: absolute;
top: 0px;
height: 30px;
left: 0px;
width: 200px;
overflow: hidden;
transition: all 0.5s ease-in-out;
display: flex;
justify-content: flex-end;
background: pink;
}
#run {
display: block;
width: 100px;
background: red;
cursor: pointer;
margin: 0 auto;
color: white;
padding: 10px 0px;
text-align: center;
font-weight: bold;
}
#run:hover {
background: green;
}
#cont-right.hide,
#cont-left.hide {
width: 0px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="cont-right" class="hide">
<div id="test">
111<br />222<br />333
</div>
</div>
<div id="cont-left" class="hide">
<div id="test2">
111<br/>222<br />333
</div>
</div>
<span id="run">Run</span>