javascript - 使 div 的右侧而不是左侧对齐

标签 javascript jquery html css

我有 2 个 div,一个在另一个之上。您看到红色边框 div 的左侧如何与蓝色边框 div 的左侧对齐了吗?我的问题是,有没有办法让红色边框 div 的右侧与蓝色边框 div 的右侧对齐?

#top {
   border: 1px solid red;
   display: inline-block;
}

#bottom {
   border: 1px solid blue;
   width: 25%;
   display: block;
}
<div id = 'top'> top </div>
<div id = 'bottom'> bottom </div>   

最佳答案

是的,你可以有一个容器并将里面的元素向右浮动:

#top {
   border: 1px solid red;
   display: inline-block;
   float: right;
}

#bottom {
   border: 1px solid blue;
   width: 25%;
   display: block;
   clear:both;
   float: right;
}

#container {
  width: 50%;
}
<div id="container">
    <div id = 'top'> top </div>
    <div id = 'bottom'> bottom </div>
</div>

关于javascript - 使 div 的右侧而不是左侧对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33028578/

相关文章:

javascript - 使用 AngularJS 发送数据的 Multipart/form-data 表单

php - Fancybox - 重新加载页面或加载新页面

javascript - HTML 5 "number"类型输入在输入小数位时没有值

jquery - 实现 datepicker jquery UI 时出错

javascript - 无法隐藏/取消隐藏表单内的按钮

javascript - 用 500 行填充表格需要很长时间 - jQuery 和 Bootstrap CSS

html - Bootstrap : Full page width mega menu inside a responsive container

javascript - 直接访问 JSON 子对象的更好方法

javascript - 如果数据库中存在数据则显示警报图标 - JQuery AJAX

javascript - $.get() 方法 JQuery 不读取任何内容 (html)