Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

html - How to have social media handle to the right side of icon?

Pretty new to working with CSS and was trying to figure out ideas of what to do to have the span, which is acting the as the social media handle/label associated with the icon to be to the right side of the social media icon? I am trying to have the handle to be on the right side of the icon and to be in the center vertically as well if that makes sense. I tried playing around with the float attribute with the span, but that did not help much. My code pen is a very small snippet of what rest of the code is on purpose to achieve the small task I have in mind. I am keeping the social media icon(s) to be vertically aligned on purpose.

.pic {
  display: flex;
  align-items: center;
  width: 30px;
  height: 30px;
}
<div>
  <a href="https://www.facebook.com/joebiden/" >
    <img class="pic" src="https://i.pinimg.com/originals/b7/63/69/b763699fd1fa3bfb374442593ae642e1.png"/> 
    <span>Facebook Handle </span>
  </a>
</div>
question from:https://stackoverflow.com/questions/65840816/how-to-have-social-media-handle-to-the-right-side-of-icon

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should use display: flex; with row direction on the container of the two items (img and span).

Here's the code piece you can add to your stylesheet

a {
    display: flex;
    flex-direction: row;
    align-items: center;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...