Languages
[Edit]
EN

CSS - display only first image in div

3 points
Created by:
Zachariah
298

In this short article, we would like to show how to display only the first img element in the div element using CSS.

Quick solution:

Use img { display: none; } with img:first-child { display: inline; }

Where: display: inline can be replaced with any other values, e.g. block, flex, itp.

 

Practical examples

Edit

In the below examples, you can find multiple div container elements where for each one only first image is displayed.

Example 1

Edit

Example 2

Edit

Example 3

Edit

See also

Edit
  1. CSS - display only last image in div 

Alternative titles

  1. CSS - display only first img element in div
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join