|
導讀網頁的本質就是超級文本標記語言,通過結合使用其他的Web技術(如:腳本語言、公共網關接口、組件等),可以創造出功能強大的網頁。因而,超級文本標記語言是萬維網(Web)編程的基礎,也就是說萬維網是建立... 網頁的本質就是超級文本標記語言,通過結合使用其他的Web技術(如:腳本語言、公共網關接口、組件等),可以創造出功能強大的網頁。因而,超級文本標記語言是萬維網(Web)編程的基礎,也就是說萬維網是建立在超文本基礎之上的。超級文本標記語言之所以稱為超文本標記語言,是因為文本中包含了所謂“超級鏈接”點。 本篇文章給大家帶來的內容是關于如何使用純CSS實現iPhone 價格信息圖(附源碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。效果預覽
源代碼下載https://github.com/comehope/front-end-daily-challenges 代碼解讀定義 dom,容器中包含 3 個元素, <div class="wall">
<h1>iPhone Price Comparison</h1>
<div class="back">
<ul>
<li class="xs-max"><span>$1099 ~ $1449</span></li>
<li class="xs"><span>$999 ~ $1349</span></li>
<li class="xr"><span>$749 ~ $899</span></li>
<li class="x"><span>$999 ~ $1149</span></li>
</ul>
</div>
<div class="side">
<ul>
<li class="xs-max">iPhone XS Max</li>
<li class="xs">iPhone XS</li>
<li class="xr">iPhone XR</li>
<li class="x">iPhone X</li>
</ul>
</div>
</div>居中顯示: body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(lightblue, skyblue);
}定義容器尺寸: .wall {
width: 60em;
height: 40em;
border: 1em solid rgba(255, 255, 255, 0.5);
border-radius: 2em;
font-size: 10px;
}用 grid 布局,把容器分成 2 部分,左側80%為背景墻,右側20%為側邊墻: .wall {
display: grid;
grid-template-columns: 0 4fr 1fr;
}分別設置背景墻和側邊墻的背景色: .back {
background: linear-gradient(
to right,
#555,
#ddd
);
}
.side {
background:
radial-gradient(
at 0% 50%,
/* tomato 25%,
yellow 90% */
rgba(0, 0, 0, 0.2) 25%,
rgba(0, 0, 0, 0) 90%
),
linear-gradient(
to right,
#ddd,
#ccc
)
}用 flex 布局設置對齊方式,列表垂直居中: .back,
.side {
display: flex;
align-items: center;
}
.back {
justify-content: flex-end;
}
ul {
list-style-type: none;
padding: 0;
}設置標題樣式: h1 {
position: relative;
width: 20em;
margin: 1em;
color: white;
font-family: sans-serif;
}設置列表項的高度和顏色: .back ul {
width: 75%;
}
.side ul {
width: 100%;
}
ul li {
height: 5em;
background-color: var(--c);
}
ul li:nth-child(1) {
--c: tomato;
}
ul li:nth-child(2) {
--c: coral;
}
ul li:nth-child(3) {
--c: lightsalmon;
}
ul li:nth-child(4) {
--c: deepskyblue;
}至此,整體布局完成。接下來設置左側背景墻的橫條樣式。 ul {
display: flex;
flex-direction: column;
}
.back ul {
align-items: flex-end;
}
ul {
--max-price: 1449;
}
ul li.xs-max {
--high-price: 1449;
}
ul li.xs {
--high-price: 1349;
}
ul li.xr {
--high-price: 899;
}
ul li.x {
--high-price: 1149;
}
.back ul li {
width: calc(var(--high-price) / var(--max-price) * 100%);
}在橫條中區分起售價 ul li.xs-max {
--low-price: 1099;
--c2: orangered;
}
ul li.xs {
--low-price: 999;
--c2: tomato;
}
ul li.xr {
--low-price: 749;
--c2: coral;
}
ul li.x {
--low-price: 999;
--c2: dodgerblue;
}
.back ul li {
--percent: calc(var(--low-price) / var(--high-price) * 100%);
background: linear-gradient(
to left,
var(--c) var(--percent),
var(--c2) var(--percent)
);
}在橫線的頂端畫出一個向左的三角形: .back ul li {
position: relative;
}
.back ul li::before {
content: '';
position: absolute;
width: 0;
height: 0;
transform: translateX(-3em);
border-right: 3em solid var(--c2);
border-top: 2.5em solid transparent;
border-bottom: 2.5em solid transparent;
}設置價格文字樣式: .back ul li span {
position: absolute;
width: 95%;
text-align: right;
color: white;
font-size: 1.25em;
line-height: 4em;
font-family: sans-serif;
}為各橫條增加陰影,增強立體感: ul li.xs-max {
z-index: 5;
}
ul li.xs {
z-index: 4;
}
ul li.xr {
z-index: 3;
}
ul li.x {
z-index: 2;
}
.back ul li {
filter: drop-shadow(0 1em 1em rgba(0, 0, 0, 0.3));
}至此,背景墻的橫條完成。接下來設置側邊墻的樣式。 .side {
perspective: 1000px;
}
.side ul {
transform-origin: left;
transform: rotateY(-75deg) scaleX(4);
}設置側邊墻的文字樣式: .wall {
overflow: hidden;
}
.side ul li {
padding-right: 30%;
text-align: right;
color: white;
font-family: sans-serif;
line-height: 5em;
}至此,靜態視覺效果完成。最后增加入場動畫效果: ul li {
animation: show 1s linear forwards;
transform-origin: right;
transform: scaleX(0);
}
@keyframes show {
to {
transform: scaleX(1);
}
}
.back ul li {
animation-delay: 1s;
}大功告成! 以上就是如何使用純CSS實現iPhone 價格信息圖(附源碼)的詳細內容,更多請關注php中文網其它相關文章! 網站建設是一個廣義的術語,涵蓋了許多不同的技能和學科中所使用的生產和維護的網站。 |
溫馨提示:喜歡本站的話,請收藏一下本站!