html - 如何将徽标与链接对齐?
问题描述
我正在尝试使用通过 MYSQL 收集的链接正确地在 css 中获取 SVG 徽标。我无法设置链接的样式,因此它们与 SVG 居中对齐。我尝试了添加vertical-align:center的常用技巧,但它不喜欢那样。我在这里做错了什么?
i.logo {
position: absolute;
background: url(http://www.grampianyoga.org.uk/other/lvo.svg) no-repeat;
top: 0;
left: 0;
min-width: 200px;
height: 100%;
background-color: rgba(0, 0, 0, .2);
background-size: 200px;
background-position: 50%
}
.logoheader {
background: transparent;
color: #fff;
padding: 20px 60px 20px 100px;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
position: relative;
min-height: 200px;
width: 100%;
}
.logoheader a {
font-size: 40px;
line-height: 1.5;
color: black;
-ms-flex-item-align: center;
align-self: center;
margin: 0 20px 0 0;
}
<nav>
<div class='logoheader'>
<i class="logo"></i>
<a href='page.php'>section</a> | <a href='page.php'>contact</a> |
</div>
</nav>
解决方案
如果您唯一关心的是将内容垂直居中,则可以使用 flexbox。例如,看看下面的附加片段。
我将您的图像更改为relative
位置并将其显示更改为block
,然后将它们全部插入到弹性框中。
i.logo {
position: relative; /*changed this*/
display: block; /*added this*/
background: url(http://www.grampianyoga.org.uk/other/lvo.svg) no-repeat;
min-width: 200px;
height: 200px; /* changed this */
background-color: rgba(0, 0, 0, .2);
background-size: 200px;
}
.logoheader {
background: transparent;
color: #fff;
padding: 20px 60px 20px 100px;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
position: relative;
min-height: 200px;
width: 100%;
display: flex; /*added this*/
align-items: center;
}
.logoheader a {
font-size: 40px;
line-height: 1.5;
color: black;
-ms-flex-item-align: center;
align-self: center;
margin: 0 20px 0 0;
}
<nav>
<div class='logoheader'>
<i class="logo"></i>
<a href='page.php'>section</a> | <a href='page.php'>contact</a> |
</div>
</nav>
希望能帮助到你!
推荐阅读
- javascript - OpenLayers create Layers from GeoJSON by property
- javascript - 我想知道我可以获得路径 PromiseValue 数据
- javascript - 无重复的随机报价生成器
- javascript - 如何在没有 Internet 连接的情况下在 Web 浏览器中显示谷歌地图
- javascript - web - website is laggy when scrolling on chrome
- sql - Invalid expression in the select list when using group by
- java - 在 Intents 中传递 FirebaseFirestore 引用
- apache - Tomcat 是 HTTP 服务器还是 Servlet 容器?
- reactjs - 从快速服务器发出渲染反应应用程序
- git - VS2017:构建子文件夹下的 git