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 7559127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:33:25+00:00 2026-05-30T12:33:25+00:00

This question pops up in my mind form time to time, but since the

  • 0

This question pops up in my mind form time to time, but since the workaround is so simple I have never bothered taking the time to investigate it further. Today I thought I’d see what Stack Overflow has to say on the matter.

Let’s say I have this:

/* Selector setting up shared properties for some elements */ 
#header, #main, #footer {
    margin: 0 5%;
}

Now assume I would like to override margin-top and margin-bottom of #header. Off the top of my head I usually would do margin: 1em 0; (forgetting about the preceding rule), but that will of course also override margin-right and margin-left. What I would like is a way to specify that a certain value of a shorthand property should not change at all, is that possible? These are the options I have come to think of:

#header {
    margin: 1em 0; /* Will remove left/right margin */
    margin: 1em auto; /* Will revert to default left/right margin */
    margin: 1em inherit; /* Will inherit left/right margin from parent */
    margin: 1em no-change; /* This is what I'm after: shorthand property to set only 2 of 4 values */

    /* And this is how I end up solving it */
    margin-top: 1em;
    margin-bottom: 1em;
}
  • 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-05-30T12:33:26+00:00Added an answer on May 30, 2026 at 12:33 pm

    This isn’t currently possible, unfortunately. You’ll have to stick with assigning margin-top and margin-bottom respectively.

    A shorthand property always changes the values of all its component (longhand) properties. Namely, any values omitted in a shorthand property will default to initial for their respective properties, unless resolved by cascading or by some other rules depending on the shorthand property. For example, the following results in auto margins on all sides except the bottom due to the margin-bottom longhand that appears after the shorthand:

    #header {
        /* 
         * Note: this is short for margin: auto auto auto auto;
         * none of the longhands are set to initial! Different shorthands
         * have different rules, but a shorthand always changes the values
         * of all its longhands.
         */
        margin: auto;
        margin-bottom: 1em;
    }
    

    If there were separate shorthands for horizontal margins and vertical margins, you would be able to do this without having to worry about keeping specific longhand values, but no such shorthands exist at the moment.

    As I mentioned in my comment, margin: 1em inherit is invalid as the CSS-wide keywords inherit (along with initial and others introduced in later standards) may only appear by themselves in property declarations, and this includes shorthand declarations. Even if margin: 1em inherit did work, the element would inherit horizontal margins from its parent element, and not from its own cascade (since that’s not what inheritance means). It is not possible to retrieve a cascaded or specified value for a property on a given element, and being able to do this would almost certainly be error-prone due to the fact that the bottommost declaration from the most specific selector that contains the resolved value could be anywhere.

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

Sidebar

Related Questions

Okay this may seem too simple of a question but I've wasted enough time
Alright, I presented this question on the MSDN forums but have yet to receive
hopefully this is a simple question. In the JQGrid form edit mode, the edit
This question seems to have been asked before, but I feel like my situation
This question was very helpful, however I have a list control in my report,
Ok, I know this seems like a duplicate question, but don't think it is.
This sounds like a trivial question, but it's proved quite hard to google anything
This is a follow-up to my earlier question I have written a script which
I imagine that this question pops up every now and then (I actually read
Ok this is a continuation from this question: How to make a simple Hello

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.