I know this question has been asked before, but the solutions out there did not work for me.
中调整图像大小这是我的图片,最大宽度和最大高度设置为100%。
即使将max-width和max-height设置为50%,我的图像仍然无法正确显示。它没有居中。
这是我的代码:
.container-header {
width: 100%;
height: 8%;
display: flex;
flex-direction: column;
background: #e3f0da
}
.container-nav {
height: 100%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
/* x-axis */
align-items: center;
/* y-axis */
font-size: 1.8em;
background: #f2f2e2
}
li {
list-style-type: none;
margin: 0 15px 0 15px
}
a {
text-decoration: none
}
img {
max-width: 50%;
max-height: 50%;
}
<div class="container-header">
<div class="container-nav">
<li><a href="#">Portfolio</a></li>
<li><a href="#">Resume</a></li>
<li><a href="#"><img src="img/logo.png"></a></li>
<li><a href="#">About Me</a></li>
<li><a href="#">Contact</a></li>
</div>
</div>
答案 0 :(得分:1)
将$ node -v
v9.9.0
$ npm -v
6.2.0
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32]
$ bundler -v
Bundler version 1.16.3
元素显示为a
,然后可以使用block
将其居中。
test-align
li a {
display: block;
text-align: center;
}
.container-header {
width: 100%;
height: 8%;
display: flex;
flex-direction: column;
background: #e3f0da
}
.container-nav {
height: 100%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
/* x-axis */
align-items: center;
/* y-axis */
font-size: 1.8em;
background: #f2f2e2
}
li {
list-style-type: none;
margin: 0 15px 0 15px
}
a {
text-decoration: none
}
img {
max-width: 50%;
max-height: 50%;
}
li a {
display: block;
text-align: center;
}
答案 1 :(得分:1)
问题是您没有告诉它以a标签为中心。
a{
display:flex;
justify-content: center;
align-items: center;
}