简体   繁体   English

在另一个div中对齐一个div

[英]Aligning a div within another div

Ok here is my site http://joshadik307.github.io/ . 好的,这是我的网站http://joshadik307.github.io/ And here is the specific code I need help with 这是我需要帮助的特定代码

CSS: CSS:

.pagemenu {
 padding-top: 25px;
 padding-right: 2%;
 padding-left: 2%;
 text-align: center;
}
.bubblewrap {
 display: inline-block;
 vertical-align: top;
 width: 23%;
 margin-right: 5%;
 margin-left: 5%;
 text-align:center;
}
.bubble {
 background-color: white;
 border-radius: 50%;
 border-style: solid;
 border-width: 5px;
 border-color: black;
 width: 250px;
 height: 250px;
 display: inline-block;
}

HTML for one of the 5 circles (I figured it would save space to just show one, but they all use the same html and are all wrapped in the same pagemenu div) 5个圆圈之一的HTML(我认为这样做可以节省空间,只显示一个圆圈,但是它们都使用相同的html,并且都包裹在同一pagemenu div中)

   <div class = "pagemenu">

        <div class = "bubblewrap">

          <div class="bubble">
            <div class="text">
              <a href ="#aboutme">ABOUT</a>
            </div>

          </div>

        </div>
   </div>

Ok now here is the problem. 好了,这就是问题所在。 If you look at my sight (linked to above) basically I have 5 circle divs set up to align themselves in the shape of a W at the top of the page (under the header.) The problem is the W is not always center aligned on the page, and after looking at the source on chrome, I realized that this is because the "bubbles" are not always horizontally centered within the bubble wrapper. 如果您看一下我的视线(链接到上面),基本上我设置了5个圆形div,以使其在页面顶部(在页眉下方)以W的形状对齐。问题是W并不总是居中对齐在页面上,并查看了chrome的来源之后,我意识到这是因为“气泡”并不总是在气泡包装纸内水平居中。 Does anyone know how I can fix it so that the bubble div always aligns itself horizontally within the bubblewrapper div? 有谁知道我可以解决这个问题,以便气泡div始终在bubblewrapper div内水平对齐?

Add margin: auto; 增加margin: auto; into your .bubble class 进入您的.bubble

.bubble {
background-color: white;
border-radius: 50%;
border-style: solid;
border-width: 5px;
border-color: black;
width: 250px;
height: 250px;
margin: auto;
}

A margin:0 auto; 边距:0自动; to your .bubble class will do the fix :) 到您的.bubble类将解决此问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM