簽出這個代碼筆。codepen 專案 調整視窗大小,您將在影像下方看到額外的空間。我不知道如何擺脫它。影像在表格中。如果你不介意,就如何更好地做我所做的事情提出建議。我正在做 freeCodeCamp 專案。“看起來你的帖子主要是代碼;請添加更多細節。” 堆疊溢位 這里是 html。
@import 'https://fonts.googleapis.com/css?family=Lato:400,700';
html {
height: 100%;
margin: 0;
}
body {
height: 100%;
top: 10px;
padding: 0;
margin: 0 30px 0 30px;
background-color: rgb(30, 60, 90, 0.1);
font-family: 'Lato', sans-serif;
}
header {
position: sticky;
margin: 10px auto;
width: 100%;
height: fit-content;
}
#navbar {
width: 100%;
height: 150px;
display: flex;
flex-direction: row;
justify-content: space-between;
transition: all 1s;
}
@media (max-width: 750px) {
#navbar {
transform: scale(0.9);
flex-direction: column;
justify-content: space-evenly;
text-align: center;
}
}
#header-img {
height: 80px;
align-self: center;
}
#company {
font-size: 36pt;
font-style: bold;
color: rgb(30, 60, 90);
}
#nav-bar {
align-self: center;
margin: 0;
}
table {
align-self: center;
width: fit-content;
height: 150px;
}
@media (max-width: 480px) {
#logo-table {
transition: all 1s;
transform: scale(0.8);
justify-self: space-around;
margin: auto;
}
}
@media (max-width: 320px) {
#logo-table {
transition: all 1s;
transform: scale(0.6);
justify-self: center;
margin: auto;
}
}
ul {
display: flex;
justify-content: space-around;
list-style: none;
}
@media (max-width: 480px) {
#nav-bar {
width: 100%;
}
ul {
flex-direction: column;
justify-content: space-between;
}
}
li {
width: max-content;
transition: all 0.3s ease-in-out;
}
li:hover {
transform: scale(1.5);
}
@media (max-width: 480px) {
li {
flex-direction: column;
align-self: center;
justify-self: space-around;
padding-bottom: 15px;
}
}
a {
color: black;
text-decoration: none;
margin: 20px;
}
/* End of nav bar decorations*/
main {
display: block;
top: 0;
margin: 0;
}
#top {
margin: 20px auto;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
h1 {
text-align: center;
}
#email {
display: flex;
width: 200px;
margin: auto;
padding: 8px;
}
#submit {
display: block;
margin: 15px auto;
padding: 5px;
width: 50%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Product landing page</title>
</head>
<body>
<header>
<div id="navbar">
<table id="logo-table">
<tr>
<th><img src="https://festive-hypatia-ab69c7.netlify.app/dumbbell.png" alt="logo" id="header-img"></th>
<th>
<p id="company"><strong>Dumbbell</strong> </p>
</th>
</tr>
</table>
<nav id='nav-bar'>
<ul>
<li><a href=""> Features</a></li>
<li><a href=""> How it works</a></li>
<li><a href=""> Pricing</a></li>
</ul>
</nav>
</div>
</header>
<main>
<section id="top">
<h1>Dumbbell everyone</h1>
<form action="submit" id="form">
<input type="email" placeholder="Enter your email address" id="email">
<input type="submit" value="GET STARTED" id="submit">
</form>
</section>
<section id="features">
</section>
<section id="vid">
<iframe src="" frameborder="0" id="video"></iframe>
</section>
<section id="pricing">
<div></div>
<div></div>
<div></div>
</section>
</main>
<footer></footer>
</body>
</html>
uj5u.com熱心網友回復:
表格幾乎沒有回應,也不像使用 div 那樣容易操作。另一種解決方案是使用div's 代替。
我繼續用 div 替換了表格。我洗掉了p.
然后我加display: flex;了#logo-table。我還洗掉了您在某些導航組件上設定的一些邊距以減少間距。查看我在下面所做的更改/* added CSS */
@import 'https://fonts.googleapis.com/css?family=Lato:400,700';
html {
height: 100%;
margin: 0;
}
body {
height: 100%;
top: 10px;
padding: 0;
margin: 0 30px 0 30px;
background-color: rgb(30, 60, 90, 0.1);
font-family: 'Lato', sans-serif;
}
header {
position: sticky;
width: 100%;
height: fit-content;
}
#navbar {
width: 100%;
height: 150px;
display: flex;
flex-direction: row;
justify-content: space-between;
transition: all 1s;
}
@media (max-width: 750px) {
#navbar {
transform: scale(0.9);
flex-direction: column;
justify-content: space-evenly;
text-align: center;
}
}
#header-img {
height: 80px;
align-self: center;
}
#company {
font-size: 36pt;
font-style: bold;
color: rgb(30, 60, 90);
}
#nav-bar {
align-self: center;
margin: 0;
}
table {
align-self: center;
width: fit-content;
height: 150px;
}
@media (max-width: 480px) {
#logo-table {
transition: all 1s;
transform: scale(0.8);
justify-self: space-around;
margin: auto;
}
}
@media (max-width: 320px) {
#logo-table {
transition: all 1s;
transform: scale(0.6);
justify-self: center;
margin: auto;
}
}
ul {
display: flex;
justify-content: space-around;
list-style: none;
}
@media (max-width: 480px) {
#nav-bar {
width: 100%;
}
ul {
flex-direction: column;
justify-content: space-between;
}
}
li {
width: max-content;
transition: all 0.3s ease-in-out;
}
li:hover {
transform: scale(1.5);
}
@media (max-width: 480px) {
li {
flex-direction: column;
align-self: center;
justify-self: space-around;
padding-bottom: 15px;
}
}
a {
color: black;
text-decoration: none;
margin: 20px;
}
/* End of nav bar decorations*/
main {
display: block;
top: 0;
margin: 0;
}
#top {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
h1 {
text-align: center;
}
#email {
display: flex;
width: 200px;
margin: auto;
padding: 8px;
}
#submit {
display: block;
margin: 15px auto;
padding: 5px;
width: 50%;
}
/* added CSS */
#logo-table {
display: flex;
justify-content: center;
align-items: center;
}
p {
margin: 0 !important;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Product landing page</title>
</head>
<body>
<header>
<div id="navbar">
<div id="logo-table">
<img src="https://festive-hypatia-ab69c7.netlify.app/dumbbell.png" alt="logo" id="header-img">
<p id="company"><strong>Dumbbell</strong> </p>
</div>
<nav id='nav-bar'>
<ul>
<li><a href=""> Features</a></li>
<li><a href=""> How it works</a></li>
<li><a href=""> Pricing</a></li>
</ul>
</nav>
</div>
</header>
<main>
<section id="top">
<h1>Dumbbell everyone</h1>
<form action="submit" id="form">
<input type="email" placeholder="Enter your email address" id="email">
<input type="submit" value="GET STARTED" id="submit">
</form>
</section>
<section id="features">
</section>
<section id="vid">
<iframe src="" frameborder="0" id="video"></iframe>
</section>
<section id="pricing">
<div></div>
<div></div>
<div></div>
</section>
</main>
<footer></footer>
</body>
</html>
uj5u.com熱心網友回復:
我不清楚您在示例中的哪個位置看到了這一點,但我懷疑您指的是基線下方的空間——影像inline-block默認顯示,因此它們位于基線上(即標準小寫字母的底部)。擺脫它的最簡單方法是將其設定為display: block.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/425599.html
下一篇:Div的最高位置不為0%
