响应式CSS圈,可以容纳居中的内容

时间:2013-01-12 13:22:27

标签: html css css3 responsive-design geometry

我正在寻找一种方法来创建一个可以保持居中内容的响应式CSS3圈 关于这个圈子,我在this question找到了一些不错的信息。太糟糕了,似乎无法将内容集中在这个内容中。

This question也非常类似于我的,尽管它是一个应该居中的图像。在我的情况下使用背景图像不是一个选项,所以这个选项对我来说也不起作用。

你有什么想法我怎么能接近这个?
当然我可以使用图像,但CSS会更优雅!

3 个答案:

答案 0 :(得分:5)

纯CSS需要许多额外的包装

更新:原始发布(我删除)错过了您正在寻求响应式设计的事实。 Building upon my answer for the responsive circles question you reference似乎适用于所有CSS3浏览器see fiddle

HTML (需要五个级别的包装器,我只在这个html中显示一个圆圈)

<div class="circles">
    <div>
      <div>
        <div>
          <div>
            <!-- BEG Content -->
            All types of content (see fiddle)
            <!-- END Content -->
          </div>
        </div>
      </div>
    </div>
    <!-- ditto the above 3 more times -->
</div>

<强> CSS

.circles{
    margin:0px auto;
}
.circles > div {
    overflow:hidden;
    float:left;
    width:auto;
    height:auto;
    position: relative;
    border-radius:50%;
    -moz-border-radius:50%;
    -webkit-border-radius:50%;
    -khtml-border-radius: 50%;
    background:#eee;
}

.circles > div > div {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}
.circles > div > div > div {
    display: table;
    width: 100%;
    height: 100%;
}
.circles > div > div > div > div {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}

@media (max-width: 320px)
{
    .circles > div {padding: 50%;}
}

@media (min-width: 321px) and (max-width: 800px)
{
    .circles > div {padding: 25%;}
}

@media (min-width: 801px)
{
    .circles{width:800px}
    .circles > div {padding: 12.5%;}
}

答案 1 :(得分:1)

如果内容的高度是固定的并且您需要CSS方法,请使用以下属性应用于cicle内部的内容

margin: auto; /*will center the element*/
position: relative;
top: 50%;
margin-top: - [here insert the height of the element if you know in advance / 2]px

答案 2 :(得分:1)

接受的答案对我不起作用,因为我想旋转圆圈。 这样做:

HTML

<div class="mycircle">
  <div class="mycontent">
    <span>TEXT</span>
  </div>
</div>

CSS

.mycircle {
  width: 30%; 
  height: 0;
  padding: 15% 0; //padding top & bottom must equal width 
  border-radius: 50%;
  -moz-border-radius: 50%; 
  -webkit-border-radius: 50%; 
  background: #dedede; 
}
.mycontent {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  text-align: center;
}
.mycontent:before {
  content: '';
  vertical-align: middle;
  display: inline-block;
  width: 0;
  height: 100%;
}

.mycontent span {
  vertical-align: middle;
  display: inline-block;
}