简体   繁体   English

不确定如何从复制的HTML5,CSS,JS中指定样式

[英]Not sure how to specify a style from a copied HTML5, CSS, JS

I have been slowly pulling apart an HTML5 template and have copy pasted a parallax section below several times on the same page As I have copied this 3 times for the parallax effect I also have the same background image as defined in the main.css 我一直在慢慢拉开HTML5模板,并在同一页面上多次复制粘贴了下面的视差部分。由于我已经为视差效果复制了3次,所以我也拥有与main.css中定义的相同的背景图片

 /* ========================================================================== Counter Section Style ========================================================================== */ .counters { background: url(../img/bg1.jpg) fixed; position: relative; } .counters .facts-item { text-align: center; color: #fff; } .counters .facts-item .icon { margin-bottom: 20px; } .counters .facts-item .icon i { font-size: 50px; color: #fff; } .counters .facts-item .fact-count h3 { font-size: 35px; color: #fff; margin-bottom: 15px; } .counters .facts-item .fact-count h4 { font-size: 20px; color: #fff; 
  <div class="counters section" data-stellar-background-ratio="0.5"> <div class="overlay"></div> <div class="container"> <div class="row"> <div class="col-sm-6 col-md-3 col-lg-3"> <div class="item-boxes wow fadeInDown" data-wow-delay="0.2s"> <!-- <div class="icon"> <i class="lnr lnr-pencil"></i> </div> --> <a class="nav-link" href="#video-area"> <h4>SaaS Assurance</h4></a> <p></p> </div> </div> 

The problem I have is that even though I have copied them, I would still like them to be their own sections with different backgrounds and with my limited experience on Web Dev I am not sure how class .counters from CSS which is defining the image I want to change is being picked up by the code which says counter section 我的问题是,即使我已经复制了它们,但我仍然希望它们成为具有不同背景的自己的版块,并且由于我在Web Dev方面的经验有限,我不确定CSS的.counters类如何定义我的图像。想要更改的内容正在计数器部分的代码中显示

Thanks all 谢谢大家

In CSS, Classes can be used more than once , so if you copy the parallax section three times, then there should be three parallax section with the same background as declared by .counters which is used by every of your parallax section. 在CSS中, 可以多次使用,因此, 如果您复制的视差部分三次,然后应该有三个视差部分与由所使用的每一个你的视差部分的.counters声明相同的背景。

To make sure that every of those 3 parallax section won't use the same background, try to use ID instead as ID's can be only used once and must have a unique name. 为了确保这3个视差部分不会使用相同的背景,请尝试使用ID代替,因为ID 只能使用一次,并且必须具有唯一的名称。

When an ID and classes is used together , the ID attributes should override any declarations made by any classes used in the element. 当ID和类一起使用 ,ID属性应覆盖元素中使用的任何类所作的任何声明。 In this case, you can give an ID that contain an individual background property for every of your parallax section ( something like #parallax-section1 , 2, and more ), so .counters's background declaration will override. 在这种情况下,您可以为每个视差部分提供一个包含独立背景属性的ID(类似于#parallax-section1,2等),因此.counters的背景声明将被覆盖。

Further reading : 进一步阅读:

  1. CSS Selectors by MDN Web Docs. MDN Web文档提供的CSS选择器
  2. Override Class Declarations by Styling ID Attributes by FreeCodeCamp. 通过设置FreeCodeCamp的ID属性样式来覆盖类声明

Note: When copy pasting an HTML element, make sure you do select from the starting bracket till the closing ones. 注意:复制粘贴HTML元素时,请确保从开始括号到结束括号之间进行选择。

thanks for all the responses. 感谢您的所有答复。 I found the issue that the class .counters was actually calling the image from class counters section from the code above, it must have just been ignoring the space and the section confused me :) 我发现问题是类.counters实际上是从上面的代码从类计数器部分调用图像,它肯定只是忽略了空格,该部分使我感到困惑:)

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

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