我對web編碼世界非常陌生,需要一些幫助。我正在為當地的運動隊做一個網頁,因為他們的網頁看起來不太好,Wordpress也不是很友好,所以我決定自己編碼可能更容易。
我不能讓我的導航欄,主要內容和頁腳進入頁面。我想輸入導航欄,主要內容和頁腳,只有80%的寬度,所以你會看到一些背景將是體育隊球員的照片)
#footerWrapper { max-width: 80%;
max-height: 5%;
margin-bottom: 20px;
line-height: 30px;
font-size: 0.9em;
border: 0 solid #ddd;
border-bottom-color: #3F8444;
border-width: 1px 0;}
/*Positions and Margins*/
.image {
position: absolute;
top:100px;
left:100px;
}
.image-1 {
position: absolute;
top:20px;
right: 100px;
}
header{
text-align: center;
margin-top: 100px;
margin-bottom: 100px;
}
main{ width: 80%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;}
footer{
position: static;
left: 0;
bottom: 0;
width: 80%;
height: 5%;}
p {margin-left: 5px;
margin-right: 5px;}
/*Navigation*/
ul { display: flex;
flex-direction: row;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #04AA6D;
width: 80%;
}
/*li {float: left;}*/
li a, .dropdown li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {background-color: #111;}
li.dropdown {
display: inline-block;}
.dropdown-content {
display:none;
position: absolute;
background-color: #04AA6D;
color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0,.2);
z-index: 1;
}
.dropdown-content a
{
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #111;color: white;}
.dropdown:hover .dropdown-content
{
display: block;
}
</style>
</div>
</head>
<body>
<header>
<div class="image" id="Sports Team logo">
<img src="Sport Teams logo">
</div>
<div class="image-1" id="Club logo">
<img src="Club logo" width="246" height="237">
</div>
<h1>Sports Team</h1>
</header>
<nav>
<ul>
<li><a href="Sports Team url link">Home</a></li>
<li class="dropdown">
<a class="dropbtn">Club Info</a>
<div class="dropdown-content">
<a href="Sports Team url link">About Us</a>
<a href="Sports Team url link">Committee</a>
<a href="Sports Team url link">Contact Us</a>
<a href="Sports Team url link">Game Rules</a>
<a href="Sports Team url link">Uniforms</a>
<a href="Sports Team url link">Fair Play</a>
<a href="Sports Team url link">Terms and Conditions</a>
</div>
<li class="dropdown">
<a class="dropbtn">Winter Season 2023</a>
<div class="dropdown-content">
<a href="Sports Team url link">Training Information</a>
<a href="Sports Team url link">Game Details</a>
<a href="Sports Team url link">Registration</a>
<a href="Sports Team url link">Season Info Pack</a>
<a href="Sports Team url link">Handbook</a>
<a href="Sports Team url link">Privacy Policy</a>
</div>
<li class="dropdown">
<a class="dropbtn">Summer Season 2023</a>
<div class="dropdown-content">
<a href="Sports Team url link">Training Information</a>
<a href="Sports Team url link">Game Details</a>
<a href="Sports Team url link">Registration</a>
<a href="Sports Team url link">Season Info Pack</a>
</div>
<li><a href="Sports Team url link">Umpire Information</a>
</ul>
</nav>
<Div></Div>
<main>
<div class="main">
<h2>Contact Us</h2>
<p>Sports Team email</p>
</main>
</body>
</html>
我嘗試了很多不同的CSS樣式,浮動、邊距、伸縮、網格等等
干得好!這是一個很好的開始。看起來你已經習慣了。我強烈建議研究像tailwindcss或bootstrap這樣的框架。
這些框架有助于處理大部分繁瑣的微調。你的文件中不會有太多的CSS,你可以添加類名。類似于class = & quotm-auto d-flex文本中心& quot會取代你所有的css。
這些框架是基于類的,這是我的下一個建議。你應該對所有事情都使用類或id。這就是你能夠寫出更干凈、更有條理的代碼的方法。你應該有:
<style>
.nav_bar { }
</style>
<ul class="nav_bar">
...
</ul>
如果你的網站上需要不止一個ul,但是它們需要不同的顏色,或者其他的不應該居中,該怎么辦?
以下是如何使現有代碼居中的方法: 導航欄和main上的邊距應該是自動的,而不是0。
main { width: 80%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
margin: auto;
}
ul { display: flex;
flex-direction: row;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #04AA6D;
width: 80%;
}