将<div>附加到另一个<div> </div> </div>的水平中心

时间:2014-02-16 17:09:17

标签: javascript jquery html css

我正在尝试创建一个在用户滚动时更改位置的小菜单。我为这个风格做了一件事 - http://jsfiddle.net/piedoom/S8tyn/

正如您所看到的,点会附加到每个文本<div>元素,它看起来像这样。 enter image description here

然而,这看起来非常难看。如何将每个文本div下方的每个点居中?我尝试过像text-align: center这样的事情无济于事。

3 个答案:

答案 0 :(得分:1)

使用margin: auto的css样式将子div居中。

http://jsfiddle.net/S8tyn/1/

答案 1 :(得分:0)

只需将你的风格改为下一个

.unselectedcircle
{
  background: grey;
  position: relative; 
  top: 32px;
  border-radius: 100%;
  width: 10px;
  height: 10px;
  margin: 0 auto;
}

Demo

答案 2 :(得分:0)

以下是您的问题的答案: 左侧和左侧边距

.unselectedcircle
{
background: grey;
position: relative; 
top: 32px;
border-radius: 100%;
width: 10px;
left:50%;
margin-left:-5px;
height: 10px;
}

updated link