html用標籤來實現一個有趣的文字冒險網頁
阿新 • • 發佈:2018-12-21
原博來自http://ife.baidu.com/note/detail/id/168,效果十分有趣
然後在他的基礎上我做了一些實踐效果
實現原理十分簡單,主要用的就是<detail>標籤
<details>
<summary>概要</summary>
<p>內容內容內容內容內容內容內容</p>
</details>
在Chrome下執行就可以出現一個可展開的摺疊標籤
接著就是實現一個可選擇分支的文字表現,需要有選擇枝,並且要有提示選擇的文字,最後在選擇之後,新出現的選擇和文字,要能夠覆蓋原有的選擇和文字框。
然後有了這個
<div style="height: 100px;">
<details style="
height: 100px;
background: #f9f;
">
<summary style="
float: left;
width: 100%;
height: 40px;
background: #9f9;
">概要</summary>
<div style="
float: left;
width: 100%;
height : 100px;
margin-top: -40px;
background: #99f;
">展開後內容</div>
</details>
<div style="margin-top: -60px;">展開前內容區文字</div>
</div>
這裡使用margin-top:-40px用來將內容拉上去
並且定位使用float來防止文字重疊
overflow:hidden來防止內容被擠下去
下面是一個文字冒險的實踐內容
<!DOCTYPE html>
<html lang=" en">
<head>
<meta charset="UTF-8">
<title>文字冒險</title>
<style>
.box {
width: 100%;
height: 200px;
overflow: hidden;
}
.box details {
margin-top: -200px;
height: 200px;
background: #f9f;
}
.box details:first-child {
margin-top: 0;
}
.box summary {
float: left;
width: 50%;
height: 40px;
background: #9f9;
line-height: 40px;
cursor: pointer;
}
.box details > div {
float: left;
width: 100%;
height: 200px;
margin-top: -40px;
background: #99f;
}
.box details + div {
margin-top: -160px;
padding: 0.5em;
}
.box p {
margin: 0 auto 0.5em;
text-indent: 2em;
}
</style>
</head>
<body>
<div class="box">
<details>
<summary>再睡一會,睡個回籠覺</summary>
<div>
<details>
<summary>不理她,繼續睡覺</summary>
<div>
<p>日復一日,每次六花喊你的時候你都沒有搭理她,後來你們慢慢就疏遠了</p>
<p>你孤獨終老了</p>
</div>
</details>
<details>
<summary>起床,然後和六花一起去上學</summary>
<div>
<p>六花問起了班上轉校生新條茜的事,她很善良,打算幫新同學融入班級</p>
</div>
</details>
<div>可是你才躺下你就聽到你的青梅竹馬六花在樓下喊你上學,你想了想</div>
</div>
</details>
<details>
<summary>起床去學校</summary>
<div>
<details>
<summary>上去搭話</summary>
<div>
<p>好吧我編不下去了,結局你自己想吧</p>
</div>
</details>
<details>
<summary>默默跟在新條茜的後面</summary>
<div>
<p>日復一日,你每天都跟新條茜的後面上學,卻從來沒有勇氣上去和她搭話</p>
<p>你孤獨終老了</p>>
</div>
</details>
<div>
<p>路上你看到班上的轉校生新條茜</p>
<p>茜的學習很好,長的也很可愛,不過剛來學校還沒麼朋友,此時正一個人走在你的前面</p>
</div>
</div>
</details>
<div>
<p>清晨,陽光透光窗簾照入臥室,你揉了揉眼睛,伸了個懶腰,你決定:</p>
</div>
</div>
</body>
</html>