【发布时间】:2021-07-24 09:53:04
【问题描述】:
我想使用 CSS 创建一个形状。我面临的唯一问题是半圆与矩形边框的对齐方式无法正常工作。 我附上了我到目前为止所做的事情的图像。谁能帮我解决这些对齐问题。谢谢。
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: white;
}
#talkbubble {
width: 120px;
height: 80px;
border: 4px solid #4C4C4C;
position: relative;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
#talkbubble:before {
content: "";
position: absolute;
top: 42%;
left: -11.6px;
width: 30px;
height: 15px;
border: 4px solid #4C4C4C;
border-bottom: none;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
background-color: white;
transform: rotate(90deg);
box-sizing: border-box;
}
#talkbubble:after {
content: "";
position: absolute;
top: 42%;
right: -12px;
width: 30px;
height: 15px;
border: 4px solid #4C4C4C;
border-bottom: none;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
background-color: white;
transform: rotate(270deg);
box-sizing: border-box;
}
<div id="talkbubble"></div>
【问题讨论】:
-
嗯,但是当我运行代码时我根本没有看到这个问题
-
@coder 如果你放大一点并检查半圆和矩形边框之间的对齐,你会看到它。您还会在其上看到浅色边框
-
尝试增加
::before和::after的宽度一点点,它对我有用