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 do I access HTML elements created by a function? The elements are “undefined” and therefore not CSS apply-able

    how can style be added to the first 2 list elements using CSS

    How do I size an image to fit inside another image? [closed]

    How to align colon vertically using css?

    how to animate with CSS?

    How to change the style/css of a tooltip?

    How to keep nav menu highlighted after click using js in sidebar

    CSS: How to make an image-border

    How to specify correct output folder for CSS using SASS & LiveReload?

    How to accomplish this layout with CSS and HTML?

    How to create class in a custom CSS file by JavaScript?

    How do I select a css element with a text not attached to the attribute?

    How to redefine a CSS class for the whole document?

    How to Make Glossy Colors in CSS. [closed]

    How to anchor a dynamic div to the screen?

    How to make footer not overlap and positioned properly?

    How to concat js/css files and replace in html using gulp?

    How to overlap elements inside of a ng-repeat list - position: absolute?

    How to contain a scrollable div element completely within another?

    My pure CSS dropdown isn't working, anybody knows how to fix it? [duplicate]

    CSS: How to limit length of the border-bottom div?

    How can i change or remove title and page address?

    How to prevent outside CSS from overriding web component styles

    How to target CSS link with JavaScript

    how to indent HTML forms on modals [closed]

    How To Set Height of Child Div According To Parent Div

    Show Limited Data Using jquery

    How to use jQuery's flag to swap CSS display property

    How to tilt inner element forward when tilting outer back with css 3d transforms

    How do I put a horizontal line/border right in the middle of a table row?