css3製作IOS風格的快顯功能表效果

來源:互聯網
上載者:User

首先我們來編寫基本的HTML結構

<div class="popover">
  <ul>
    <li class="active"><a href="index.html">Bookmarks</a></li>
    <li class="active"><a href="index.html">Passwords</a></li>
    <li><a href="index.html">Preferences</a></li>
    <li><a href="index.html">History</a></li>
  </ul>
</div>

給LI元素添加一個active類,標識滑鼠響應的樣式,給大的div添加一個popover類,便於我們尋找到這個元素。
接下來我們來看看CSS樣式是怎樣的。
首先我們給div添加一點效果

.popover {
  position: relative;
  width: 200px;
  padding: 5px;
  background: #606060;
  border: 1px solid black;
  border-radius: 11px;
  background-image: -webkit-linear-gradient(top, #606060, #4a4a4a);
  background-image: -moz-linear-gradient(top, #606060, #4a4a4a);
  background-image: -o-linear-gradient(top, #606060, #4a4a4a);
  background-image: linear-gradient(to bottom, #606060, #4a4a4a);
  -webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.2), inset 1px 0 rgba(255, 255, 255, 0.08), inset -1px 0 rgba(255, 255, 255, 0.08), 0 2px 8px rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.2), inset 1px 0 rgba(255, 255, 255, 0.08), inset -1px 0 rgba(255, 255, 255, 0.08), 0 2px 8px rgba(0, 0, 0, 0.5);
}

上面的代碼中,我們給div設定一個內陰影和漸層背景,這都要歸功於CSS3先進的屬性,不然這些效果就只能使用背景圖片

然後我們定義UL的樣式

.popover ul {
  overflow: hidden;
  background: white;
  border: 1px solid black;
  border-radius: 7px;
  -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(255, 255, 255, 0.1), 0 1px rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(255, 255, 255, 0.1), 0 1px rgba(255, 255, 255, 0.1);
}

這樣看起來,div和ul之間就有了一點間隙,從視覺上看就是有了邊框
然後我們添加那個三角形效果

.popover:before, .popover:after, .popover ul:before {
  content: '';
  display: block;
  position: absolute;
  left: 22px;
  width: 0;
  height: 0;
  border: 7px outset transparent;
}
.popover:before {
  top: -14px;
  border-bottom: 7px solid black;
}
.popover:after {
  top: -13px;
  border-bottom: 7px solid #888;
}
.popover ul:before {
  z-index: 2;
  top: -12px;
  border-bottom: 8px solid #666;
}

設定LI樣式

.popover li {
  display: block;
}
.popover li + li {
  border-top: 1px solid #eee;
}
.popover li:first-child a {
  border-radius: 7px 7px 0 0;
}
.popover li:last-child a {
  border-radius: 0 0 7px 7px;
}

定義A連結元素滑鼠響應樣式

.popover a {
  display: block;
  position: relative;
  line-height: 44px;
  padding: 0 15px 0 48px;
  font-size: 16px;
  font-weight: bold;
  color: black;
  text-decoration: none;
}
.popover a:hover {
  background: white;
  -webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}


好了以上就是這個效果的核心代碼,有一些代碼在這裡沒有列出來,比如清空瀏覽器預設給元素的樣式值等。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.