Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CSS locates how to use it in various languages

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to use CSS in various languages", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how to use CSS in various languages".

In the CSS file

The positioning method we are going to introduce is called css positioning, so it basically belongs to the category of CSS technology. We know that the basic syntax of CSS is as follows:

Selector {style code; style code}

For example:

.content p.nowrap {disblock:none; background-color:yellow;}

We know that tags that might have the same situation exist in an html file. So when writing front-end pages, front-end development engineers will try their best to avoid repetition of selectors. By heavily setting selectors, they make each selector correspond to a tag as much as possible (of course, front-end developers prefer styles to be reused).

As a front-end technology, this idea of CSS selectors gives other languages a good idea, such as the next JavaScript.

In JavaScript

In the process of JavaScript operating on DOM, many partners will feel that the operation is inadequate. The reason is simple: not all html elements have id attributes, and other getElement methods have corresponding defects (fetching many objects at a time, which is inconvenient to use). But in fact, JavaScript provides two more useful methods-- querySelector () and querySelectorAll (). The querySelector () method returns the first child element that matches the specified CSS selector element. This method returns only the first element that matches the specified selector. The querySelectorAll () method returns all matching elements at once.

Note: in the above, we mentioned the CSS selector. Yes, the object to be passed in by these two methods is the CSS selector. Taking the above CSS code as an example, to find the element rendered by this CSS code, we use the following method:

Var el = querySelector (".content p.nowrap")

This method returns an el object. If there is more than one label rendered, we can use the following method to get all the elements:

Var el = querySelectorAll (".content p.nowrap")

This method returns an array of el objects.

In jQuery

JQuery, as a library for JavaScript, can also use the above JavaScript method, but it is used in a slightly different way.

Var el = $(".content p.nowrap")

In selenium

In selenium, you can also use CSS to locate elements on html (but unlike the purpose of JavaScript, selenium locates elements for the purpose of manipulating this element for the purpose of automation). Selenium is supported in multiple languages. Take python as an example. The code for CSS positioning by python selenium is as follows:

Content = driver.find_element_by_css_selector ('.content p.nowrap')

In addition, selenium provides a By class for positioning, which can be used by both python and java.

Driver.find_elements (By. CSS_SELECTOR,'.content p.nowrap')

The above is about the content of this article on "how to use CSS in various languages". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report