html - Div 不正确
问题描述
我希望第二个和第三个 div 的文本在右侧。我通过使用margin-left: auto
并将所有 div 设置为display: inline-block
. 它也不起作用float: left
。我做错了什么?
它应该看起来像这样
.header > div {
display: inline-block;
}
.right-justified{
margin-left: auto;
width: auto;
}
<section class="header">
<div>
<div>Left</div>
<div>Left</div>
</div>
<div class="right-justified">
<div>Right</div>
<div>Right</div>
</div>
<div>
<div>Right</div>
</div>
</section>
解决方案
您应该使用 flexbox 或网格来获得更好的布局设计,从而成为一名出色的开发人员,而不是使用这种愚蠢的技术。
试试下面的代码——
.header{
display: flex;
justify-content: space-between;
}
.right-justified{
display: flex;
}
.mid{
align-self: center;
margin:0 1rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/style.css" />
<title>template</title>
</head>
<body>
<section class="header">
<div>
<div>Left</div>
<div>Left</div>
</div>
<div class="right-justified">
<div>
<div>Right</div>
<div>Right</div>
</div>
<div class="mid">
<div>Right</div>
</div>
</div>
</section>
</body>
</html>
推荐阅读
- php - 使用 php 更新和重新加载 mysql - 删除确认问题
- javascript - 使用 PHP 和 JS 的 While 循环中的 SQL 查询不工作
- oracle - 如何使用一个程序插入两个表
- python - 如何使用 tokezine/untokenize?
- laravel - 访问关注者数据 Laravel 5.8 和 Eloquent
- math - 标记数据的离散度测量
- c++ - 对 Google CodeJam 2018 预选赛进行故障排序
- .net - 无法访问已处置的对象。此错误的常见原因是处理上下文
- haskell - 为什么这个单射类型族实际上不是单射的?
- maven - jenkins(openshift) chrome 节点上的“org.openqa.selenium.WebDriverException:未知错误:Chrome 无法启动:异常退出”问题