我在使用CSS网格减少页脚空间时遇到一些问题。我已经达到了我的列表项在一行上的程度,但是我找不到缩小两者之间差距的方法。这可能是因为我居中,但在谷歌搜索/播放后我无法弄清楚。
https://codepen.io/DanielPeterHill/pen/pxjpzM
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
font-family: 'Oswald', sans-serif;
color: #FEDCD2;
}
.nav-container {
width: 100%;
background: #DF744A;
margin: 0;
}
nav {
max-width: 1720px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr auto 1fr;
}
.left-menu {
grid-column: 1;
align-self: center;
}
.logo {
grid-column: 2;
}
#nav-toggle,
.burger-menu {
display: none;
}
nav a {
color: white;
text-decoration: none;
text-transform: uppercase;
transition: .3s all ease-in-out;
}
nav a:hover {
opacity: .7;
color: blue;
}
.left-menu a {
padding: 10px 0;
margin-left: 15px;
font-size: 14px;
font-weight: 300;
letter-spacing: 0.5px;
}
.logo {
font-size: 40px;
padding: 1rem;
}
.burger-menu {
grid-column: 1;
align-self: center;
margin-left: 20px;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: #DF744A;
color: white;
text-align: center;
}
footer {
display: grid;
grid-template-rows: auto 3fr auto;
}
.footer-left {
grid-column: 1;
align-self: center;
}
.footer-right {
grid-column: 3;
align-self: center;
list-style-type: none;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-row-gap: 50px;
}
.footer-right li {
text-decoration: none;
}
.footer-right li a {
color: white;
}
.footer-right li a:hover {
opacity: .7;
color: blue;
}
.underlineremove {
text-decoration: none;
text-decoration-style: none;
}
@media only screen and (max-width: 1025px) {
.burger-menu {
display: inline-block;
width: 40px;
}
.left-menu {
display: none;
}
#nav-toggle:checked~.left-menu {
display: grid;
grid-row: 2;
}
}
<link href="https://fonts.googleapis.com/css?family=Oswald:600" rel="stylesheet">
<div class="nav-container">
<nav>
<input type="checkbox" id="nav-toggle">
<label for="nav-toggle" class="burger-menu">
<img src="images/hamburger.png" alt="">
</label>
<div class="left-menu">
<a href="#">Shop</a>
<a href="#">Blog</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
<a href="#" class="logo">Dill's Delight's</a>
</nav>
</div>
<div class="footer">
<footer>
<p class="footer-left"> © FarHill Deisgns </p>
<ul class="footer-right">
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
</ul>
</footer>
</div>
以上是我的示例,任何帮助都将是惊人的!我的结果将是能够减少右下角4个TESTS之间的距离,以使其看起来更干净。
谢谢
丹
答案 0 :(得分:0)
您可以尝试以下方法:
.footer-right
{
grid-column: 3;
align-self: center;
list-style-type: none;
display: grid;
grid-template-columns: repeat(4, 50px);
grid-row-gap: 50px;
}
我将网格模板列更改为此grid-template-columns: repeat(4, 50px);
,以使列宽为50px。但是,如果这不适合您,则您始终可以使用%或其他度量形式的其他宽度。
答案 1 :(得分:0)
一个选项...根本不使用CSS-Grid。 Flexbox会更简单。
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
font-family: 'Oswald', sans-serif;
color: #FEDCD2;
}
.footer {
/* not required for demo
position: fixed;
left: 0;
bottom: 0;
width: 100%;
*/
background-color: #DF744A;
color: white;
text-align: center;
}
footer {
display: flex;
}
.footer-left {
grid-column: 1;
align-self: center;
}
.footer-right {
margin-left: auto;
list-style-type: none;
display: flex;
}
.footer-right li {
text-decoration: none;
margin: .25em;
/* manages spacing */
}
.footer-right li a {
color: white;
}
.footer-right li a:hover {
opacity: .7;
color: blue;
}
.underlineremove {
text-decoration: none;
text-decoration-style: none;
}
<div class="footer">
<footer>
<p class="footer-left"> © FarHill Deisgns </p>
<ul class="footer-right">
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
</ul>
</footer>
</div>
或者,如果必须使用CSS-Grid,则考虑使用两列网格并弯曲ul
...
footer {
display: grid;
grid-template-columns:1fr auto;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
font-family: 'Oswald', sans-serif;
color: #FEDCD2;
}
.footer {
/* not required for demo
position: fixed;
left: 0;
bottom: 0;
width: 100%;
*/
background-color: #DF744A;
color: white;
text-align: center;
}
footer {
display: grid;
grid-template-columns: 1fr auto;
}
.footer-left {
grid-column: 1;
align-self: center;
}
.footer-right {
margin-left: auto;
list-style-type: none;
display: flex;
}
.footer-right li {
text-decoration: none;
margin: .25em;
}
.footer-right li a {
color: white;
}
.footer-right li a:hover {
opacity: .7;
color: blue;
}
.underlineremove {
text-decoration: none;
text-decoration-style: none;
}
<div class="footer">
<footer>
<p class="footer-left"> © FarHill Deisgns </p>
<ul class="footer-right">
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
<li><a href="#" class="underlineremove">TEST</a></li>
</ul>
</footer>
</div>