圆形div计算宽度不正确导致不是圆形

时间:2016-11-05 21:52:34

标签: html css twitter-bootstrap-3 media-queries

我有一些圆形div(使用大的border-radius),并且使用媒体查询在不同的屏幕尺寸上它们的大小不同。但是,在某些媒体查询大小上,宽度无法正确启动。例如,这里是一个超小设备的屏幕截图:

enter image description here

图像显示宽度和高度在css中设置为80px,但计算出的宽度为63px。

当我将屏幕拖得更宽时,我看到圆圈逐渐变得越来越宽,直到它们成为圆形,有点像“响应”div,而不是仅在某些宽度断点处改变大小的div。

这是一个jsfiddle:

http://jsfiddle.net/52VtD/15513/

如何让圆圈div始终为圆圈(宽度与高度相同)?

HTML:

                                                                                                                                                                                                                                                                                                                                         

的CSS:

#about-page {
    height: 100%;
    padding-top: 57px;
    width: 100%;
    overflow-y: auto;
    overflow-x: auto;
    min-height: 480px;
    justify-content: center;
    color: black;
    background-color: white;
}
#content-container {
    h1, h2, h3, h4, h5, h6 {
        text-align: center;
        text-transform: uppercase;
        font-weight: 200;
    }
}
.circle-container {
    display: inline-flex;
    margin-bottom: 40px;
    width: 100%;
    justify-content: center;
}
.circle {
    border-radius: 75px;
    border: 1px solid black;
    display: inline-flex;
}
/* xs */

@media only screen and (min-width: 320px) {
    .circle {
        height: 80px;
        width: 80px;
        margin: 5px;
    }
}
/* s */

@media only screen and (min-width: 544px) {
    .circle {
        height: 110px;
        width: 110px;
        margin: 5px;
    }
}
/* m */

@media only screen and (min-width: 768px) {
    .circle {
        height: 120px;
        width: 120px;
        margin: 8px;
    }
}
/* L */

@media(min-width:992px) {
    .circle {
        height: 130px;
        width: 130px;
        margin: 10px;
    }
}
/* xl */

@media only screen and (min-width: 1200px) {
    .circle {
        height: 150px;
        width: 150px;
        margin: 10px;
    }
}

1 个答案:

答案 0 :(得分:1)

您正在使用flexbox(特别是inline-flex),因此默认情况下,圆圈会缩小以适合容器元素。为防止出现这种情况,请设置flex-shrink: 0flex: 0 0 auto;以防止此行为。

.circle {
  border-radius: 75px;
  border: 1px solid black;
  display: inline-flex;
  flex: 0 0 auto;
}

http://jsfiddle.net/52VtD/15520/