简体   繁体   English

逆向工程Bootstrap菜单栏

[英]Reverse Engineering a Bootstrap Menubar

I used the website http://bootstrapdesigntools.com/tools/bootstrap-menu-builder/ (very helpful- check it out if you haven't already) to create a responsive menubar. 我使用网站http://bootstrapdesigntools.com/tools/bootstrap-menu-builder/ (非常有帮助 - 如果你还没有检查它)来创建一个响应式菜单栏。 However, I am having trouble editing certain aspects of it because I did not create the code myself. 但是,我在编辑它的某些方面时遇到问题,因为我自己没有创建代码。 I have attempted to reverse engineer (not sure if this term applies in coding) the code and have nine questions. 我试图对代码进行逆向工程(不确定这个术语是否适用于编码)并且有九个问题。 Sorry for the number of questions. 对不起,问题的数量。 Feel free to only answer a few. 随意只回答几个。 I posted this last night but it was a mess, so reposting a more simple version. 我昨晚发布了这个,但它很乱,所以重新发布一个更简单的版本。

1.) How do I set a different color for the active tab of the menu? 1.)如何为菜单的活动选项卡设置不同的颜色?

2.) What is a CSS selector like the following targeting? 2.)什么是CSS选择器,如下面的定位?

#custom-bootstrap-menu.navbar-default .navbar-brand 

3.) Why is there a space between the ".navbar-default" and ".navbar-brand" but not with "#custom-bootstrap-menu.navbar-default" in the above code? 3.)为什么“.navbar-default”和“.navbar-brand”之间有空格,而上面代码中没有“#custom-bootstrap-menu.navbar-default”?

4.) Why is the background defined three times in code blocks like the following? 4.)为什么背景在代码块中定义了三次,如下所示? Is this a backup for older browsers? 这是旧版浏览器的备份吗?

   background-color: rgba(47, 196, 116, 1);
    background: -webkit-linear-gradient(top, rgba(54, 135, 2, 1) 0%, rgba(47, 196, 116, 1) 100%);
    background: linear-gradient(to bottom, rgba(54, 135, 2, 1) 0%, rgba(47, 196, 116, 1) 100%);

5.) What is the end part of the following code styling? 5.)以下代码样式的最终部分是什么? Links that are the children of list items that are the children of class navbar-nav? 作为navbar-nav类的子项的列表项的子项的链接?

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a

6.) What is the point of setting a background color with complete transparency as done in the following code? 6.)如下所示,在完全透明的情况下设置背景颜色的重点是什么?

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(248, 248, 248, 0);

7.) Does seperating two targets with a comma simply make the code within brackets apply to both? 7.)用逗号分隔两个目标只是使括号内的代码适用于两者吗?

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:hover,
#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:focus {

8.) In the code above I know hover is when the user places their mouse over the element. 8.)在上面的代码中,我知道悬停是指用户将鼠标放在元素上。 What does focus do? 焦点有什么作用? The descriptions I've read are written like "when something gains focus". 我读过的描述就像“当某些事情获得焦点”时所写的那样。 What exactly does gaining focus mean? 获得焦点究竟是什么意思?

9.) When targeting navbar elements with the bootstrap class toggle does this mean that the changes are only made upon screen resize? 9.)使用bootstrap类切换来定位navbar元素时,这是否意味着更改仅在屏幕调整大小时进行?

#custom-bootstrap-menu.navbar-default .navbar-toggle:hover,
#custom-bootstrap-menu.navbar-default .navbar-toggle:focus 

Relevant code is as follows: 相关代码如下:

Relevant CSS 相关的CSS

