html – 如何创建一个与css重叠的圆和条?

前端之家收集整理的这篇文章主要介绍了html – 如何创建一个与css重叠的圆和条?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对于用户配置文件,我正在尝试创建一个圆形图像以及一个与图像高度相同的水平条.此外,它应该是响应.它应该如下图所示.在黑色栏中会有文字.

有人可以用正确的CSS帮助我吗?到目前为止,我有下面的代码,但这已经出错,因为黑条位于圆圈下方而不是旁边.但我也不知道如何让黑条准确地从图像中间开始,将图像放在顶部,并使黑条中的文字充分向右开始(同时响应屏幕尺寸) .

  1. <div class="col-md-12 profile-topbar">
  2. <div class="round">
  3. <img src=<%= image_path('profile.gif') %>>
  4. </div>
  5. <div class="text-bar">
  6. ...
  7. </div>
  8. </div>

在我的CSS文件中:

  1. .round {
  2. margin: 2em;
  3. border-radius: 50%;
  4. overflow: hidden;
  5. width: 150px;
  6. height: 150px;
  7. -webkit-border-radius: 50%;
  8. -moz-border-radius: 50%;
  9. Box-shadow: 0 0 8px rgba(0,.8);
  10. -webkit-Box-shadow: 0 0 8px rgba(0,.8);
  11. -moz-Box-shadow: 0 0 8px rgba(0,.8);
  12. }
  13. .round img {
  14. display: block;
  15. width: 100%;
  16. height: 100%;
  17. }
  18.  
  19. .text-bar {
  20. display: inline-block;
  21. background: #FFF;
  22. left: 222px; //Problem: not responsive. This block should start exactly halfway from the image.
  23. width: 100%;
  24. }
  25. .text-bar p {
  26. left: 250 px;
  27. }

解决方法

你可以使用figure和figcaption来构建你的html.

内联块,垂直对齐和边距将文本设置为文本

  1. figure {
  2. margin-left:50px;/* half image width */
  3. background:black;
  4. Box-shadow:0 0 1px;
  5. border-radius:3px;
  6. }
  7. img {
  8. border-radius:100%;
  9. position:relative;/* brings it at front,can trigger z-index too */
  10. Box-shadow:-1px 0 1px,1px 0 1px white ;/* whatever U like */
  11. vertical-align:middle;
  12. right:50px;/* move visually from real position */
  13. margin-right:-40px;/* pull or push text aside */
  14. }
  15. figcaption {
  16. display:inline-block;
  17. vertical-align:middle;
  18. color:white;
  19. }
  20. p {
  21. margin:0;
  22. }
  1. <figure>
  2. <img src="http://lorempixel.com/100/100/people/9" />
  3. <figcaption>
  4. <p>some text here 10px away from image</p>
  5. <p>and more</p>
  6. </figcaption>
  7. </figure>

猜你在找的HTML相关文章