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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:16:53+00:00 2026-05-29T06:16:53+00:00

Is this valid CSS to center the div and also apply a top margin?

  • 0

Is this valid CSS to center the div and also apply a top margin?

div {
     margin: 0 auto;
     margin-top: 30px;
     }
  • 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-29T06:16:54+00:00Added an answer on May 29, 2026 at 6:16 am

    Use the following to specify margins:

    div { margin: 30px auto 0; }
    

    Which is shorthand for:

    div { margin : 30px auto 0 auto; } /* margin: [top] [right] [bottom] [left]; */
    

    Which is shorthand for:

    div {
        margin-top: 30px;
        margin-right: auto;
        margin-bottom: 0;
        margin-left: auto;
    }
    

    Now that you know the different ways margins, and/or padding, can be specified; the choice is yours.

    As far a precedence is concerned the later definition will apply; as defined in the spec.

    To find the value for an element/property combination, user agents must apply the following sorting order:

    1. Find all declarations that apply to the element and property in question, for the target media type. Declarations apply if the associated selector matches the element in question.
    2. The primary sort of the declarations is by weight and origin: for normal declarations, author style sheets override user style sheets which override the default style sheet. For "!important" declarations, user style sheets override author style sheets which override the default style sheet. "!important" declaration override normal declarations. An imported style sheet has the same origin as the style sheet that imported it.
    3. The secondary sort is by specificity of selector: more specific selectors will override more general ones. Pseudo-elements and pseudo-classes are counted as normal elements and classes, respectively.
    4. Finally, sort by order specified: if two rules have the same weight, origin and specificity, the latter specified wins. Rules in imported style sheets are considered to be before any rules in the style sheet itself.

    Apart from the "!important" setting on individual declarations, this strategy gives author’s style sheets higher weight than those of the reader. It is therefore important that the user agent give the user the ability to turn off the influence of a certain style sheet, e.g., through a pull-down menu.

    As others have mentioned, you’ll likely need to specify a fixed width in order to see your div centered …

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

Sidebar

Related Questions

Is this valid css? Can the vertical bar be used like this? div{margin-left:1px !important;|
I keep getting an error like this: $(div.valid_box).html(data.message).css(margin-left, 145px).css(width, 520px).show().delay is not a function
Is this valid CSS for browser reset? What does it do? I have been
Possible Duplicate: What's the point of valid CSS/HTML? This is a over-asked question, but
My question below is: Is this a valid URL? https://example.com/css/login.css?12.1 My questions is basically
Is this valid and correct? RewriteRule ^myOldPage.html$ /index.php#info [R] I'm specifically interested about the
Is this valid: $_SESSION['pictures']['rateAlbum']['_POST'] = $_POST; I want to save all of the POST
Is this valid C++ (e.g. not invoking UB) and does it achieve what I
As you know the dash introduces a comment how can I make this valid?
Quick question, how can I make this valid : if($this->datos->bathrooms == 1½){$select1 = JText::_(

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.