我的图像为display: block;、text-align: center;、 ,width: 33%;但仍然没有居中或表现得像 33%。我也尝试过width: 33vw(33%视口宽度),仍然没有运气。
我尝试创建一个100%的容器,然后创建一个图像所在的div,仍然没有解决它。我有一种强烈的感觉,这很愚蠢,但我已经看代码太久了,我找不到它。我只是希望徽标的大小发生变化,以便手机上的用户可以看到完整的徽标,而不必向右滚动。
a {
text-decoration: none;
color: black;
}
nav {
position: sticky;
position: -webkit-sticky;
top: 0;
}
.nav {
position: sticky;
left: 0;
background-color: rgba(255,255,255,.8);
border-radius: 0px;
border: none;
width: 100%;
padding: 10px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: capitalize;
width: 25%;
text-align: center;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
padding-top: 107px;
padding: 10px;
font-size: small;
left: 0;
right: 0;
text-transform: capitalize;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: left;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: left;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255,255,255,.8);
}
ul {
list-style: none;
padding: 0;
}
.logo {
top: 0;
display: block;
width: 33%;
text-align: center;
margin-top: 50px;
margin-bottom: 25px;
}
Run Code Online (Sandbox Code Playgroud)
<head>
<meta charset="UTF-8" content="width=device-width, initial-scale= 1">
<title>Graphic Design</title>
<link href="../CSS/Navigation.css" rel="stylesheet" type="text/css">
<link href="../CSS/Printing.css" rel="stylesheet" type="text/css">
</head>
<a class="logo" href="index.html">
<img src="../Images/Navigation/Intak Logo 40px High.png" alt="Home"/>
</a>
<nav>...
Run Code Online (Sandbox Code Playgroud)
它应该以 33% 的宽度居中,但它不会对宽度命令或居中做出反应。
这可能是解决您的问题的最基本的解决方案。
.logo {
display: block;
margin-right: auto;
margin-left: auto;
width: 33.33333vw;
}Run Code Online (Sandbox Code Playgroud)
<img class="logo" src="https://via.placeholder.com/600x600/fc0">Run Code Online (Sandbox Code Playgroud)
有链接。
.logo {
display: block;
margin-right: auto;
margin-left: auto;
width: 33.33333vw;
}
.logo img {
display: block;
height: auto;
max-width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<a class="logo" href="#">
<img src="https://via.placeholder.com/600x600/fc0">
</a>Run Code Online (Sandbox Code Playgroud)