gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
.nav-link { align-items: center; /* text-align: center; */ margin-top: 1%;…
- User
.nav-link { align-items: center; /* text-align: center; */ margin-top: 1%; margin-bottom: 1%; border: none; border-left: 1px solid #176dd0; padding: 10px; }
code.nav-link a { color: white; text-decoration: none; } .nav-link:hover { background-color: #4fc1e9; text-align: center; margin-top: 0; margin-bottom: 0; }为什么文字会上浮 - Assistant
文字上浮的原因是因为在.nav-link:hover伪类中设置了margin-top: 0和margin-bottom: 0。这会将文字的顶部和底部边距设置为0,从而导致文字上浮。如果希望文字保持在垂直居中的位置,可以移除这两行margin的设置。
- User
.nav-link { align-items: center; /* text-align: center; */ margin-top: 1%; margin-bottom: 1%; border: none; border-left: 1px solid #176dd0; padding: 10px; }
code.nav-link a { color: white; text-decoration: none; } .nav-link:hover { background-color: #4fc1e9; text-align: center; margin-top: 0; margin-bottom: 0; }在不去除margin的情况下怎么改善文字上浮情况使得文字仍旧居中 - Assistant
如果想保持文字在垂直居中的同时不去除margin,可以使用flexbox布局。将父元素的display属性设置为flex,并使用align-items: center;来使文字垂直居中。以下是修改后的代码:
code.nav-link { display: flex; align-items: center; /* text-align: center; */ margin-top: 1%; margin-bottom: 1%; border: none; border-left: 1px solid #176dd0; padding: 10px; } .nav-link a { color: white; text-decoration: none; } .nav-link:hover { background-color: #4fc1e9; text-align: center; margin-top: 0; margin-bottom: 0; }通过设置display: flex;和align-items: center;,文字将保持在垂直居中的位置,而不会发生上浮。