Questions tagged [css-parsing]

CSS is the abbreviation of Cascading Style Sheets

57 questions
13
votes
8 answers

Parsing CSS by regex

I'm creating a CSS editor and am trying to create a regular expression that can get data from a CSS document. This regex works if I have one property but I can't get it to work for all properties. I'm using preg/perl syntax in…
Ross
  • 46,186
  • 39
  • 120
  • 173
12
votes
2 answers

Is it possible to parse a stylesheet with Nokogiri?

I've spent my requisite two hours Googling this, and I can not find any good answers, so let's see if humans can beat Google computers. I want to parse a stylesheet in Ruby so that I can apply those styles to elements in my document (to make the…
wbharding
  • 4,213
  • 2
  • 30
  • 25
11
votes
1 answer

Why do CSS comma separated selectors break entire rule when one part is unknown?

Explaining the issue: So if you have a CSS Rule that looks something like this: h1, h1 a:hover { color: blue; } It works fine, the example might ne be the best from a usability point of view, but it works. (And it works to demonstrate the issue…
Type-Style
  • 1,791
  • 1
  • 16
  • 35
10
votes
2 answers

Do custom CSS properties use one leading dash or two?

#elem { -myCustom: 99; } OR #elem { --myCustom: 99; } I have seen both of the above used in examples online. What the difference between the two? Trying to access custom properties in JavaScript returns null.. #elem { -myCustom: 99; }
9
votes
4 answers

Parsing CSS with ANTLR - edge cases

I'm trying to parse CSS, or at least the basics, using ANTLR. I'm running into a few problems with my lexer rules though. The problem lies in the ambiguity between an ID selectors and hexadecimal color values. Using a simplified grammar for clarity,…
Erik van Brakel
  • 23,220
  • 2
  • 52
  • 66
6
votes
6 answers

Add prefix to css rules with javascript

I have a string with the following css that I need to process with javascript h1 { color: red; } .info { border: 1px dotted blue; padding: 10px; } #rect { background: pink; } h2, h3, h4 { font-weight: bold; } table td:last…
Adrian Rosca
  • 6,922
  • 9
  • 40
  • 57
5
votes
2 answers

PHP CSS Parser - Selector Declarations to String

I want to be able to read a CSS file, and be able to extract all declarations of a given selector in to a string. For example, given the following stylesheet: h1 { font-size: 15px; font-weight: bold; font-style: italic; font-family: Verdana,…
0pt1m1z3
  • 841
  • 3
  • 12
  • 23
3
votes
1 answer

How to get css properties from a parsed html element using AngleSharp

Having this CSS: .foo { background-size: 10px 20px; } And this Html: And this C#: var parser = new HtmlParser(); var doc = parser.Parse("http://localhost/test.html"); var element = doc.QuerySelector("span.foo"); How do I…
SamuGG
  • 479
  • 2
  • 8
  • 20
3
votes
4 answers

How to parse HTML and get CSS styles

I need to parse HTML and find corresponding CSS styles. I can parse HTML and CSS separataly, but I can't combine them. For example, I have an XHTML page like this:
Hello…
atknatk
  • 31
  • 1
  • 3
3
votes
4 answers

Do browsers request images that have been overwritten in CSS?

Let's say I have CSS that looks like this: #element {background-image: url("image1.png");} #element {background-image: url("image2.png");} Will the browser: Request image1.png, then request image2.png and display it? Or... Parse the CSS first, see…
daGUY
  • 27,055
  • 29
  • 75
  • 119
2
votes
1 answer

I'm searching for a reliable CSS parser / manipulator in PHP

I'm working on a project where a user can edit a CSS-file. However, we need to set some rules that must not be overwritten. Using the !important rule would be one way to do this, but in a worst-case-scenario, the user could overwrite that too by…
Lukas
  • 9,752
  • 15
  • 76
  • 120
2
votes
1 answer

CSS parsing: matching specific entities using cssparser

For one of my projects, which validates JSON using JSON Schema, I miss accurate code for two format specifications: color and style. The first specification, color, denotes whatever color is valid in CSS 2.1. The second, style, is whatever CSS 2.1…
fge
  • 119,121
  • 33
  • 254
  • 329
2
votes
0 answers

CSS-in-JS parser for JavaScript/Typescript?

I'd like to parse CSS-in-JS (styled-components) which is written in my tsx file into an AST so I can change the hex color into the css variable name. For example, const Wrapper = styled.div` background-color: #ffffff; `; to const Wrapper =…
2
votes
2 answers

How to get selector inside @media?

I'm trying to parse css by using CSSParser For example, I have css: final String css = "@media screen and (color) { h1 { color: red } }"; I want to get this part: { h1 { color: red } } But when I'm doing it by using mediaList final…
rdhd
  • 85
  • 1
  • 1
  • 9
2
votes
2 answers

distinguishing between pages using JavaScript

I'm curious as to how I'd get JavaScript to distinguish between two near identical pages which (as far as I can tell) have the same div's. An example of a page like this would be Google Home Page vs. Google Search Results. Is there anyway I can…
Skizit
  • 43,506
  • 91
  • 209
  • 269
1
2 3 4