我想将内容放在星形符号内。发现它很难只使用css而不是svg。我试过这样的:https://css-tricks.com/examples/ShapesOfCSS/但它不起作用。 一种方法是使用SVG,但他们很难响应,因为我需要在那里有额外的jquery/js功能。 所以想知道是否有其他方法来实现这一点。形状符号内的内容/数字
1
A
回答
2
您可以使用clip path(Clippy是一个很好的生成器)创建星号,并使用伪元素垂直对齐文本。
注意:DOM元素上的剪辑路径目前仅支持Chrome,Firefox及其移动版本。
.star {
height: 100px;
width: 100px;
-webkit-clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
text-align: center;
background: red;
color: white;
}
.star::before {
display: inline-block;
height: 100%;
background: blue;
vertical-align: middle;
content: '';
}
<div class="star">100</div>
1
你可以包装在一个容器中的明星与一些flexbox
性质。添加您的内容,并使用position: absolute
使其居中......
- 代码星从css tricks
.wrapper {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
height: 100vh;
}
#star-five {
margin: 50px 0;
position: relative;
display: block;
color: red;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-moz-transform: rotate(35deg);
-webkit-transform: rotate(35deg);
-ms-transform: rotate(35deg);
-o-transform: rotate(35deg);
}
#star-five:before {
border-bottom: 80px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: '';
-webkit-transform: rotate(-35deg);
-moz-transform: rotate(-35deg);
-ms-transform: rotate(-35deg);
-o-transform: rotate(-35deg);
}
#star-five:after {
position: absolute;
display: block;
color: red;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-webkit-transform: rotate(-70deg);
-moz-transform: rotate(-70deg);
-ms-transform: rotate(-70deg);
-o-transform: rotate(-70deg);
content: '';
}
.wrapper span {
position: absolute;
color: white;
font-size: 48px;
}
<div class="wrapper">
<div id="star-five"></div>
<span>2</span>
</div>
1
<html>
<head>
<style>
#star-five {
margin: 50px 0;
position: relative;
display: block;
color: red;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-moz-transform: rotate(35deg);
-webkit-transform: rotate(35deg);
-ms-transform: rotate(35deg);
-o-transform: rotate(35deg);
}
#star-five:before {
border-bottom: 80px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: '';
-webkit-transform: rotate(-35deg);
-moz-transform: rotate(-35deg);
-ms-transform: rotate(-35deg);
-o-transform: rotate(-35deg);
}
#star-five:after {
position: absolute;
display: block;
color: red;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-webkit-transform: rotate(-70deg);
-moz-transform: rotate(-70deg);
-ms-transform: rotate(-70deg);
-o-transform: rotate(-70deg);
content: '';
}
#item {
margin-top: -75px;
left: 75px;
position: absolute;
}
</style>
</head>
<body>
<div>
<div id="star-five">
</div>
<div id="item">
ITEM
</div>
</div>
</body>
</html>
这部作品只是改变位置和操作保证金!
1
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.star{position:relative; display:inline-block;}
.star i{font-size:68px;}
.star-content{position: absolute;top: 37%; left: 37%; z-index: 999999; text-align: center; }
.star-content span{color: #fff;}
</style>
</head>
<body>
<div class="star">
<i class="fa fa-star" aria-hidden="true"></i>
<div class="star-content">
<span>01</span>
</div>
</div>
</body>
</html>
1
您可以将您的明星设置为Unicode字符,并使用绝对定位移动星号内的数字。在那里你可以设置CSS属性color
和font-size
使用颜色和字体大小。
.star {
font-size: 75px;
color: cornflowerblue;
position: relative;
display: inline-block;
}
.star:after {
content: "1";
font-size: 16px;
color: white;
display: inline-block;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -20%);
}
<div class="star">★</div>
+0
不错,但问题是我想要动态操作数字,并将其用于DOM页面,而不是在star中设置为内容属性:在classname之后。 –
+0
@NikolaNoxiousDimitrov你可以在这里交换星号:) Star可以驻留在内容中。数字将是'.star'的'innerText'。如果你需要它可以发布示例。 –
相关问题
- 1. android形状内的形状
- 2. 将括号内的字符串与括号中的内容分开vs对比括号中的内容
- 3. 将无符号字符数组的内容分成两半
- 4. 删除字符串中括号内的内容
- 5. 字符串拆分并保留引号内的内容“” - Python
- 6. Rsync符号链接内容
- 7. css内容:X符号
- 8. 动画UIView形状及其内容
- 9. UITextfield内容验证(字母,数字和特殊标点符号)
- 10. 比较字符串数组内容与内容的EditText
- 11. 两个asp:web内容形式的内容
- 12. 更改字符的内容*
- 13. 符号文字内的空格字符
- 14. 更改形状内的字体ppt
- 15. ng-map。文字内的形状?
- 16. 显示字符串数组的内容
- 17. 只取数字括号内(括号内)
- 18. 在内容之间创建CSS形状分隔符
- 19. 如何删除特定字符或符号后的内容
- 20. 删除内容括号内
- 21. PHP simplexml_load_file和内容中的&符号(&)
- 22. preg_replace但@符号的所有内容
- 23. 显示'?'的Mysql内容'符号
- 24. 如果字符串包含括号,请检查括号内容
- 25. ShapeDrawable内的偏移形状
- 26. 使用字符串内容
- 27. 删除字符串内容
- 28. WPF:由字符串内容
- 29. 内容搜索字符串
- 30. 设置字符串内容
多少分,你想在你的星型? – weBBer