最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Margin-Right on css not Working - Stack Overflow

programmeradmin3浏览0评论

I have been messing with Coding during school because it interests me the most out of anything at school, and have been self-teaching myself Html-Css-and Js for most of the school year.

I have been re-creating my school's website, and I have run into some problems.

My CSS "Margin-Right" mand has not been working. I have been trying to center a <Div> area with CSS and the "Style" mand using margin left and right, and the right will never work.
I don't want to just use the position: absolute; mand because I want some space on the side so you can see the background.
Here is my Html code.

CSS:

    .Isaac {
      width: 100%;
      padding: 4px;
      margin-right:100px;
      background-color: white;
      -webkit-box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4);
      -moz-box-shadow: 0px 2px 12px rgba(23, 69, 88, .5);
      -webkit-border-radius: 100px;
      -moz-border-radius: 100px;
      border-radius: 10px;
    }

HTML:

  <div class="Isaac" Style="Background-color: #E6E6E6 ; Margin-Top: 40px">
      <!-- div content -->
  </div>

Edit: The "100x" thing was just a silly error on my part, I meant to have "100px"
Also, I changed Margin-Right: 100x ; to margin-right:100px; and it still have no difference
I hope you can help me

I have been messing with Coding during school because it interests me the most out of anything at school, and have been self-teaching myself Html-Css-and Js for most of the school year.

I have been re-creating my school's website, and I have run into some problems.

My CSS "Margin-Right" mand has not been working. I have been trying to center a <Div> area with CSS and the "Style" mand using margin left and right, and the right will never work.
I don't want to just use the position: absolute; mand because I want some space on the side so you can see the background.
Here is my Html code.

CSS:

    .Isaac {
      width: 100%;
      padding: 4px;
      margin-right:100px;
      background-color: white;
      -webkit-box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4);
      -moz-box-shadow: 0px 2px 12px rgba(23, 69, 88, .5);
      -webkit-border-radius: 100px;
      -moz-border-radius: 100px;
      border-radius: 10px;
    }

HTML:

  <div class="Isaac" Style="Background-color: #E6E6E6 ; Margin-Top: 40px">
      <!-- div content -->
  </div>

Edit: The "100x" thing was just a silly error on my part, I meant to have "100px"
Also, I changed Margin-Right: 100x ; to margin-right:100px; and it still have no difference
I hope you can help me

Share Improve this question edited Apr 25, 2016 at 12:59 Mr Lister 46.6k15 gold badges113 silver badges155 bronze badges asked Apr 21, 2016 at 17:58 Isaac SybrandyIsaac Sybrandy 531 silver badge4 bronze badges 7
  • It would be easier if you copy the relevant codes and paste it here, that way we don`t have to skim through all the code you have in your link. Provide us with the CSS portion that's giving you issues and the HTML as well. – yardie Commented Apr 21, 2016 at 18:01
  • What is 100x? Also, try without capitalized initials. – ForceMagic Commented Apr 21, 2016 at 18:02
  • @IsaacSybrandy - for a start, your mands should look like this: margin-right:100px; not Margin-Right: 100x ; The big difference here is the px. Take some time and review the CSS section on w3schools. – yardie Commented Apr 21, 2016 at 18:05
  • 2 So you've been self-teaching yourself ? If so, could I self-teach you not to capitalize any property in CSS ? – Eduard Commented Apr 21, 2016 at 18:06
  • Question edited with irrelevant codes removed. @IsaacSybrandy Impressive work for a 13 year old bro. Keep learning and you might just end up even earning from this as you grow older. And yeah, as mentioned above, avoid capitalising css properties as that is not semantic. – AndrewL64 Commented Apr 21, 2016 at 18:09
 |  Show 2 more ments

3 Answers 3

Reset to default 3

Change:

Margin-Right: 100x;

to:

margin-right: 100px;

The problem is the width:100% on the .Isaac divs. This causes the divs themselves to be as wide as their parent, the body. Then the margins extend to the right of that, off screen.

Solution: remove the width:100%.

    
    .Isaac {
      /*width: 100%;*/
      padding: 4px;
      Margin-Right: 100px;
      background-color: white;
      -webkit-box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4);
      -moz-box-shadow: 0px 2px 12px rgba(23, 69, 88, .5);
      -webkit-border-radius: 100px;
      -moz-border-radius: 100px;
      border-radius: 10px;
    }

    .myButton {
      -moz-box-shadow: inset 0px 5px 0px 0px #000000;
      -webkit-box-shadow: inset 0px 5px 0px 0px #000000;
      box-shadow: inset 0px 1px 0px 0px #000000;
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #ffffff));
      background: -moz-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: -webkit-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: -o-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: -ms-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: linear-gradient(to bottom, #ffffff 5%, #ffffff 100%);
      filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff', GradientType=0);
      background-color: #ffffff;
      -moz-border-radius: 3px;
      -webkit-border-radius: 3px;
      border-radius: 3px;
      border: 1px solid #000000;
      display: inline-block;
      cursor: pointer;
      color: #000000;
      font-family: Arial;
      font-size: 13px;
      padding: 6px 24px;
      text-decoration: none;
      text-shadow: 0px 1px 0px #000000;
    }
    
    .myButton:hover {
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #ffffff));
      background: -moz-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: -webkit-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: -o-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: -ms-linear-gradient(top, #ffffff 5%, #ffffff 100%);
      background: linear-gradient(to bottom, #ffffff 5%, #ffffff 100%);
      filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff', GradientType=0);
      background-color: #ffffff;
    }
    
    .myButton:active {
      position: relative;
      top: 1px;
    }

/* I added this, because the body start tag doesn't appear in the snippet */
body {
  background-attachment: fixed; background-repeat: no-repeat; Background-size: 100% 100%; background-image:url(https://upload.wikimedia/wikipedia/mons/3/32/Mount_Rainier_from_above_Myrtle_Falls_in_August.JPG)
    }
  <div class="Isaac" Style="Background-color: #E6E6E6;  Margin-Top: 40px"><img src="http://www.conway.k12.wa.us/sites/default/files/logov4.png" style="width:150px;height:50px;"><a href="#" class="Hello">Menu</a> : <a href="#" class="Hello">Family access</a> : <a href="#" class="Hello"> Facebook/Social Media<a/> : <a href="#" class="Hello"><br><a href="#" class="MyButton">District Office</a>
    <a
    href="#" class="myButton">School Office</a><a href="#" class="myButton">Departments</a><a href="#" class="myButton">Staff</a><a href="#" class="myButton">Family</a><a href="#" class="myButton">Teachers</a><a href="#" class="myButton">Board</a></div>

use text-align center for aligning your contents to center

  • issue with margin-right was you use : x instead of px

    .Isaac { width: 100%; padding: 4px; text-align: center; margin-right: 100px; background-color: white; -webkit-box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4); -moz-box-shadow: 0px 2px 12px rgba(23, 69, 88, .5); -webkit-border-radius: 100px; -moz-border-radius: 100px; border-radius: 10px; }

Hope this is what you want to achieve

发布评论

评论列表(0)

  1. 暂无评论