html - HTML 中的图像和文本一个标签,其中图像调整大小以适合容器
问题描述
我有一个 482x482 图像,我想与一个<nav>
定义如下的容器一起使用:
<nav id="nav">
<ul class="links">
<li><a href="/exchange/accueil">
<img src="{% static 'exchange/images/HomeIconWhite.png' %}"></img>
</a><p>Accueil</p></li>
<li><a href="/exchange/recherche_avance">Recherche avancée</a></li>
<li><a href="/exchange/rajouter">Ajouter une info</a></li>
{% if user.is_authenticated %}
<li><a href="/exchange/deconnexion">Déconnexion</a></li>
{% else %}
<li><a href="/exchange/connexion">Connexion</a></li>
{% endif %}
</ul>
</nav>
定义此容器的 CSS 如下:
#nav {
color: #ffffff;
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-transition: -moz-transform 1s ease, opacity 1s ease;
-webkit-transition: -webkit-transform 1s ease, opacity 1s ease;
-ms-transition: -ms-transform 1s ease, opacity 1s ease;
transition: transform 1s ease, opacity 1s ease;
background: rgba(255, 255, 255, 0.175);
height: 4rem;
line-height: 4rem;
margin: -4rem auto 0 auto;
overflow: hidden;
padding: 0 2rem 0 0;
position: relative;
width: calc(100% - 4rem);
max-width: 72rem;
z-index: 2;
}
#nav ul.divided li {
border-top-color: #ffffff;
}
#nav ul.icons li a.icon:hover:before {
color: #18bfef;
}
#nav ul.icons.alt li .icon:before {
box-shadow: inset 0 0 0 2px #ffffff;
}
#nav ul.icons.alt li a.icon:hover:before {
box-shadow: inset 0 0 0 2px #18bfef;
}
#nav input, #nav select, #nav textarea {
color: #ffffff;
}
#nav a {
color: #ffffff;
border-bottom-color: rgba(255, 255, 255, 0.5);
}
#nav a:hover {
border-bottom-color: transparent;
color: #18bfef !important;
}
#nav strong, #nav b {
color: #ffffff;
}
#nav h1, #nav h2, #nav h3, #nav h4, #nav h5, #nav h6 {
color: #ffffff;
}
#nav blockquote {
border-left-color: #ffffff;
}
#nav code {
background: rgba(255, 255, 255, 0.075);
border-color: #ffffff;
}
#nav hr {
border-bottom-color: #ffffff;
}
#nav ul.links {
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-flex-grow: 1;
-webkit-flex-grow: 1;
-ms-flex-grow: 1;
flex-grow: 1;
-moz-flex-shrink: 1;
-webkit-flex-shrink: 1;
-ms-flex-shrink: 1;
flex-shrink: 1;
font-family: "Source Sans Pro", Helvetica, sans-serif;
font-weight: 900;
letter-spacing: 0.075em;
list-style: none;
margin-bottom: 0;
padding-left: 0;
text-transform: uppercase;
}
#nav ul.links li {
display: block;
padding-left: 0;
}
#nav ul.links li a {
-moz-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
-webkit-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
-ms-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
display: block;
font-size: 0.8rem;
outline: none;
padding: 0 2rem;
}
#nav ul.links li a:hover {
color: inherit !important;
background-color: rgba(255, 255, 255, 0.1);
}
#nav ul.links li.active {
background-color: #ffffff;
}
#nav ul.links li.active a {
color: #1e252d;
}
#nav ul.links li.active a:hover {
color: #18bfef !important;
}
#nav ul.icons {
-moz-flex-grow: 0;
-webkit-flex-grow: 0;
-ms-flex-grow: 0;
flex-grow: 0;
-moz-flex-shrink: 0;
-webkit-flex-shrink: 0;
-ms-flex-shrink: 0;
flex-shrink: 0;
margin-bottom: 0;
}
@media screen and (max-width: 980px) {
#nav {
display: none;
}
}
我尝试在 CSS 中定义一些规则,#nav ul.links img
但这并没有达到我的目标。
我想要的是图像正确适合导航容器,在其中居中并在其旁边有一些文本(也居中)
我很确定这样做的方式很明显,但我没有在网上找到任何适合我的问题的答案,它们都有不同的变化,使它们不适用于我的问题。
如果您需要更多详细信息,请告诉我。图像的链接 100% 有效,因此问题不来自于此。
编辑
这是Github链接。
解决方案
推荐阅读
- java - 同步器混乱
- excel - 确定列中的值是否在数组中的 2 个数字之间
- c - 在C中使用pthreads查找数组的平方和
- jenkins - provider.vault:“地址”:未设置必填字段
- asp.net-core - 如何使用 ASP.NET Core 2.2 创建用户
- java - Spring Boot Cacheable 注解——如何刷新每个请求的结果
- python - 如何修复两个对象同名“分配前引用的局部变量”Python中的错误
- mysql - 在 MySQL 中取消透视多个分组列
- ios - 如何用可变行创建一段StaticTableView?
- python - 如何在文本文档中找到这种模式?