#custom-bootstrap-menu.navbar-default .navbar-brand {
    color: rgba(255, 255, 255, 1);
}
#custom-bootstrap-menu.navbar-default {
    font-size: 15px;
    background-color: rgba(47, 196, 116, 1);
    background: -webkit-linear-gradient(top, rgba(54, 135, 2, 1) 0%, rgba(47, 196, 116, 1) 100%);
    background: linear-gradient(to bottom, rgba(54, 135, 2, 1) 0%, rgba(47, 196, 116, 1) 100%);
    border-width: 1px;
    border-radius: 4px;
}
#custom-bootstrap-menu.navbar-default .navbar-nav>li>a {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(248, 248, 248, 0);
}
#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:hover,
#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:focus {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(68, 229, 74, 1);
}
#custom-bootstrap-menu.navbar-default .navbar-nav>.active>a,
#custom-bootstrap-menu.navbar-default .navbar-nav>.active>a:hover,
#custom-bootstrap-menu.navbar-default .navbar-nav>.active>a:focus {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(66, 165, 3, 1);
    background: -webkit-linear-gradient(top, rgba(54, 135, 2, 1) 0%, rgba(66, 165, 3, 1) 100%);
    background: linear-gradient(to bottom, rgba(54, 135, 2, 1) 0%, rgba(66, 165, 3, 1) 100%);
}
#custom-bootstrap-menu.navbar-default .navbar-toggle {
    border-color: #42a503;
}
#custom-bootstrap-menu.navbar-default .navbar-toggle:hover,
#custom-bootstrap-menu.navbar-default .navbar-toggle:focus {
    background-color: #42a503;
}
#custom-bootstrap-menu.navbar-default .navbar-toggle .icon-bar {
    background-color: #42a503;
}
#custom-bootstrap-menu.navbar-default .navbar-toggle:hover .icon-bar,
#custom-bootstrap-menu.navbar-default .navbar-toggle:focus .icon-bar {
    background-color: #2fc474;
}

Relevant HTML: 相关HTML:

    <div id="custom-bootstrap-menu" class="navbar navbar-default " role="navigation">
    <div class="container-fluid">
        <div class="navbar-header"><a class="navbar-brand" href="#">Brand Logo</a>
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-menubuilder"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse navbar-menubuilder">
            <ul class="nav navbar-nav navbar-left">
                <li><a href="#">Home</a>
                </li>
                <li><a href="/products">Products</a>
                </li>
                <li><a href="/about-us">About Us</a>
                </li>
                <li><a href="/contact">Contact Us</a>
                </li>
            </ul>
        </div>
    </div>
</div>
  1. The tool gives the ability to add different color to the active tab via "Active styles" 该工具可以通过“活动样式”为活动选项卡添加不同的颜色
  2. #custom-bootstrap-menu.navbar-default .navbar-brand will target the text "Brand" or the logo placed in this tag #custom-bootstrap-menu.navbar-default .navbar-brand将定位文本“Brand”或放置在此标签中的徽标
  3. The space means that the next element is child of the previous. 空格意味着下一个元素是前一个元素。 When they are not separated with space this means that the two classes/ids belong to one element. 当它们没有用空格分隔时,这意味着两个类/ id属于一个元素。
  4. Yes, the first one is valid to all browsers and is back up to these browsers, which can not apply the gradient. 是的,第一个对所有浏览器都有效,并且备份到这些浏览器,这些浏览器无法应用渐变。 -webkit- is needed for the webkit based browsers. -webkit-是基于webkit的浏览器所必需的。
  5. Yes, links that are direct children. 是的,直接孩子的链接。
  6. -- -
  7. Yes
  8. Focus is when the element is clicked, like when you click on input to write. 焦点是单击元素的时候,就像单击要写入的输入一样。

Let me try to answer your questions. 让我试着回答你的问题。

1.) How do I set a different color for the active tab of the menu? 1.)如何为菜单的活动选项卡设置不同的颜色?

There should be a class (usually .active ) that would be applied to the currently active menu item or tab. 应该有一个类(通常是.active )将应用于当前活动的菜单项或选项卡。 You just need to override styles for it. 您只需要覆盖它的样式。

2.) What is a CSS selector like the following targeting? 2.)什么是CSS选择器,如下面的定位?

#custom-bootstrap-menu.navbar-default .navbar-brand

This targets all elements that have a class navbar-brand and are CHILDREN fo an element that has an id custom-bootstrap-menu AND a class navbar-default applied to it. 这是针对具有类navbar-brand所有元素,并且是具有id custom-bootstrap-menu和应用了类navbar-default的元素的CHILDREN。

3.) Why is there a space between the ".navbar-default" and ".navbar-brand" but not with "#custom-bootstrap-menu.navbar-default" in the above code? 3.)为什么“.navbar-default”和“.navbar-brand”之间有空格,而上面代码中没有“#custom-bootstrap-menu.navbar-default”?

