css - CSS 内容之前在“BOX”之外
问题描述
有些东西我不明白。
当我创建一个例子时
<style>
.vorher{
text-align: center;
border: 1px solid red;
max-width: 100px;
margin-left: auto;
margin-right: auto;
}
.vorher:before{
content: "\2192";
}
</style>
<div class="row">
<div class="half">
<p id="button1" class="vorher"><a href="#">Some Text</a>
</p>
</div>
<div class="half">
<p id="button2" class="vorher"><a href="#">Some Text</a>
</p>
</div>
</div>
.row {
width: 100%;
display: flex;
}
.half {
width: 50%;
border: 1px solid green;
}
.vorher {
text-align: center;
border: 1px solid red;
max-width: 100px;
margin-left: auto;
margin-right: auto;
}
.vorher:before {
content: "\2192";
}
<div class="row">
<div class="half">
<p id="button1" class="vorher"><a href="#">Some Text</a>
</p>
</div>
<div class="half">
<p id="button2" class="vorher"><a href="#">Some Text</a>
</p>
</div>
</div>
但箭头总是在盒子里。如何移动盒子的箭头,让他粘在红色盒子的左边框上?
我知道这是一个非常基本的问题,但我无法让它工作
解决方案
您可以使用transform: translate
绝对定位:
.row {
position: relative;
width: 100%;
display: flex;
}
.half {
position: relative;
width: 50%;
border: 1px solid green;
}
.vorher {
position: relative;
text-align: center;
border: 1px solid red;
max-width: 100px;
margin-left: auto;
margin-right: auto;
}
.vorher:before {
position: absolute;
left: 0;
transform: translateX(-100%);
content: "\2192";
}
<div class="row">
<div class="half">
<p id="button1" class="vorher"><a href="#">Some Text</a>
</p>
</div>
<div class="half">
<p id="button2" class="vorher"><a href="#">Some Text</a>
</p>
</div>
</div>
推荐阅读
- c# - Bittrex API V3 无效的 API 密钥
- ios - 将自定义 NSLayoutManager 添加到在 Storyboard 中创建的 UItextView
- python - Pyyaml 未正确读取(非 ascii)字符(“§”)
- javascript - 如何使用复选框显示和隐藏段落
- javascript - 我如何在 react-native 中翻转图像?
- c++ - 使用 apt-get 安装时 Boost Testing 编译错误
- csv - 从 GAN 模型导出到 CSV
- javascript - 将table1中的列名和编号复制到table2
- github - 我可以直接在 Github 上编辑 html 文件吗(在我的浏览器上,而不是桌面上)?
- typescript - 在 TypeScript 中获取类型键