[英]How do I get this div tag to the right side of the box?
.left {
width: 50%;
display: inline-block;
float: left;
}
/* Second user block */
.right {
border-color: lightskyblue;
background-color: darkcyan;
width: 50%;
display: inline-block;
float: right;
}
These are the css for the wrappers, not sure why it does not work still. 这些是包装器的CSS,不确定为什么它仍然无法正常工作。
.boxed {
border: 2px solid black;
padding-left: 20px;
padding-right: 20px;
padding-bottom: 20px;
background-color: darkgoldenrod;
max-width:800px;
margin:1rem auto;
overflow:hidden;
}
/* Chat blocks */
.block {
border: 2px solid darkgreen;
background-color: lightgreen;
border-radius: 30px;
padding: 10px;
margin: 10px 0;
border-radius:20px;
margin-bottom:10px;
width:60%;
}
I am making a mock UI and I can't seem to get the blue chat bubbles to the right side, I tried using right: 0px;
我正在制作一个模拟UI,但似乎无法将蓝色聊天气泡显示在右侧,我尝试使用
right: 0px;
and float: right;
float: right;
but both don't seem to work. 但两者似乎都不起作用。 Are there any other css tags I can use position it correctly?
我还可以使用其他CSS标签正确定位它吗?
Here are the div tags: 以下是div标签:
<div class="boxed card my-3">
<h2 align="center">Chat Log:</h2>
<div class="block left">
<img src="User1.jpg" alt="FortniteGamer">
<p>Hey whats up?. Do you want to get a game going?</p>
<span class="time-right">11:00</span>
</div>
<div class="block right">
<img src="User2.jpg" alt="CODGamer" class="right">
<p>Hey! Yeah defintely that sounds fun!</p>
<span class="time-left">11:01</span>
</div>
<div class="block left">
<img src="User1.jpg" alt="FortniteGamer">
<p>Sweet! Whats your username on fornite?</p>
<span class="time-right">11:02</span>
</div>
<div class="block right">
<img src="User2.jpg" alt="CODGamer" class="right">
<p>My username is: CODSav</p>
<span class="time-left">11:02</span>
</div>
</div>
It seems that the wrapper ( .card
) is a flex container, in which case floats wont have any effect. 似乎包装器(
.card
)是一个flex容器,在这种情况下,浮点数不会起作用。
Instead, set the opposite margin to auto: 而是将相反的边距设置为auto:
.right {
border-color: lightskyblue;
background-color: darkcyan;
width: 50%;
margin-left:auto;
}
Put position:absolute and try: 放置位置:绝对,然后尝试:
.right {
position:absolute;
border-color: lightskyblue;
background-color: darkcyan;
width: 50%;
display: inline-block;
float: right;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.