How to select the second paragraph after another with css?


Tags: css

Problem :

I would like to apply margin-bottom, only if there is another paragraph directly after the other one. I know there is a way to select the first paragraph if the next one is also a paragraph, but I unfortunately forgot how. Can someone help me out?

I thought with the plus symbol: #blog .blog-post .entry p+p

But this will result in add margin-bottom to the last paragraph...



Solution :

You can use nth-child. For more details see here: https://css-tricks.com/how-nth-child-works/

To add more detail, badically you would do something like this:

p:nth-child(2) { }

Or apply it to a div if the 2nd p is a child of div. More details on child selection


    CSS Howto..

    How to achieve this layout with CSS and div?

    how to save responsive menu open/close value?

    How to align div in body to stay with specific height and width

    How to verify background (css) image was loaded?

    How to inherit the background color of textarea from parent element in Internet Explorer?

    how to conditionally transform div to and from a state on multiple presses of same button

    Show missing CSS in Google Chrome

    How to style radcombobox item so that words that wrap are separated

    How can a user add content to a website? [closed]

    jQuery - How to get elements height value and use it in another element via css code?

    How do I submit suggestions to the CSS spec? [closed]

    How to scroll an html element both horizontally and vertically with top and side labels scrolling correctly

    How to include image into css file using JSF tag

    How to selectively load/use CSS for YUI modules?

    How to use YUI Compressor in Ant build script for javascript and css

    How to display child elements of
  • at 100% height?
  • Bootstrap with custom css how to align text vertically?

    How to change styling of a specific div onhover of another element when divs share an id

    How to make submenus drop down below parent menu, instead of flying out?

    How can I make a fade in function without using jQuery like this? (JavaScript)

    How to style differently only the first list item from unsorted list

    How can i override the margin: 0; padding: 0; border: 0; css styles from main body css for ul li

    How do you add pseudo classes to elements using jQuery?

    How to style a PHP generated label?

    How to target the first-child of an optgroup with css or jquery

    How to override cloudmade maps css with your own css? [closed]

    Openlayers Map is shown only if the CSS contains a syntax error

    How do I use CSS to give a section a background that doesn't scroll with the page?

    How to use “css” in the “jsp” in Spring MVC project?

    android - How to build complex views that stretch?