html - 在 div 旁边添加 Unicode

标签 html css

我在下面有一些数据的 CSS 代码,这些数据以 pill 的形式显示,我想要完成的是尝试在其中添加一个 Unicode 加号我的药丸类似于下图。

enter image description here

但是每当我尝试增加 Unicode 的 font-size 时,它只会弄乱整个文本和药丸的形状有没有办法让它看起来像上面的图像而不弄乱了太多的原始CSS?任何帮助将不胜感激。

var red = {};
var key = "Red Fruits";
red[key] = ['Apple', 'Cherry', 'Strawberry', 'Pomegranate', 'Rassberry'];

var redString = '';
$.each(red[key], function(index) {
  redString += ('<div class="pilldiv redpill class">' + red[key][index] + '</div>');
});
$('.redclass').html(redString);
.pilldiv {
    padding: 0px 19px;
    text-align: center;
    font-size: 14px;
    border-radius: 25px;
    color: Black;
    margin: 1px;
}
.redpill {
  background-color: Pink;
  cursor: default;
}

 .redpill:before {
    content: "\002B";
    font-size: 28px;
    width: 15px;
    vertical-align: baseline;
    margin-left: -7px;
}
.class {
  font-family: Open Sans;
}

.center {
  display: flex;
  justify-content: center;
}

.wrappingflexbox {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

h3 {
  font-weight: normal;
  color: White;
}

.panel {
  display: table;
  table-layout: fixed;
  height: 100%;
  width: 30%;
  background-color: black;
}

body {
  background-color: white;
}
<div class="center">
  <div class="panel">
    <div id="redid" class="redclass wrappingflexbox"></div>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

最佳答案

当您更改伪元素字体的实际大小时,它会相应地更改药丸的形状,因为药丸的大小由内容的大小决定。

因此,我建议您使用 transform 来更改字形的apparent 大小。

因为这是完全视觉的,所以它不会影响药丸的大小。

 .redpill:before {
    content: "\002B";
    /* font-size: 28px;*/ */ remove this */
    width: 15px;
    vertical-align: baseline;
    margin: 0 7px 0 -7px;
    display:inline-block; /* required */
    transform:scale(2); /* this*/
}

var red = {};
var key = "Red Fruits";
red[key] = ['Apple', 'Cherry', 'Strawberry', 'Pomegranate', 'Rassberry'];

var redString = '';
$.each(red[key], function(index) {
  redString += ('<div class="pilldiv redpill class">' + red[key][index] + '</div>');
});
$('.redclass').html(redString);
.pilldiv {
  padding: 0px 19px;
  text-align: center;
  font-size: 14px;
  border-radius: 25px;
  color: Black;
  margin: 1px;
}

.redpill {
  background-color: Pink;
  cursor: default;
}

.redpill:before {
  content: "\002B";
  /* font-size: 28px;*/
  */ remove this */ width: 15px;
  vertical-align: baseline;
  margin: 0 7px 0 -7px;
  display: inline-block;
  transform: scale(2)
}

.class {
  font-family: Open Sans;
}

.center {
  display: flex;
  justify-content: center;
}

.wrappingflexbox {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

h3 {
  font-weight: normal;
  color: White;
}

.panel {
  display: table;
  table-layout: fixed;
  height: 100%;
  width: 30%;
  background-color: black;
}

body {
  background-color: white;
}
<div class="center">
  <div class="panel">
    <div id="redid" class="redclass wrappingflexbox"></div>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

关于html - 在 div 旁边添加 Unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51058194/

相关文章:

html - Div 在 css 变换上与其他 div 重叠

html - 仅使用 CSS 在转换后隐藏元素

php - 如何在jquery中改变字体颜色

php - 如何在 php 中从数据库填充下拉值

html - 无法使 div 达到屏幕高度 100%

css - 当 div 是背景框时,如何禁用特定内部 div 标记的 css 类?

php - 随机背景图片导致登陆页面显示问题?

javascript - 如何引用日历表单中的输入日历弹窗?

javascript - 如何检查表的父类

css - 这个 nth-child 选择器在 IE 8 中如何工作?