【问题标题】:Creating responsive circle borders in CSS and/or jQuery在 CSS 和/或 jQuery 中创建响应式圆形边框
【发布时间】:2015-04-30 00:36:20
【问题描述】:

我今天从我们的设计师那里得到了一份 PSD,其布局如下:

他们希望包含 3 个均匀分布的圆圈,它们也必须具有响应性。到目前为止,我尝试过的所有解决方案都失败了。

我现在的代码如下:

CSS(从 SCSS 编译)

 .section2 .info-box {
    float: left;
    display: block;
    margin-right: 10.1484%;
    width: 26.56773%; }
    /* line 89, /Users/chriswatson/.rvm/gems/ruby-2.1.5/gems/neat-1.7.2/app/assets/stylesheets/grid/_span-columns.scss */
    .section2 .info-box:last-child {
      margin-right: 0; }
    @media screen and (max-width: 992px) {
      /* line 84, /Users/chriswatson/Sites/nuvi-website/source/stylesheets/index.css.scss */
      .section2 .info-box {
        float: left;
        display: block;
        margin-right: 38.19821%;
        width: 100%;
        margin-bottom: 40px;
        background-color: rgba(250, 250, 250, 0.1);
        padding: 15px; }
        /* line 89, /Users/chriswatson/.rvm/gems/ruby-2.1.5/gems/neat-1.7.2/app/assets/stylesheets/grid/_span-columns.scss */
        .section2 .info-box:last-child {
          margin-right: 0; } }
    /* line 94, /Users/chriswatson/Sites/nuvi-website/source/stylesheets/index.css.scss */
    .section2 .info-box img {
      height: 90px;
      margin-bottom: 20px; }
    /* line 99, /Users/chriswatson/Sites/nuvi-website/source/stylesheets/index.css.scss */
    .section2 .info-box h2 {
      font-size: 1.2em; }
    /* line 103, /Users/chriswatson/Sites/nuvi-website/source/stylesheets/index.css.scss */
    .section2 .info-box p {
      font-size: 18px; }

HTML

<div class="full-width">
        <h1>A Comprehensive Solution</h1>
        <div class="info-box">
          <div class="circle">
            <img src="/images/timer.png" alt="timer" />
            <h2>Real-Time</h2>
            <p>NUVI monitors 12 social networks and nearly 4 million RSS feeds in over 20 languages in Real Time.</p>
            <button class="learn-more">Learn More</button>
          </div>
        </div>
        <div class="info-box themiddleone">
          <div class="circle">
            <img src="/images/multi-monitors.png" alt="monitors" />
            <h2>Visualizations</h2>
            <p>Beautiful visualizations and dashboards make it easy to see actionable insights.</p>
            <button class="learn-more">Learn More</button>
          </div>
        </div>
        <div class="info-box">
          <div class="circle">
            <img src="/images/server.png" alt="server" />
            <h2>Reporting</h2>
            <p>Beautiful visualizations and dashboards make it easy to see actionable insights.</p>
            <button class="learn-more">Learn More</button>
          </div>
        </div>
    </div>

我怎样才能让这些圆圈如上图所示?

【问题讨论】:

  • 也许您可以详细说明如何您希望它响应?
  • 在这种情况下,特别是如果您收到 PSD 格式的设计并希望与旧版浏览器兼容,我通常建议使用圆圈的图像。我会让它们成为一个只有圆圈本身的背景图像,其他一切都是透明的
  • 使用弹性盒子和justify-content: space-around
  • 这不是纯 CSS BTW。要么发布 CSS,要么用 less、sass 或其他任何东西更新问题标签。

标签: javascript jquery html css


【解决方案1】:

你可以用视口单位做到这一点

body {
  text-align: center;
}
div {
  width: 20vw;
  height: 20vw;
  margin: 2vw;
  border-radius: 50%;
  background: red;
  border: 1px solid grey;
  display: inline-block;
}
<div></div>
<div></div>
<div></div>

【讨论】:

  • 我正在努力使用% 值创建圈子。但是您使用了view port 单位的非常有创意的解决方案。在这种情况下,使用remem 将不起作用。
【解决方案2】:

这是您需要的 CSS(大约)。当然,您必须根据您需要的规范进行媒体查询,但这只是一个示例。并在 jsfiddle 中对其进行测试,您可以扩大和缩短视图窗口以查看它的变化:

 .info-box {
    display: inline-block;
    width: 29.5%;
    height: auto;
    border: 1px solid #FFF;
       padding: 100px;

}
.circle img {
    height: 70vh;
    margin-bottom: 20px;
    border-radius:50%;

}

@media screen and (max-width: 800px){
    .circle img{
       height: 40vh;   
    }
}

DEMO

【讨论】:

  • 你使用不同的不同单位;例如vhpx%。请保持一致。
  • 好的,我明白你的意思,但有时使用不同的单位是有原因的。有时您希望它基于视口的百分比,有时您希望它基于父级的百分比......因此不同的单位。在这种情况下,是的,这有点草率,但出于这个原因,我确实在自己的东西中使用了不同的单位。
  • 好吧,我没有同时使用这么多单位。大部分时间我使用%em
  • 是的,这就是为什么我说我理解样本可能有点太多了...诚然马虎...但您也必须知道有不同的单位是有原因的。它们的含义不同,交互方式也不同。所以请记住这一点。
猜你喜欢
  • 2016-06-14
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 2018-02-12
  • 2021-03-10
  • 2015-05-16
  • 2020-10-24
  • 2020-03-03
相关资源
最近更新 更多