HTML CSS Exercise: Style first and the last element
Solution:
HTML Code:
Explanation:
- The HTML document is structured using standard tags such as <html>, <head>, <title>, <body>, and <div>.
- CSS styling is applied within <style> tags.
- The .container class sets the width of the container to 500px.
- The CSS selector p:first-child selects the first paragraph element within the container and sets its text color to #5ac4ed.
- Similarly, p:last-child selects the last paragraph element within the container and sets its text color to #5ac4ed.
Live Demo:
Supported browser
![]() |
![]() |
![]() |
![]() |
![]() |
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.