Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:30:31+00:00 2026-06-08T12:30:31+00:00

I want to create a box with consistent spacing on all sides, regardless of

  • 0

I want to create a box with consistent spacing on all sides, regardless of the content.

Unfortunately, elements have margins which cause issues when the box is given padding. This is expected because the element’s margin doesn’t ‘flow’ out of the box over padding. A demo is at http://jsfiddle.net/cZf7E/1/

Up to now I’ve had special style rules for anything in the box which is at the top (with margin-top: 0) and bottom (with margin-bottom: 0). For the top it’s not bad, but at the bottom there’s a lot of potential tags to style.

Is there a way to do this that’s not so hacky?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:30:32+00:00Added an answer on June 8, 2026 at 12:30 pm

    How about

    aside :first-child {
        margin-top: 0;
    }
    ​aside :last-child {
        margin-bottom: 0;
    }​
    

    First/ last element can be any kind of element (h1, h2, …, p, div, span)

    DEMO

    Note that there is a space between aside and first-child/ last-child. Without it, the styling would apply to the first/ last aside.


    If there will be more levels in the aside and propagation further down is not desirable, it is better to use

    aside > :first-child {
        margin-top: 0;
    }
    ​aside > :last-child {
        margin-bottom: 0;
    }​
    

    in order to select just the direct children of the aside.

    Propagation vs. no propagation demo (of course, margin won’t apply to inline elements such as span, em, or strong – it was just to show how propagation works.)


    Support: As Ben Dyer has pointed out, last-child is a CSS3 pseudo-class. It is not supported by IE8 or older. Also, first-child is buggy in IE8 and 7.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create JSF table which has select all button and check box
I want to create a simple gsp page which will have an input box
I want to create a form which has a text entry box where a
I want to create a GUI in which the combo-box allows me to open
I have three problems: I want to create resizable shapes with box bounding... I
Is there any way to create a css box-shadow in which regardless of the
i want to create message box which must be seen on current screen(Ex i
I want to create a dialog box which contain four button yes no yes
I want to create Dialog box which can show form where i can refresh
I want to create a warning dialog box which asks the users if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.