如何使用 CSS 制作 3 个垂直点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30260195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:12:02  来源:igfitidea点击:

How to make 3 vertical dots using CSS?

css

提问by user4903904

I want to have 3 dots on my page to, for example, toggle the display of a contextual menu. How can I achieve this using CSS?

我想在我的页面上有 3 个点,例如,切换上下文菜单的显示。如何使用 CSS 实现这一点?

3-dots toggle animation gif

3-dots toggle animation gif

回答by vals

using an unicode char

使用 unicode 字符

.test:after {
  content: '07';
  font-size: 100px;
  }
<div class="test"></div>

using background property

使用背景属性

div {
    width: 100px;
    height: 100px;
    background-image: radial-gradient(circle, black 10px, transparent 11px);
    background-size: 100% 33.33%;
}
<div></div>

shadow

阴影

div {
  width: 30px;
  height: 30px;
  border-radius: 50%;
    background-color: black;
  box-shadow: 0px 40px 0px black, 0px 80px 0px black;
}
<div></div>

pseudo elements

伪元素

div {
  position: relative;
  width: 20px;
  height: 20px;
  background-color: black;
  border-radius: 50%;
}

div:before, div:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0px;
  background-color: inherit;
  border-radius: inherit;
  }

div:before {
  top: 40px;
  }


div:after {
  top: 80px;
}
<div></div>

回答by Ashwin

Try this complete source code for 3 dot menu:

试试这个 3 点菜单的完整源代码:

index.html

索引.html

<!DOCTYPE html>
    <html>
        <head>
            <title>Three Dot Menu</title>

            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

            <style>
                *{margin: 0;padding:0px}

                .header{
                    width: 100%;
                    background-color: #0d77b6 !important;
                    height: 60px;
                }

                .showLeft{
                    background-color: #0d77b6 !important;
                    border:1px solid #0d77b6 !important;
                    text-shadow: none !important;
                    color:#fff !important;
                    padding:10px;
                }

                .icons li {
                    background: none repeat scroll 0 0 #fff;
                    height: 7px;
                    width: 7px;
                    line-height: 0;
                    list-style: none outside none;
                    margin-right: 15px;
                    margin-top: 3px;
                    vertical-align: top;
                    border-radius:50%;
                    pointer-events: none;
                }

                .btn-left {
                    left: 0.4em;
                }

                .btn-right {
                    right: 0.4em;
                }

                .btn-left, .btn-right {
                    position: absolute;
                    top: 0.24em;
                }

                .dropbtn {
                    background-color: #4CAF50;
                    position: fixed;
                    color: white;
                    font-size: 16px;
                    border: none;
                    cursor: pointer;
                }

                .dropbtn:hover, .dropbtn:focus {
                    background-color: #3e8e41;
                }

                .dropdown {
                    position: absolute;
                    display: inline-block;
                    right: 0.4em;
                }

                .dropdown-content {
                    display: none;
                    position: relative;
                    margin-top: 60px;
                    background-color: #f9f9f9;
                    min-width: 160px;
                    overflow: auto;
                    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
                    z-index: 1;
                }

                .dropdown-content a {
                    color: black;
                    padding: 12px 16px;
                    text-decoration: none;
                    display: block;
                }

                .dropdown a:hover {background-color: #f1f1f1}

                .show {display:block;}

            </style>
            <script>
                function changeLanguage(language) {
                    var element = document.getElementById("url");
                    element.value = language;
                    element.innerHTML = language;
                }

                function showDropdown() {
                    document.getElementById("myDropdown").classList.toggle("show");
                }

                // Close the dropdown if the user clicks outside of it
                window.onclick = function(event) {
                    if (!event.target.matches('.dropbtn')) {
                        var dropdowns = document.getElementsByClassName("dropdown-content");
                        var i;
                        for (i = 0; i < dropdowns.length; i++) {
                            var openDropdown = dropdowns[i];
                            if (openDropdown.classList.contains('show')) {
                                openDropdown.classList.remove('show');
                            }
                        }
                    }
                }
            </script>
        </head>
        <body>
            <div class="header">

                <!-- three dot menu -->
                <div class="dropdown">
                    <!-- three dots -->
                    <ul class="dropbtn icons btn-right showLeft" onclick="showDropdown()">
                        <li></li>
                        <li></li>
                        <li></li>
                    </ul>
                    <!-- menu -->
                    <div id="myDropdown" class="dropdown-content">
                        <a href="#home">Home</a>
                        <a href="#about">About</a>
                        <a href="#contact">Contact</a>
                    </div>
                </div>

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

回答by Donato

If you are using font-awesome, it is as easy as including the .fa-ellipsis-vstyle. Further documentation is found here: http://fontawesome.io/icon/ellipsis-v/.

如果您使用 font-awesome,它就像包含.fa-ellipsis-v样式一样简单。可在此处找到更多文档:http: //fontawesome.io/icon/ellipsis-v/

回答by Qammar Feroz

  1. With fontawesome.css

    <i class='fa fa-ellipsis-v'></i>
    
  2. With Glyphicons

    <span class="glyphicons glyphicons-option-vertical"></span>
    
  3. With css

    .textSpan:after {
     content: '07';
     font-size: 3em;
     color: #2e2e2e
    }
    
  1. 使用 fontawesome.css

    <i class='fa fa-ellipsis-v'></i>
    
  2. 带字形

    <span class="glyphicons glyphicons-option-vertical"></span>
    
  3. 用css

    .textSpan:after {
     content: '07';
     font-size: 3em;
     color: #2e2e2e
    }
    

回答by kojow7

Unicode includes ⠇ which is the Braille symbol for the letter "U". To use, just use the HTML entity &#10247;in your code.

Unicode 包括 ⠇,它是字母“U”的盲文符号。要使用,只需&#10247;在代码中使用 HTML 实体。

回答by vas

HTML

HTML

<div class="dot"></div>

css:

css:

.dot{
    width: 10px;
    height: 10px;
    background: red;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}

回答by Jaison

Most voted answer showed me with dotted with 2 column, So I accomplished with below Unicode character.

大多数投票的答案向我展示了带有 2 列的虚线,所以我完成了以下 Unicode 字符。

<div>&#xFE19;</div>

回答by Anoop M

<script> <meta name="viewport" content="width=device-width, initial-scale=1"/>
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></link></script>

 <i class="fa fa-ellipsis-v col-2 mt-3 .text-light fa-lg" style={{"float":"right"}}></i>

This can be used to see three dots.This can be used in cards in react

这可以用来看到三个点。这可以用在卡片中的反应