我有一条带有白色半圆和双线文字的条纹,它应该在圆圈和条纹内侧。但它超越了国界。如果我将 span 应用于这些div,则不会发生任何变化。我该如何解决这个问题?
HTML
<div class="summarize">
<div class="top-button">
<span class="half-circle"></span>
<div>First line</div>
<div>Second line</div>
</div>
</div>
CSS
.summarize {
background-color: #B7B7B7;
}
.top-button {
height: 10vh;
}
.half-circle {
background: white;
height: 100%;
width: 20%;
border-radius: 00px 50px 50px 0px;
display: flex;
align-items: center;
}
答案 0 :(得分:3)
只需将float: left;
提交给.half-circle
.half-circle {
background: white;
height: 100%;
width: 20%;
border-radius: 00px 50px 50px 0px;
display: flex;
align-items: center;
float: left;
}
<强> Working Fiddle 强>
答案 1 :(得分:1)
虽然添加float: left;
的答案肯定有效,但这里有一个使用flexbox的选项。
我更喜欢flexbox的原因是因为它可以更容易正确对齐。
.summarize {
background-color: #B7B7B7;
}
.top-button {
height: 50px;
display: flex;
flex-direction: row;
align-items: center;
}
.half-circle {
background: #F0F0F0;
height: 100%;
width: 20%;
border-radius: 00px 50px 50px 0px;
display: block;
}
.text {
flex: 1;
padding-left: 15px;
}
.text span {
display: block;
}
<div class="summarize">
<div class="top-button">
<div class="half-circle"></div>
<div class="text">
<span>line 1</span>
<span>line 2</span>
</div>
</div>
</div>
答案 2 :(得分:1)
使用少量标记实现所需目标的一种方法是使用绝对定位的pseudo-element,如下所示:
div{
background-color:#b7b7b7;
height:10vh;
padding-left:calc(20% + 10px);
/* Left padding should be at least the same width as the pseudo-element - I added 10px to create some space between it and the content */
position:relative;
}
div::before{
background:#fff;
border-radius:0 50px 50px 0;
bottom:0;
content:"";
left:0;
position:absolute;
top:0;
width:20%;
}
/** Add the following if you want to center the children vertically in the parent **/
div{
align-content:center;
display:flex;
flex-wrap:wrap;
}
p{
flex:0 0 100%;
}
/** Presentational stuff for this Snippet **/
*{box-sizing:border-box;font-family:sans-serif;margin:0;padding:0;}
div{border:1px solid #999;margin:10px;}
<div>
<p>First line</p>
<p>Second line</p>
</div>
答案 3 :(得分:1)
你没有正确使用flex,也没有在正确的位置使用。
如果你制作了一个圆圈和一个容纳文本sibbling的容器,它将很容易起作用:
.summarize {
background-color: #B7B7B7;
}
.top-button {
height:3em;/* vh might not be the best idea ... */
display: flex;
align-items: center;
}
.half-circle {
background: white;
height: 100%;
width: 20%;
border-radius: 00px 50px 50px 0px;
}
p {
margin: 0;
}
&#13;
<div class="summarize">
<div class="top-button">
<span class="half-circle"></span>
<div>
<p>
First line</p>
<p>
Second line</p>
</div>
</div>
</div>
&#13;
https://jsfiddle.net/Loj4Lgkq/4/
增加容器高度?
.summarize {
background-color: #B7B7B7;
}
.top-button {
height:10em;/* vh might not be the best idea ... */
display: flex;
align-items: center;
}
.half-circle {
background: white;
height: 100%;
width: 20%;
border-radius: 00px 50px 50px 0px;
}
p {
margin: 0;
}
&#13;
<div class="summarize">
<div class="top-button">
<span class="half-circle"></span>
<div>
<p>
First line</p>
<p>
Second line</p>
</div>
</div>
</div>
&#13;
答案 4 :(得分:0)