簡體   English   中英

樣式化HTML以模仿Facebook,例如下拉菜單

[英]Styling HTML to mimic Facebook like dropdown menu

我需要一些建議和幫助。 我不是一個css家伙,但是我想學習。

我正在嘗試為下拉菜單調整一些CSS。

我有以下問題:

  • 下拉按鈕應與圖像一樣大,僅保留下拉三角形的區域。
  • 下拉三角形應在中間垂直對齊並在水平方向居中。
  • 下拉選項應與右邊框對齊,並向左向內打開,而不是相反。

有人可以幫助我進行調整嗎? 我想學習這些技術,但是對錯誤的嘗試是如此漫長。

我的代碼如下:

<html>
<head>
<head>
<body>
    <style>
        body {
            background-color: white;
            font: normal 11px Tahoma,Verdana,Arial,Sans-Serif;
            color: #222;
            height: 380px;
        }

        .dropdown {
            display: block;
            display: inline-block;
            margin: 0px 3px;
            position: relative;
        }

        /* ===[ For demonstration ]=== */

        .dropdown { margin-top: 25px }

        /* ===[ End demonstration ]=== */

        .dropdown .dropdown_button {
            cursor: pointer;
            width: auto;
            display: inline-block;
            padding: 0px 0px;
            border: 1px solid silver;
            -webkit-border-radius: 0px;
            -moz-border-radius: 0px;
            border-radius: 2px;
            font-weight: bold;
            color: #717780;
            line-height: 16px;
            text-decoration: none !important;
            background: white;
        }

        .dropdown input[type="checkbox"]:checked +  .dropdown_button {
            border: 1px solid #3B5998;
            color: white;
            background: silver;
            -moz-border-radius-topleft: 2px;
            -moz-border-radius-topright: 2px;
            -moz-border-radius-bottomright: 0px;
            -moz-border-radius-bottomleft: 0px;
            -webkit-border-radius: 2px 2px 0px 0px;
            border-radius: 2px 2px 0px 0px;
            border-bottom-color: silver;
        }

        .dropdown input[type="checkbox"] + .dropdown_button .arrow {
            display: inline-block;
            width: 1px;
            height: 1px;
            border-top: 5px solid silver;
            border-right: 5px solid transparent;
            border-left: 5px solid transparent;
        }

        .dropdown input[type="checkbox"]:checked + .dropdown_button .arrow { border-color: white transparent transparent transparent }

        .dropdown .dropdown_content {
            position: absolute;
            border: 1px solid #777;
            padding: 0px;
            background: white;
            margin: 0;
            display: none;
        }

        .dropdown .dropdown_content li {
            list-style: none;
            margin-left: 0px;
            line-height: 16px;
            border-top: 1px solid #FFF;
            border-bottom: 1px solid #FFF;
            margin-top: 2px;
            margin-bottom: 2px;
        }

        .dropdown .dropdown_content li:hover {
            background: silver;
        }

        .dropdown .dropdown_content li a {
            display: block;
            padding: 2px 7px;
            padding-right: 15px;
            color: black;
            text-decoration: none !important;
            white-space: nowrap;
        }

        .dropdown .dropdown_content li:hover a {
            color: white;
            text-decoration: none !important;
        }
        .dropdown input[type="checkbox"]:checked ~ .dropdown_content { display: block }
        .dropdown input[type="checkbox"] { display: none }
    </style>    

    Here there will be a lot of text and a lot of other menu buttons. So hope the angle of the dropdown will open to the left instead of the right.
    <div class="dropdown" id="dropdown">
        <input type="checkbox" id="drop1" />
        <label for="drop1" class="dropdown_button"><img src="http://ichef.bbci.co.uk/wwfeatures/43_43/images/live/p0/17/tx/p017txf6.jpg" height="43" width="43" /><span class="arrow"></span></label>
        <ul class="dropdown_content">
            <li><a href="#">Privacy settings</a></li>                       
            <li><a href="#">Account settings</a></li>
            <li><a href="#">Logout</a></li>                                
        </ul>

    </div>
</body>
</html>

現在,我通過糾正padding padding: 0px 0px;來固定圖像周圍的padding padding: 0px 0px; 但是后來我感覺就像在瞎子里工作...有人可以幫我指出在哪里進行調整嗎?

給您的跨度ID為“ arrowSpan”,並在您的CSS中應用此樣式:

#arrowSpan{
    display:block;
    margin-left:17px;
    margin-top:2px;
    margin-bottom:5px;
}

還加position:absolute; right:0到您的.dropdown .dropdown_content樣式。

這是一個小提琴: http : //jsfiddle.net/zsp7t/1/

至於在外部單擊時折疊下拉菜單,則可以。 網上有很多使用jQuery的示例,以下幾個可以幫助您入門:

您還提到了您想了解更多信息,因此請訪問以下網站,以幫助您提高技能:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM