围绕内联编号圈出

时间:2017-11-21 17:52:01

标签: html css sass

我试图在这样的数字周围创建一个圆形边框: enter image description here

但到目前为止,我所有的尝试都产生了一个椭圆形:

enter image description here

Codepen to see it live 到目前为止的SCSS代码

$browser-context: 16;

@function em($pixels, $context: $browser-context) {
    @return #{$pixels/$context}em;
}

body {
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: 'PT Sans', sans-serif;
    background: #e5dde1;
}

ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.header-nav {
    background-color: #ff4c61;
    color: white;
    font-family: 'Oswald', sans-serif;
}

.category-nav ul {
  background-color: #212d5b;
  color: #ff4c61;
  display: flex;
  justify-content: space-evenly;
}

.category-nav a {
  font-size: em(34);  
  text-decoration: none;
}

.category-nav .circled {
      border-radius: 50%;
      width: em(12);
      height: em(12);
      padding: em(4);
      border: em(1) solid #ff4c61;
}

HTML:

<header class="header-nav">
  <h1> APP</h1>
</header>
<nav class="category-nav">
  <ul>
    <li><a href="#">A</a></li>
    <li><a href="#">B</a></li>
    <li><a href="#">C <span class="circled">3</span></a></li>
  </ul>
</nav>

到目前为止,我一直在尝试不同的解决方案,我认为问题主要来自于数字的容器是内联元素(span)的事实。每当我将类.circled转换为div而不是将显示设置为阻塞时,我会得到一个完美的圆圈但是数字被推出并且它会破坏弹性布局。我想知道是否有办法让圆圈与跨度一起工作?

3 个答案:

答案 0 :(得分:3)

对于colors.html课程,您需要添加以下样式:

.circled

答案 1 :(得分:2)

你可以把它变成一个内联块。将此添加到您的示例中对我有用:

  display: inline-block;
  line-height: em(12);
  text-align: center;

答案 2 :(得分:0)

检查this答案以获取更多信息

&#13;
&#13;
$browser-context: 16;
@function em($pixels, $context: $browser-context) {
  @return #{$pixels/$context}em;
}

body {
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: 'PT Sans', sans-serif;
  background: #e5dde1;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.header-nav {
  background-color: #ff4c61;
  color: white;
  font-family: 'Oswald', sans-serif;
}

.category-nav ul {
  background-color: #212d5b;
  display: flex;
  justify-content: space-evenly;
}

.category-nav a {
  color: #ff4c61;
  font-size: em(34);
  text-decoration: none;
}

.category-nav .circled {
  border-radius: 50%;
  width: em(12);
  height: em(12);
  padding: em(4);
  border: em(1) solid #ff4c61;
}

.numberCircle {
  display: inline-block;
  border-radius: 50%;
  behavior: url(PIE.htc);
  /* remove if you don't care about IE8 */
  width: 1em;
  height: 1em;
  padding: auto;
  background: transparent;
  border: 2px solid red;
  color: red;
  text-align: center;
  font: 20px Arial, sans-serif;
}
&#13;
<header class="header-nav">
  <h1> APP</h1>
</header>
<nav class="category-nav">
  <ul>
    <li><a href="#">A</a></li>
    <li><a href="#">B</a></li>
    <li><a href="#">C <div class="numberCircle">3</div></a></li>
  </ul>
</nav>
&#13;
&#13;
&#13;

相关问题