Basically, when there is a space between selectors it refers to a parent-child relationship as in #custom-bootstrap-menu.navbar-default .navbar-brand , here .navbar-brand refers to child elements of #custom-bootstrap-menu.navbar-default . 基本上,当选择器之间有space ,它指的是父子关系,如#custom-bootstrap-menu.navbar-default .navbar-brand ,这里.navbar-brand指的是#custom-bootstrap-menu.navbar-default子元素#custom-bootstrap-menu.navbar-default Whereas when the selectors have no space, as in #custom-bootstrap-menu.navbar-default , it means an AND operation <id>and<class> in this case. 而当选择器没有空间时,如#custom-bootstrap-menu.navbar-default ,在这种情况#custom-bootstrap-menu.navbar-default ,它表示AND操作<id>and<class>

4.) Why is the background defined three times in code blocks like the following? 4.)为什么背景在代码块中定义了三次,如下所示? Is this a backup for older browsers? 这是旧版浏览器的备份吗?

This is targeting different types of browsers. 这是针对不同类型的浏览器。 The WebKit-based ones like chrome and safari and others. 基于WebKit的,如chrome和safari等。 When you see something starting with -webkit- it means we are targeting WebKit-based browsers. 当您看到以-webkit-开头的内容时,这意味着我们的目标是基于WebKit的浏览器。

5.) What is the end part of the following code styling? 5.)以下代码样式的最终部分是什么? Links that are the children of list items that are the children of class navbar-nav? 作为navbar-nav类的子项的列表项的子项的链接?

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a

Yes. 是。 Almost correct. 差不多正确。 Just that it refers to, Links that are the immidiate children of list items that are the immidiate children of class navbar-nav` 只是,它指的是,这是链接immidiate children的列表项属于immidiate children类导航栏,nav`的

6.) What is the point of setting a background color with complete transparency as done in the following code? 6.)如下所示,在完全透明的情况下设置背景颜色的重点是什么?

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(248, 248, 248, 0);

This is usually done when you want the font color to be fully opaque versus the background. 当您希望字体颜色与背景完全不透明时,通常会执行此操作。

7.) Does seperating two targets with a comma simply make the code within brackets apply to both? 7.)用逗号分隔两个目标只是使括号内的代码适用于两者吗?

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:hover,
#custom-bootstrap-menu.navbar-default .navbar-nav>li>a:focus {

Yes.That's correct. 对,那是正确的。 This is how you reuse CSS and apply it to various elements. 这是您重用CSS并将其应用于各种元素的方法。

8.) In the code above I know hover is when the user places their mouse over the element. 8.)在上面的代码中,我知道悬停是指用户将鼠标放在元素上。 What does focus do? 焦点有什么作用? The descriptions I've read are written like "when something gains focus". 我读过的描述就像“当某些事情获得焦点”时所写的那样。 What exactly does gaining focus mean? 获得焦点究竟是什么意思?

The focus makes the current element active. 焦点使当前元素有效。 For instance, if you are filling a form and you are typing in the first text field, then the first text field is said to have the focus or it is the element the user is interacting with. 例如,如果要填写表单并输入第一个文本字段,则表示第一个文本字段具有focus或者它是用户正在与之交互的元素。 He does not necessarily have his mouse over that field, but he is interacting with it using his keyboard. 他不一定将鼠标放在那个领域上,但是他正在使用他的键盘与它进行交互。 Similarly, when you navigate a web page using your keyboard by hitting the Tab key multiple times, then, in reality you are shifting the focus from one element to other. 同样,当您通过多次按Tab键使用键盘导航网页时,实际上您将focus从一个元素转移到另一个元素。 However, it is an important point to note that not all HTML elements can get focus. 但是,需要注意的是,并非所有HTML元素都能获得焦点。

9.) When targeting navbar elements with the bootstrap class toggle does this mean that the changes are only made upon screen resize? 9.)使用bootstrap类切换来定位navbar元素时,这是否意味着更改仅在屏幕调整大小时进行?

