特斯拉官網作為一家高科技電動汽車生產公司的官方網站,自然也有著相應的前端技術的支持。其中,CSS的運用也不容忽視。
body { font-family: 'Open Sans', sans-serif; font-size: 16px; line-height: 1.6; background-color: #f8f8f8; } header { display: flex; justify-content: space-between; align-items: center; padding: 20px; background-color: #131921; color: white; } nav { display: flex; justify-content: space-between; align-items: center; margin: 0 50px; } nav ul { display: flex; justify-content: space-between; align-items: center; list-style: none; } nav ul li { margin: 0 20px; } nav ul li a { text-decoration: none; color: white; } .hero { height: 700px; background-position: center; background-repeat: no-repeat; background-size: cover; display: flex; justify-content: center; align-items: center; flex-direction: column; } .hero h1 { font-size: 5rem; font-weight: bold; color: white; text-align: center; margin-bottom: 20px; } .hero p { font-size: 2.5rem; color: white; text-align: center; margin-bottom: 40px; } .learn-more { background-color: #f8f8f8; padding: 100px; display: flex; justify-content: center; align-items: center; flex-direction: column; } .learn-more h2 { font-size: 3rem; font-weight: bold; text-align: center; margin-bottom: 20px; } .learn-more p { font-size: 1.5rem; text-align: center; margin-bottom: 40px; } .button { border: none; background-color: #131921; color: white; font-size: 1.2rem; padding: 10px 20px; border-radius: 4px; cursor: pointer; } .button:hover { background-color: white; color: #131921; }
可以看到,特斯拉官網的CSS代碼中充分運用了flex布局,以及background屬性進行背景圖的定位,同時也使用了顏色、字體、邊框等屬性調整頁面樣式。此外,特斯拉官網還使用hover偽類實現了鼠標懸停效果。這些CSS技巧的運用,優化了頁面的視覺效果和用戶體驗。