初次接觸HTML+CSS+JS遇到的問題
阿新 • • 發佈:2019-02-08
自從在SAE上建立了個應用後,只是用來實現網頁控制LCD顯示動態網頁控制lcd顯示太浪費也太簡陋了,自然更多的功能會在後面實現,但實在太low了(連主頁都沒有!),為此從未接觸過web前端的我開始摸索著學習web前端。
建立個簡單的主頁
從網上不明所以的扒了個HTML下來(這時候不知道有css這東西,具體來說是不知道它和html還有js三者的關係,後來瞭解到形象的比喻是:
html是骨架,CSS是肌肉,JS肌膚毛髮等等
由於這個html檔案中css是內建的,所以不用考慮css檔案的位置問題,具體後面詳細說。
簡單的修改了些我知道的引數後,頁面大概是這個樣子
這是一個簡單的圖片輪播
下面是原始碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首頁</title>
<style type="text/css">
/* Slider wrapper*/
.css-slider-wrapper {
display: block;
background: #FFF;
overflow: hidden;
position: absolute;
left: 0;
right : 0;
top: 0;
bottom: 0;
}
/* Slider */
.slider {
width: 100%;
height: 100%;
background: red;
position: absolute;
left: 0;
top: 0;
opacity: 1;
z-index: 0;
display: flex;
display: -webkit-flex;
display: -ms-flexbox;
flex-direction: row;
flex-wrap: wrap;
-webkit-flex-align: center;
-webkit-align-items: center;
align-items: center;
justify-content: center;
align-content: center;
-webkit-transition: -webkit-transform 1600ms;
transition: -webkit-transform 1600ms, transform 1600ms;
-webkit-transform: scale(1);
transform: scale(1);
}
/* each slide background color */
.slide1 {
background: #000000;
left: 0;
}
.slide2 {
background: #487d8d;
left: 100%
}
.slide3 {
background: #7d7d8d;
left: 200%
}
.slide4 {
background: #9f7d8d;
left: 300%;
}
.slider > div {
text-align: center;
}
/* Slider inner content */
.slider h2 {
color: #FFF;
font-weight: 900;
text-transform: uppercase;
font-size: 95px;
line-height: 120%;
opacity: 0;
-webkit-transform: translateX(500px);
transform: translateX(500px);
}
.slider .button {
color: #FFF;
padding: 5px 50px;
background: rgba(255,255,255,0.3);
text-decoration: none;
opacity: 0;
font-size: 15px;
line-height: 30px;
display: inline-block;
-webkit-transform: translateX(-500px);
transform: translateX(-500px);
}
.slider h2, .slider .button {
-webkit-transition: opacity 800ms, -webkit-transform 800ms;
transition: transform 800ms, opacity 800ms;
-webkit-transition-delay: 1s; /* Safari */
transition-delay: 1s;
}
/* Next and previous button */
.control {
position: absolute;
top: 50%;
width: 50px;
height: 50px;
margin-top: -25px;
z-index: 55;
}
.control label {
z-index: 0;
margin: 10px;
display: none;
text-align: center;
line-height: 50px;
font-size: 50px;
color: #FFF;
cursor: pointer;
opacity: 0.2;
}
.control label:hover {
opacity: 0.5;
}
.next {
right: 1%;
}
.previous {
left: 1%;
}
/* Slider pagination */
.slider-pagination {
position: absolute;
bottom: 20px;
width: 100%;
left: 0;
text-align: center;
z-index: 1000;
}
.slider-pagination label {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
background: rgba(255,255,255,0.2);
margin: 0 2px;
border: solid 1px rgba(255,255,255,0.4);
cursor: pointer;
}
/* Slider control active css */
.slide-radio1:checked ~ .next .numb2,
.slide-radio2:checked ~ .next .numb3,
.slide-radio3:checked ~ .next .numb4,
.slide-radio2:checked ~ .previous .numb1,
.slide-radio3:checked ~ .previous .numb2,
.slide-radio4:checked ~ .previous .numb3 {
display: block;
z-index: 1
}
/* Slider pagination active css */
.slide-radio1:checked ~ .slider-pagination .page1,
.slide-radio2:checked ~ .slider-pagination .page2,
.slide-radio3:checked ~ .slider-pagination .page3,
.slide-radio4:checked ~ .slider-pagination .page4 {
background: rgba(255,255,255,1)
}
/* css for sliding effect when you click on control button*/
.slide-radio1:checked ~ .slider {
-webkit-transform: translateX(0%);
transform: translateX(0%);
}
.slide-radio2:checked ~ .slider {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
}
.slide-radio3:checked ~ .slider {
-webkit-transform: translateX(-200%);
transform: translateX(-200%);
}
.slide-radio4:checked ~ .slider {
-webkit-transform: translateX(-300%);
transform: translateX(-300%);
}
.slide-radio1:checked ~ .slide1 h2,
.slide-radio2:checked ~ .slide2 h2,
.slide-radio3:checked ~ .slide3 h2,
.slide-radio4:checked ~ .slide4 h2,
.slide-radio1:checked ~ .slide1 .button,
.slide-radio2:checked ~ .slide2 .button,
.slide-radio3:checked ~ .slide3 .button,
.slide-radio4:checked ~ .slide4 .button {
-webkit-transform: translateX(0);
transform: translateX(0);
opacity: 1
}
@media only screen and (max-width: 767px) {
.slider h2 {
font-size: 20px;
}
.slider > div {
padding: 0 2%
}
.control label {
font-size: 35px;
}
.slider .button {
padding: 0 30px;
}
}
</style>
</head>
<body>
<div class="css-slider-wrapper">
<input type="radio" name="slider" class="slide-radio1" checked id="slider_1">
<input type="radio" name="slider" class="slide-radio2" id="slider_2">
<input type="radio" name="slider" class="slide-radio3" id="slider_3">
<input type="radio" name="slider" class="slide-radio4" id="slider_4">
<div class="slider-pagination">
<label for="slider_1" class="page1"></label>
<label for="slider_2" class="page2"></label>
<label for="slider_3" class="page3"></label>
<label for="slider_4" class="page4"></label>
</div>
<div class="next control">
<label for="slider_1" class="numb1"><i class="fa fa-arrow-circle-right"></i></label>
<label for="slider_2" class="numb2"><i class="fa fa-arrow-circle-right"></i></label>
<label for="slider_3" class="numb3"><i class="fa fa-arrow-circle-right"></i></label>
<label for="slider_4" class="numb4"><i class="fa fa-arrow-circle-right"></i></label>
</div>
<div class="previous control">
<label for="slider_1" class="numb1"><i class="fa fa-arrow-circle-left"></i></label>
<label for="slider_2" class="numb2"><i class="fa fa-arrow-circle-left"></i></label>
<label for="slider_3" class="numb3"><i class="fa fa-arrow-circle-left"></i></label>
<label for="slider_4" class="numb4"><i class="fa fa-arrow-circle-left"></i></label>
</div>
<div class="slider slide1">
<div>
<h2>The experiment content</h2>
<a href="textInput" class="button">實驗內容</a>
</div>
</div>
<div class="slider slide2">
<div>
<h2>GROUP MEMBERS</h2>
<a href="members" class="button">組員詳情</a>
</div>
</div>
<div class="slider slide3">
<div>
<h2><img src="http://17148203126-pic.stor.sinaapp.com/qrcode.png" width=180 height=180/><br></h2>
<h2>JOIN US</h2>
<a href="#" class="button">加入我們</a>
</div>
</div>
<div class="slider slide4">
<div>
<h2>MORE</h2>
<a href="#" class="button">更多功能正在開發中...</a>
</div>
</div>
</div>
</body>
</html>
寫個註冊登入介面
主頁有了,功能頁有了,主頁上按鈕跳轉功能頁有了,下面打算搞個註冊登入介面,註冊了的使用者登入成功後才可前往相應功能頁實現相關功能,這個貌似比較難,還要連線資料庫。(而後來事實證明真是有夠折騰,也才讓我更深入的體會和了解了CSS和JS)
接下來問題就來了,當我svn commit到sae上後,開啟是這個樣子的:
這….這就比較尷尬了…
也是在這個時候我開始明白了CSS存在的意義,sae上應該是沒呼叫css,於是我看原始碼的css的地址呼叫:
1是絕對地址呼叫,2是相對地址呼叫
可是我其他的檔案像css,js什麼的都是按一樣的位置上傳的啊,按道理不會有問題啊(相對地址並沒有改變),後來看網上說用絕對地址,於是把css和js檔案上傳到sae的storage上再用絕對地址呼叫。可是,免費的storage每天訪問次數是有限的,這樣沒訪問一次就得呼叫一次?於是乎,我看到了sae上之前其他網頁創的static資料夾,裡面是存了一個css檔案的,後來才知道要把css、js包括圖片這些都存放在static資料夾下。
下面是程式碼:
html
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Sign-Up/Login Form</title>
<link href='http://fonts.googleapis.com/css?family=Titillium+Web:400,300,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel="stylesheet" href="static/sty.css">
</head>
<body>
<form action="signup.php" method="post">
<div class="form">
<ul class="tab-group">
<li class="tab active"><a href="#signup">註冊/Sign Up</a></li>
<li class="tab"><a href="#login">登入/Log In</a></li>
</ul>
<div class="tab-content">
<div id="signup">
<h1>免費註冊/Sign Up for Free</h1>
<form action="/" method="post">
<div class="top-row">
<div class="field-wrap">
<label>
名/First Name<span class="req">*</span>
</label>
<input type="text" name="firstName" required autocomplete="off" />
</div>
<div class="field-wrap">
<label>
姓/Last Name<span class="req">*</span>
</label>
<input type="text" name="lastName" required autocomplete="off"/>
</div>
</div>
<div class="field-wrap">
<label>
郵箱/Email Address<span class="req">*</span>
</label>
<input type="email" name="email" required autocomplete="off"/>
</div>
<div class="field-wrap">
<label>
設定密碼/Set A Password<span class="req">*</span>
</label>
<input type="password" name="password" required autocomplete="off"/>
</div>
<button type="submit" name="submit" class="button button-block"/>註冊/Get Started</button>
</form>
</div>
<div id="login">
<h1>歡迎回來!/Welcome Back!</h1>
<form action="/" method="post">
<div class="field-wrap">
<label>
郵箱/Email Address<span class="req">*</span>
</label>
<input type="email" name="loginEmail" required autocomplete="off"/>
</div>
<div class="field-wrap">
<label>
密碼/Password<span class="req">*</span>
</label>
<input type="password" name="loginPassword" "required autocomplete="off"/>
</div>
<p class="forgot"><a href="#">忘記密碼?/Forgot Password?</a></p>
<button class="button button-block" name="loginButton"/>登入/Log In</button>
</form>
</div>
</div><!-- tab-content -->
</div> <!-- /form -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="static/js/index.js"></script>
</body>
</html>
CSS:
*, *:before, *:after {
box-sizing: border-box;
}
html {
overflow-y: scroll;
}
body {
background: #c1bdba;
font-family: 'Titillium Web', sans-serif;
}
a {
text-decoration: none;
color: #1ab188;
-webkit-transition: .5s ease;
transition: .5s ease;
}
a:hover {
color: #179b77;
}
.form {
background: rgba(19, 35, 47, 0.9);
padding: 40px;
max-width: 600px;
margin: 40px auto;
border-radius: 4px;
box-shadow: 0 4px 10px 4px rgba(19, 35, 47, 0.3);
}
.tab-group {
list-style: none;
padding: 0;
margin: 0 0 40px 0;
}
.tab-group:after {
content: "";
display: table;
clear: both;
}
.tab-group li a {
display: block;
text-decoration: none;
padding: 15px;
background: rgba(160, 179, 176, 0.25);
color: #a0b3b0;
font-size: 20px;
float: left;
width: 50%;
text-align: center;
cursor: pointer;
-webkit-transition: .5s ease;
transition: .5s ease;
}
.tab-group li a:hover {
background: #179b77;
color: #ffffff;
}
.tab-group .active a {
background: #1ab188;
color: #ffffff;
}
.tab-content > div<