0
A
回答
1
最好的办法是使用Flex样式。
- 删除所有样式 '.title伪我', '.title伪跨度',” .title伪H1'
- 编辑标题如下:
Flex的字幕样式:
.title {
width: 100%;
margin: 30px auto;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
justify-content:center; - 这将重新对齐H1,短划线和中间跨度。
align-items:center; - 这给你的垂直对齐。
0
在h1
和span
周围添加一个包装,然后将其设置为inline-flex
。包装将由于标题为text-align
而居中。
.title {
width: 100%;
margin: 30px auto;
text-align: center;
}
.wrapper {
display: inline-flex;
justify-content: flex-start;
align-items: center;
}
.title i {
color: var(--grey-500);
}
.title span {
font-size: var(--caption);
line-height: 40px;
color: #9E9E9E;
}
.title h1 {
color: var(--black);
font-size: var(--h1);
text-align: center;
font-weight: 500;
margin: 65px auto;
}
<div class="title">
<div class="wrapper">
<h1>Title 1</h1> <i class="material-icons separateTitleType">remove</i> <span>Page</span>
</div>
</div>
0
将此代码添加到.title
display: flex;
justify-content:center;
align-items:center;
而且,我从h1
删除margin: 65px auto
所以它不会把所有的地方在柔性容器。
/* Titles */
.title {
width: 100%;
margin: 30px auto;
text-align: center;
display: flex;
justify-content:center;
align-items:center;
}
.title i {
color: var(--grey-500);
}
.title span {
font-size: var(--caption);
line-height: 40px;
color: #9E9E9E;
}
.title h1 {
color: var(--black);
font-size: var(--h1);
text-align: center;
font-weight: 500;
}
:root {
--black: #000000;
--h1: 2.125em;
--caption: 0.875em;
--grey-500: #9E9E9E;
}
/* fallback */
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: local('Material Icons'), local('MaterialIcons-Regular'), url(https://fonts.gstatic.com/s/materialicons/v22/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2) format('woff2');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
body {
font-family: 'Roboto', sans-serif;
background-color: #fff;
}
<div class="title">
<h1>Title 1</h1> <i class="material-icons separateTitleType">remove</i> <span>Page</span>
</div>
相关问题
- 1. 如何垂直居中h1和跨度在li
- 2. 我该如何在一个div中垂直居中跨度?
- 3. 如何垂直居中跨度和一个列表内的div?
- 4. 如何将这个textView垂直居中?
- 5. 如何垂直居中固定位置的文本跨度?
- 6. 在一个div中垂直居中跨度
- 7. RelativeLayout垂直居中于右
- 8. 如何垂直居中div?
- 9. 如何居中垂直figcaption?
- 10. Bootstrap如何垂直居中
- 11. 如何垂直居中div?
- 12. 如何垂直居中div?
- 13. 我如何垂直居中?
- 14. 中心跨度垂直
- 15. 中心跨度垂直
- 16. 在列表项中垂直和水平居中跨度
- 17. 如何将(H1 +(跨度))+(H2)变为(跨度)+(H1)+(H2)...?
- 18. 垂直居中
- 19. Flexbox不垂直居中嵌入块跨度
- 20. 垂直居中与背景图像的跨度
- 21. 垂直居中响应横幅图像中的H1 + H2线
- 22. 垂直居中两个div
- 23. 垂直居中一个div
- 24. 如何水平和垂直居中这四个divs的内容?
- 25. CSS垂直对齐跨度
- 26. 与跨度垂直对齐
- 27. 垂直对齐跨度Div
- 28. 跨度垂直对齐
- 29. 为什么这不是垂直居中?
- 30. 如何垂直居中这个基于CSS/JavaScript的模态对话框?
这是完美的,更短的代码。谢谢! – joostdelange