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?
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.
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 .
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With