How could I center a div that is inside a div? Auto margins aren't working

user3026860

Website where the issue exists When you login ( username: male / Password: male ), you see a sidebar at the right side. I've tried everything I can but i can't center the column of buttons on the right side. If you Inspect Element you can see that i set margin-left and margin-right to auto but it simply doesn't work. How could I center the class "optionsWrapper" in class "options"? Also how would i make class"options"'s height as long as the window? I have it at 100% right now but when i test it, its height is either too long or too short depending on the screen size that views the site.

Note: It looks somewhat okay on Chrome but on Firefox and Safari it looks abysmal and I have no idea why. Any help would really be appreciated!

HTML Setup:

      <div class='options'>
          <div class='optionsWrapper'>
              <div class='toggleButton' id='white'>
              </div>

              <div class='toggleButton'  id='yellow'>
              </div>

              <div class='toggleButton'  id='green'>
              </div>

              <div class='toggleButton'  id='red'>
              </div>

              <div class='toggleButton'  id='blue'>
                <a href="https://www.google.com/"><img class='settings_icon' src="Icons/Set 1/PNG/7.png"></a>
              </div>
          </div>
      </div>

CSS Setup:

.options{
  float: right;
  width: 100px;
  height: 100%;
  background: #444444 url("http://nickbrombal.com/images/bg_pixel-grey.jpg") repeat fixed;
  padding-top: 1.2%;
}

.optionsWrapper {
margin-left:auto;
margin-right:auto;
top: 50%;
position: absolute;
transform: translate(25%, -50%);
}

.toggleButton{
  width: 100%;
  height: 66px;
  margin-bottom: 30px;
  -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px;
  cursor: pointer;
}
Guffa

I only see half of a green button. (Testing in Firefox.)

Remove the height style from the .options rule, then remove the position, top and transform styles from the .optionsWrapper rule. Now the buttons show up at least.

The reason that the auto margins doesn't seem to work is that the buttons take up the whole width of the parent, so while the margins actually work, dividing up zero in two equal parts is still zero. If you specify a width for the buttons, for example width: 65px, you see that they are centered.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I horizontally center a span element inside a div

分類Dev

How do I center text inside of a div with Foundation?

分類Dev

How can I center a div inside another div, what is the simplest way?

分類Dev

How to center input-group inside a div?

分類Dev

center text inside rotated div

分類Dev

Why doesn't overflow auto not working in div element?

分類Dev

How to vertically and horizontally center two images inside a div on a responsive page

分類Dev

How to align <div> to center?

分類Dev

How to make vertical auto scrolling image inside div?

分類Dev

Inside div my scroll bar is showing but can't use it (not working)

分類Dev

css div won't center

分類Dev

center vertically div inside bootstrap grid

分類Dev

Trying to center a rotated text inside a floated div

分類Dev

Center element inside div and over other content

分類Dev

How can i center a div in a parallax background image

分類Dev

How do I center this horizontal list within a fixed div?

分類Dev

How do I center an element within a div with another element nearby?

分類Dev

How could I store caret position in an editable div?

分類Dev

Flexbox auto margins don't work with justify-content: center in IE

分類Dev

How can I fade in and then fade out text inside a <div>

分類Dev

How do i make PHP echo only inside div?

分類Dev

How to Auto-Expand an IFrame in a DIV element when user clicks inside it?

分類Dev

How to position a div with equal margins for left, right, and top

分類Dev

javascript not working to create divs inside of another div

分類Dev

Animate scroll to hash inside div not working

分類Dev

Last-Child inside div not working

分類Dev

Flexbox does not vertically center div inside table cell

分類Dev

Easy way to center ANYTHING inside of a <div> to the very middle of the page

分類Dev

Bootstrap: How to center a p Element vertically in a div?

Related 関連記事

  1. 1

    How do I horizontally center a span element inside a div

  2. 2

    How do I center text inside of a div with Foundation?

  3. 3

    How can I center a div inside another div, what is the simplest way?

  4. 4

    How to center input-group inside a div?

  5. 5

    center text inside rotated div

  6. 6

    Why doesn't overflow auto not working in div element?

  7. 7

    How to vertically and horizontally center two images inside a div on a responsive page

  8. 8

    How to align <div> to center?

  9. 9

    How to make vertical auto scrolling image inside div?

  10. 10

    Inside div my scroll bar is showing but can't use it (not working)

  11. 11

    css div won't center

  12. 12

    center vertically div inside bootstrap grid

  13. 13

    Trying to center a rotated text inside a floated div

  14. 14

    Center element inside div and over other content

  15. 15

    How can i center a div in a parallax background image

  16. 16

    How do I center this horizontal list within a fixed div?

  17. 17

    How do I center an element within a div with another element nearby?

  18. 18

    How could I store caret position in an editable div?

  19. 19

    Flexbox auto margins don't work with justify-content: center in IE

  20. 20

    How can I fade in and then fade out text inside a <div>

  21. 21

    How do i make PHP echo only inside div?

  22. 22

    How to Auto-Expand an IFrame in a DIV element when user clicks inside it?

  23. 23

    How to position a div with equal margins for left, right, and top

  24. 24

    javascript not working to create divs inside of another div

  25. 25

    Animate scroll to hash inside div not working

  26. 26

    Last-Child inside div not working

  27. 27

    Flexbox does not vertically center div inside table cell

  28. 28

    Easy way to center ANYTHING inside of a <div> to the very middle of the page

  29. 29

    Bootstrap: How to center a p Element vertically in a div?

ホットタグ

アーカイブ