html - 当右侧元素是居中对齐的多行文本时,如何删除并排元素之间的额外空间?
问题描述
我正在实现一个带有元素并排的标题 - 左侧的图标和右侧的标题。
标题居中对齐。
当屏幕变窄并且标题换到下一行时,在图标和标题之间会创建一个空格。
正如您在屏幕截图中看到的,空间是内容的一部分(它不是填充或边距)。
即使标题换行,如何让标题靠在图标上?
这是要重现的基本 HTML 和 CSS:
HTML
<div class="container">
<svg class="svg" height="50" width="50">
<circle cx="25" cy="25" r="20" stroke="black" stroke-width="3" fill="red" />
</svg>
<h1 class="title">The title of the page</h1>
</div>
CSS
.container {
width: 320px; /* simulate mobile width */
display: flex;
justify-content: center;
align-items: flex-start;
}
.title {
text-align: center;
}
试用 Codepen 链接:https ://codepen.io/JayC_IRL/pen/VwKoJVQ
解决方案
推荐阅读
- reactjs - 使用 react-router 构建不显示我的应用程序(空白页面)
- html - 简单的侧边栏导航来填充主要内容
- python - 无法在 Windows 或 Mac OS 上安装 MOSAIC
- c# - 在 ASP.NET Core 3.1 MVC 中使用全球化和本地化时命名空间的作用
- java - 用户'root'@'localhost'的访问被拒绝-Spring Boot和MySQL连接
- r - R KNN 错误 - knn 中的错误(training_data,validation_data,training_data$Award.,k = 7):“train”和“class”的长度不同
- f# - 在 Deedle 中对列进行分组
- python-3.x - 获取可移植(gnu)Makefile 使用模式规则对匹配正则表达式的子目录中的文件进行操作
- javascript - 用于自定义交易的 Netsuite 交易摘要框
- r - 在列列表中添加几个滞后/移位