Achieving this hr element with CSS styling - pseudo elements

南楼画角 提交于 2019-12-17 20:33:21

问题


I'm having some difficulty finding a solution to style a hr element to my preference.

If you look at the following fiddle you will see the hr element has both :before and :after pseudos added to it.

http://jsfiddle.net/MattStrange/LGEjp/

So far this is what i want, both circles on either side is correct but now i want to add an image to the exact center of the line, but because both pseudos are taken up i'm not sure how to add a background image to this hr.

<hr class="bolt">
hr {
  border: 0 solid #eeedef;
  border-top-width: 1px;
  height: 0;
  margin-top: 60px;
  margin-bottom: 60px;
  float: left;
  clear: both;
  display: block;
  width: 100%;
  position: relative;
}
hr:before, hr:after {
  content: " ";
  width: 5px;
  height: 5px;
  position: absolute;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  border: 1px solid #e5e5e5;
  background-color: #fff;
}
hr:before {
  left: 0;
  bottom: -3px;
}
hr:after {
  bottom: -3px;
  right: 0;
}

Help very much appreciated.

Cheers


回答1:


You can use :

  1. one pseudo to draw the 2 rounds, first round is drawn with borders, the second is its shadow.
  2. another pseudo to bring in the image.

http://codepen.io/gcyrillus/pen/dHaus



来源:https://stackoverflow.com/questions/17182245/achieving-this-hr-element-with-css-styling-pseudo-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!