No this does not take effect on screen resize, this may mean an open-close operation, where toggle class is added or removed depending upon the state of the navbar element. 这不会对屏幕调整大小生效,这可能意味着打开关闭操作,根据导航栏元素的状态添加或删除切换类。

Phew! 唷! That was long. 那很长。 :) Hope I was able to help you understand some of this stuff. :)希望我能帮助你理解这些东西。

Use a code inspector like firebug for Firefox or right click inspect element i Safari to se what CSS rule affects different elements. 使用代码检查器(如firebug for Firefox)或右键单击inspect element i Safari来查看CSS规则对不同元素的影响。 If you click on a source code element, it even shows the line number in you css file to look for the rule to change. 如果单击源代码元素,它甚至会在您的css文件中显示行号以查找要更改的规则。

  1. #menu-builder-navigation.navbar-default .navbar-nav>.active>a {}

  2. #custom-bootstrap-menu.navbar-default .navbar-brand {} targets the element with the class "navber-brand" inside the element with id "custom-bootstrap-menu" #custom-bootstrap-menu.navbar-default .navbar-brand {}使用id为“custom-bootstrap-menu”的元素内的“navber-brand”类定位元素

  3. #custom-bootstrap-menu.navbar-default {} targets the element with both the ID custom-bootstrap-menu and also the class navbar-default #custom-bootstrap-menu.navbar-default {}使用ID custom-bootstrap-menu和类navbar-default来定位元素
  4. background: linear-gradient... is what is showing in modern browsers. background: linear-gradient...是现代浏览器中展示的内容。 The other is fallbacks for older browser. 另一个是旧浏览器的后备。
  5. This usually means menu level one * 这通常意味着菜单一级*
  6. You could change only opacity later with a simple rule, jQuery or javascript. 您可以稍后使用简单的规则,jQuery或javascript更改不透明度。 If not you could have used background:tansparent; 如果没有,你可以使用background:tansparent;
  7. Yes, two targets separated with a comma targets both classes. 是的,用逗号分隔的两个目标都是两个类。
  8. focus is when the element is used or targeted for use – when you are writing in an input field it is being targeted. 焦点是当元素被使用或被定位使用时 - 当你在输入字段中写入它时,它被定位。
  9. In this example the hover and target has the same rule set. 在此示例中,悬停和目标具有相同的规则集。 I guess the target rule set is kicking in after the element has been clicked in this case. 我想在这种情况下点击元素之后,目标规则集就开始了。

[edit]* The answer to no 5 was a bit inaccurate. [编辑] *没有5的答案有点不准确。

#custom-bootstrap-menu.navbar-default .navbar-nav li a

and

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a

usually do the same thing unless there is some other element between them like this: <li><ol><li><a href="#"></a></li></ol></li> or the menu is multilevel. 通常做同样的事情,除非他们之间有其他一些元素,如: <li><ol><li><a href="#"></a></li></ol></li>或菜单是多层次的。

If you have a multilevel menu this css code would target the different levels: 如果你有一个多级菜单,这个css代码将针对不同的级别:

#custom-bootstrap-menu.navbar-default .navbar-nav>li>a (level 1) #custom-bootstrap-menu.navbar-default .navbar-nav>li>a (1级)

#custom-bootstrap-menu.navbar-default .navbar-nav>li>ul>li>a (level 2) #custom-bootstrap-menu.navbar-default .navbar-nav>li>ul>li>a (级别2)

#custom-bootstrap-menu.navbar-default .navbar-nav>li>ul>li>ul>li>a (level 3) #custom-bootstrap-menu.navbar-default .navbar-nav>li>ul>li>ul>li>a (级别3)

or 要么

#custom-bootstrap-menu.navbar-default .navbar-nav li a (all levels) #custom-bootstrap-menu.navbar-default .navbar-nav li a (所有级别)

#custom-bootstrap-menu.navbar-default .navbar-nav li ul li a (level 2 override) #custom-bootstrap-menu.navbar-default .navbar-nav li ul li a (level 2 override)

#custom-bootstrap-menu.navbar-default .navbar-nav li ul li ul li a (level 3 override) #custom-bootstrap-menu.navbar-default .navbar-nav li ul li ul li a (3级覆盖)

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

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