Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set css properties by id prefix?

Tags:

css

Example

Set for all divs with ids starting obj_ a black background color.

Is this possible just using CSS ?

EDIT

Ups I wrote class name in the title byt I ment Id name..

like image 721
user256034 Avatar asked Apr 19 '11 19:04

user256034


People also ask

Is there a CSS selector by class prefix?

This is not possible with CSS selectors. But you could use two classes instead of one, e.g. status and important instead of status-important.

How do I specify a field by ID in CSS?

The CSS id Selector To select an element with a specific id, write a hash (#) character, followed by the id of the element.

Can I use ID for CSS?

A CSS ID selector uses the ID attribute of an HTML element to select one unique element on a page. To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.

What is the prefix for a CSS ID selector?

The #id selector allows you to target an element by referencing the id HTML attribute. Similar to how class attributes are denoted in CSS with a “period” ( . ) before the class name, ID attributes are prefixed with an “octothorpe” ( # ), more commonly known as a “hash” or “pound sign”.


1 Answers

Using the CSS3 attribute-starts-with selector:

div[id^="obj_"] {
    background: #000
}

This will work in all modern browsers.

like image 123
thirtydot Avatar answered Sep 19 '22 14:09

thirtydot