html - How can make the 2nd line of text align with the 1st line while using a pseudo element?
问题描述
I have some buttons with text on them that drop down text when they are clicked. The buttons have a pseudo element before the text. It looks good on desktop view but when I view it in mobile, the text wraps down to two lines and the second line falls under the pseudo element. I am hoping to get that second line to align with the start of the first line. Here is a picture of what is happening:
.accordion:before {
content: url(../images/new-star.png);
font-size: 15px;
margin: 0 10px 15px 5px;
vertical-align: middle;
font-size: 30px;
display: inline-block;
height: 35px;
}
<button class="accordion"><span class="button-text">Click here to see more info on this topic</span></button>
<div class="panel">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dicta, incidunt unde. Placeat aspernatur impedit deleniti atque minima commodi, fuga quasi id voluptatum ipsum sit modi doloremque tempore debitis molestias asperiores! Alias quibusdam voluptatem porro recusandae fugiat ut atque reprehenderit in ipsa natus, dolorum, repellendus quo! Corporis deleniti aliquid cumque esse.
</p>
</div>
解决方案
You can make your button flex:
.accordion {
display: flex;
align-items:center; /* optional - horizontally centres the text or icon */
}
.accordion:before {
content: url(../images/new-star.png);
font-size: 15px;
margin: 0 10px 15px 5px;
vertical-align: middle;
font-size: 30px;
display: inline-block;
height: 35px;
}
.button-text {
flex-grow: 1; /* make text fill rest of space, don't really need this */
text-align: left;
}
<button class="accordion"><span class="button-text">Click here to see more info on this topic</span></button>
<div class="panel">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dicta, incidunt unde. Placeat aspernatur impedit deleniti atque minima commodi, fuga quasi id voluptatum ipsum sit modi doloremque tempore debitis molestias asperiores! Alias quibusdam voluptatem
porro recusandae fugiat ut atque reprehenderit in ipsa natus, dolorum, repellendus quo! Corporis deleniti aliquid cumque esse.
</p>
</div>
推荐阅读
- html - 试图让 CSS 托管在 Google 网站上以用于 eBay 列表
- awk - 使用地理位置数据搜索“motorway_junction”点并创建带有描述的配置文件(awk)
- flutter - 如何在 Flutter 中将照片添加到 PDF
- spring-boot - 在 Spring Boot 中使用外部化配置进行 junit 测试的不同 YAML 配置文件
- google-cloud-functions - Google Pubsub - 接收推送订阅的传递尝试
- c - 如何将 portaudio 录制的样本写入不同的文件?
- php - POST filter_input_array & 非特定的多维数组
- python-3.x - 如何按属性分组并计算该属性的连续票证之间的时间
- java - 跟踪用户输入的整数的最大值和最小值
- docker - 恢复 docker swarm 集群