css - 如何在保持宽度的同时将标题移动到右侧?
问题描述
我在保持给定宽度的同时将 h2 标题移动到屏幕右侧时遇到问题。我试过 display: flex 和 float: right 但我似乎无法弄清楚如何有效地将 h2 div 对齐到屏幕的右侧。我的代码在这里:http: //jsfiddle.net/b62tg9un/19/
<div class="container">
<h1>Example Title</h1>
<h2>This is a test sentence to work on my html and css code.</h2>
</div
h2 {
width: 60%;
float: right;
}
.highlight {
display: inline-block;
}
.container {
display: flex;
flex-direction: column;
text-align: right;
justify-items: right;
}
谢谢
解决方案
如果您希望 flex 容器中的项目与容器的右侧对齐,您应该使用align-items: flex-end
h2 {
width: 60%;
}
.container {
align-items: flex-end;
display: flex;
flex-direction: column;
}
这仍然会将 h1 和 h2 放在一列中,但 h2 仅占宽度的 60% 并向右对齐。
推荐阅读
- amazon-web-services - 如何在不更改上次修改时间的情况下触发 AWS s3 事件?
- c - 相同的输入数据可以有不同的CRC值吗?
- mysql - 如何在 SQL 中反转所有用户交易以获取上一个日期的余额
- git - git log --cherry-pick A..B - 我做错了什么?
- xml - xQuery 使用命名空间的数据?
- javascript - 如何在不同的页面中获取 cookie?
- java - 如何迭代两个相同大小的列表并通过迭代两个列表来在另一个列表中设置其他列表值?
- virtual-machine - Azure 上适用于 Linux 的 VM。开启APS拉取用户数据
- angular - ngx-bootstrap 日期选择器不可编辑 | 角 8
- python - 如何在从基类生成的类上创建@property?