[英]how to block width expansion of div from right side without using position absolute?
我想創建一個 div 元素,當我們在其中添加任何內容時,該元素僅從左側擴展。
<div
id="sent_message"
style='background-color: #2b89cc; color: white; font-family: Arial,Helvetica, sans-serif; margin-top: 10px; display: inline-block; max-width: 50%; min-width: 20%; font-size: 25px; border-radius: 5px; word-wrap: break-word; position: relative; right: -1360;'>
<p>Hello</p>
</div>
我不希望使用position:absolute
這項工作。 有沒有辦法阻止div從右側擴展? 我會很高興回答。
使用float:right
window.setTimeout(function(){ document.querySelector('#sent_message p').innerHTML = 'Hello World, welcome!'; }, 1000);
#sent_message { background-color: #2b89cc; color: white; font-family: Arial, Helvetica, sans-serif; margin-top: 10px; display: inline-block; max-width: 50%; min-width: 20%; font-size: 25px; border-radius: 5px; word-wrap: break-word; position: relative; float: right; }
<div id="sent_message"> <p>Hello</p> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.