Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS class IMG inside div and span

Hi on beginning I have code like this:

<div class="123_test" tabindex="0" role="button">

    <span class="">
        <img class="" alt="" src="picturetopic"></img>        
    </span>
</div>

How can I style this img with 123_test class?

like image 449
Paweł Domański Avatar asked Oct 14 '13 12:10

Paweł Domański


People also ask

Can you put an image inside a span?

Usually span element is used to group inline elements together to implement style (using id or class attributes) or language information or JavaScript DOM(using id or class attributes), when no other element is found suitable to form that group. 3. The element can contain a piece of text or an image directly.

How do you call an image inside a div in CSS?

To select a image inside a div you need to first select the class of the div you want selected, like this . logo-img then add img to select the img element inside the . logo-img div, like this . logo-img img .

Can IMG have classes?

Classes (i.e. classnames) are used for styling the img element. Multiple classnames are separated by a space. JavaScript uses classes to access elements by classname. Tip: class is a global attribute that can be applied to any HTML element.

What is IMG div element in HTML?

The <img> tag is used to embed an image in an HTML page. Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the referenced image.


2 Answers

First of all you cannot start a class name using a digit, I assume that it's generating from somewhere as the classes are empty, but if you can, than consider changing it, like

class="name_123_test"

And use the selector below like

.name_123_test > span img {
   /* Styles goes here */
}

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

W3C Reference

like image 191
Mr. Alien Avatar answered Sep 23 '22 14:09

Mr. Alien


Why are your class attributes empty?

If you want to apply the 123_test class to the img tag, just add it in the class attribute:

<img class="123_test" alt="" src="picturetopic"></img>

Or do you mean that you want to use the ancestor div as a style guide for the img? In your CSS, you can reference the img as a descendant of the 123_test class:

.123_test img
{
    // css rules
}

The space between the two identifiers means that the latter is a descendant of the former.

like image 37
David Avatar answered Sep 21 '22 14:09

David