简体   繁体   English

class="active" 在 bootstrap 3 中到底做了什么?

[英]What does class=“active” really do in bootstrap 3?

I am learning twitter bootstrap 3 these days.这些天我正在学习 twitter bootstrap 3。 There is a class called "active" in bootstrap. bootstrap 中有一个叫做“active”的类。 I have seen this feature even in CSS.我什至在 CSS 中也见过这个特性。 As I know it indicates the active page or link (probably it is the page that we are currently in).据我所知,它表示活动页面或链接(可能是我们当前所在的页面)。 Please correct me if I am wrong.如果我错了,请纠正我。 What I need to know is why we need to call such a class in our mark-up.我需要知道的是为什么我们需要在标记中调用这样的类。 Because it is upto the user to decide which page that he needs to be in.因为由用户决定他需要进入哪个页面。

If I explain this further below mark-up has used class="active" in the 2nd list element.如果我在下面进一步解释这一点,标记在第二个列表元素中使用了 class="active"。 (ie Profile). (即配置文件)。 When I run the code in a browser it adds a nice blue background to Profile.当我在浏览器中运行代码时,它会为 Profile 添加漂亮的蓝色背景。 Why should I add such a class?为什么要添加这样的类? Active tabs vary when users navigate from one tab to another.当用户从一个选项卡导航到另一个时,活动选项卡会有所不同。 Is not it?是不是?

<div class="container">
            <div class="row">
                <nav>
                    <ul class="nav nav-pills nav-justified">
                        <li><a href="Breadcrumbs.html">Dashboard</a></li>
                        <li class="active"><a href="Jumbotron.html">Profile</a></li>
                        <li><a href="FavoutieActors.html">Earnings</a></li>
                        <li><a href="Buttons.html">Settings</a></li>                        
                    </ul>
                </nav>
            </div>
        </div>

With 4 pages in your Navigation, the .active class should be on each different list item from #1 to #4 depending on the page you're in. Below are 4 excerpts for each 4 pages.导航中有 4 个页面, .active类应该位于从 #1 到 #4 的每个不同列表项上,具体取决于您所在的页面。以下是每 4 个页面的 4 个摘录。

Breadcrumbs.html:面包屑.html:

                 <ul class="nav nav-pills nav-justified">
                    <li class="active"><a href="Breadcrumbs.html">Dashboard</a></li>
                    <li><a href="Jumbotron.html">Profile</a></li>
                    <li><a href="FavoutieActors.html">Earnings</a></li>
                    <li><a href="Buttons.html">Settings</a></li>                        
                </ul>

Jumbotron.html:大屏幕.html:

                 <ul class="nav nav-pills nav-justified">
                    <li><a href="Breadcrumbs.html">Dashboard</a></li>
                    <li class="active"><a href="Jumbotron.html">Profile</a></li>
                    <li><a href="FavoutieActors.html">Earnings</a></li>
                    <li><a href="Buttons.html">Settings</a></li>                        
                </ul>

FavoutieActors.html: FavoutieActors.html:

                 <ul class="nav nav-pills nav-justified">
                    <li><a href="Breadcrumbs.html">Dashboard</a></li>
                    <li><a href="Jumbotron.html">Profile</a></li>
                    <li class="active"><a href="FavoutieActors.html">Earnings</a></li>
                    <li><a href="Buttons.html">Settings</a></li>                        
                </ul>

Breadcrumbs.html:面包屑.html:

                 <ul class="nav nav-pills nav-justified">
                    <li><a href="Breadcrumbs.html">Dashboard</a></li>
                    <li><a href="Jumbotron.html">Profile</a></li>
                    <li><a href="FavoutieActors.html">Earnings</a></li>
                    <li class="active"><a href="Buttons.html">Settings</a></li>                        
                </ul>

The active class is applied to the navigation element the user is currently viewing. active类应用于用户当前正在查看的导航元素。

In the case of your given code, the user is viewing the the profile.在给定代码的情况下,用户正在查看配置文件。 It will serve as a guide or reminder to where in the website the visitor is in. That is why the active class is applied, which comes handy when viewing a website with many navigation links.它将作为访问者所在网站的指南或提醒。这就是应用活动类的原因,这在查看具有许多导航链接的网站时非常方便。

You can dynamically add the active class to whichever element is active.您可以将active类动态添加到任何活动元素。 You can either do this as your page is rendered.您可以在呈现页面时执行此操作。 Or via JavaScript, if you wish to change the active element without posting back to the server.或者通过 JavaScript,如果您希望更改活动元素而不回发到服务器。

From your example, by adding the active class to your 'Profile' item, it should render the item in a way that suggests visually that this is the current item or page you're viewing.从您的示例中,通过将active类添加到您的“个人资料”项目,它应该以一种直观的方式呈现该项目,即这是您正在查看的当前项目或页面。

What I need to know is why we need to call such a class in our mark-up.我需要知道的是为什么我们需要在标记中调用这样的类。 Because it is upto the user to decide which page that he needs to be in.因为由用户决定他需要进入哪个页面。

The user decide what page and the designer and developer decide how its button look while the user on it.用户决定哪个页面,设计者和开发者决定当用户在上面时按钮的外观。 The active class can do more than it's just a markup in your page.活动类可以做的不仅仅是页面中的标记。 It could be used to add different look and feel, color effects etc.它可用于添加不同的外观和感觉、颜色效果等。

Why should I add such a class?为什么要添加这样的类? Active tabs vary when users navigate from one tab to another.当用户从一个选项卡导航到另一个时,活动选项卡会有所不同。 Is not it?是不是?

You are not required to add and manage in many usual cases but sometimes you might need.在许多常见情况下,您不需要添加和管理,但有时您可能需要。 From design point of view, it tells the user that he/she is now here, from programming point of view that class could be used in different ways to assign unique action for that button or other button and not for it.从设计的角度来看,它告诉用户他/她现在在这里,从编程的角度来看,该类可以以不同的方式用于为该按钮或其他按钮而不是为其分配独特的动作。

The same thing for first and last classes we usually add, they allow us to do different scenarios or CSS proprieties for these buttons and/or elements.对于我们通常添加的第一个和最后一个类,它们允许我们为这些按钮和/或元素执行不同的场景或 CSS 属性。

Class="active" is usually used to highlight any active content from a selection, mostly in navigation. Class="active" 通常用于突出显示选择中的任何活动内容,主要是在导航中。 Let's say in a website with different page links on navigation, just to indicate that the user is on this page, active class highlights that link increasing the usability of navigation.假设在导航上具有不同页面链接的网站中,只是为了指示用户在此页面上,活动类突出显示该链接以增加导航的可用性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM