css 箭头作为前后伪元素
css arrows as a before and after pseudo element
在我下面的代码中,我有两个箭头指向我的 SoMe div,只要页面未调整大小,箭头就会附在边框上。
调整大小时,它会变成箭头和边框之间的 space。
我希望我可以将箭头添加为前后伪元素,而不是使用媒体查询。但是当将箭头 类 更改为 div.front-some:before
和 div.front-some:after
.
时,我还没有使箭头出现
这有可能实现吗,还是媒体查询是我唯一的选择?
body {
background: green;
}
h1.title {
color: red;
text-align: center;
text-transform: uppercase;
letter-spacing: 20px;
background: green;
max-width: 70%;
margin: -40px auto 0 auto;
}
div.inner {
border: 4px solid red;
color: #fff;
padding: 15px 50px 50px 50px;
margin-top: 100px;
box-sizing: content-box;
}
div.some {
text-align: center;
background: green;
max-width: 40%;
margin: 0 auto -60px auto;
}
.arrow-right {
border-right: 5px solid red;
border-bottom: 5px solid red;
width: 25px;
height: 25px;
transform: rotate(-45deg);
margin-bottom: -25px;
margin-left: 26.5%;
}
.arrow-left {
border-left: 5px solid red;
border-top: 5px solid red;
width: 25px;
height: 25px;
transform: rotate(-45deg);
margin-top: 37px;
margin-right: 26.5%;
float: right;
}
<div class="inner">
<h1 class="title">Hello World</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<br>
<div class="arrow-right"></div>
<div class="some"> SoMe
</div>
<!-- .social-icons -->
<div class="arrow-left"></div>
</div>
如果没有content: ''
,伪选择器将不会出现。
尝试以下操作。将出现红色箭头。
.arrow-left:before {
border-left: 5px solid red;
border-top: 5px solid red;
width: 25px;
content: '';
height: 25px;
transform: rotate(-45deg);
margin-top: 37px;
margin-right: 26.5%;
float: right;
}
像这样?
body {
background: green;
}
h1.title {
color: red;
text-align: center;
text-transform: uppercase;
letter-spacing: 20px;
background: green;
max-width: 70%;
margin: -40px auto 0 auto;
}
div.inner {
border: 4px solid red;
color: #fff;
padding: 15px 50px 50px 50px;
margin-top: 100px;
box-sizing: content-box;
}
div.some {
text-align: center;
background: green;
max-width: 40%;
margin: 0 auto -60px auto;
position: relative;
}
div.some::before {
content: '';
position: absolute;
left: 0;
top: 50%;
display: block;
border-right: 5px solid red;
border-bottom: 5px solid red;
width: 25px;
height: 25px;
transform: translate(-50%, -50%) rotate(-45deg);
}
div.some::after {
content: '';
position: absolute;
right: 0;
top: 50%;
display: block;
border-left: 5px solid red;
border-top: 5px solid red;
width: 25px;
height: 25px;
float: right;
transform: translate(50%, -50%) rotate(-45deg);
}
<div class="inner">
<h1 class="title">Hello World</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<br>
<div class="some"> SoMe
</div>
</div>
在我下面的代码中,我有两个箭头指向我的 SoMe div,只要页面未调整大小,箭头就会附在边框上。
调整大小时,它会变成箭头和边框之间的 space。
我希望我可以将箭头添加为前后伪元素,而不是使用媒体查询。但是当将箭头 类 更改为 div.front-some:before
和 div.front-some:after
.
这有可能实现吗,还是媒体查询是我唯一的选择?
body {
background: green;
}
h1.title {
color: red;
text-align: center;
text-transform: uppercase;
letter-spacing: 20px;
background: green;
max-width: 70%;
margin: -40px auto 0 auto;
}
div.inner {
border: 4px solid red;
color: #fff;
padding: 15px 50px 50px 50px;
margin-top: 100px;
box-sizing: content-box;
}
div.some {
text-align: center;
background: green;
max-width: 40%;
margin: 0 auto -60px auto;
}
.arrow-right {
border-right: 5px solid red;
border-bottom: 5px solid red;
width: 25px;
height: 25px;
transform: rotate(-45deg);
margin-bottom: -25px;
margin-left: 26.5%;
}
.arrow-left {
border-left: 5px solid red;
border-top: 5px solid red;
width: 25px;
height: 25px;
transform: rotate(-45deg);
margin-top: 37px;
margin-right: 26.5%;
float: right;
}
<div class="inner">
<h1 class="title">Hello World</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<br>
<div class="arrow-right"></div>
<div class="some"> SoMe
</div>
<!-- .social-icons -->
<div class="arrow-left"></div>
</div>
如果没有content: ''
,伪选择器将不会出现。
尝试以下操作。将出现红色箭头。
.arrow-left:before {
border-left: 5px solid red;
border-top: 5px solid red;
width: 25px;
content: '';
height: 25px;
transform: rotate(-45deg);
margin-top: 37px;
margin-right: 26.5%;
float: right;
}
像这样?
body {
background: green;
}
h1.title {
color: red;
text-align: center;
text-transform: uppercase;
letter-spacing: 20px;
background: green;
max-width: 70%;
margin: -40px auto 0 auto;
}
div.inner {
border: 4px solid red;
color: #fff;
padding: 15px 50px 50px 50px;
margin-top: 100px;
box-sizing: content-box;
}
div.some {
text-align: center;
background: green;
max-width: 40%;
margin: 0 auto -60px auto;
position: relative;
}
div.some::before {
content: '';
position: absolute;
left: 0;
top: 50%;
display: block;
border-right: 5px solid red;
border-bottom: 5px solid red;
width: 25px;
height: 25px;
transform: translate(-50%, -50%) rotate(-45deg);
}
div.some::after {
content: '';
position: absolute;
right: 0;
top: 50%;
display: block;
border-left: 5px solid red;
border-top: 5px solid red;
width: 25px;
height: 25px;
float: right;
transform: translate(50%, -50%) rotate(-45deg);
}
<div class="inner">
<h1 class="title">Hello World</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<br>
<div class="some"> SoMe
</div>
</div>