CSS : Styling the content of before pseudo element on a list
Asked Answered
A

2

9

I'm trying to style an ordered list (no dot, a border with radius and rotate 45°)

<div class="test">
  <ol>
    <li><span>it's a test</span></li>
    <li><span>and again</span></li>
  </ol>
</div>

And the css

.test ol {
  counter-reset: li;
  list-style-type: none;
}
.test ol > li {
  position:relative;
  list-style:none;
}
.test ol > li:before {
  content:counter(li);
  counter-increment:li;

  position:absolute;
  top:-2px;
  left:-24px;
  width:21px;

  color:#E2202D;
  font-weight:bold;
  font-family:"Helvetica Neue", Arial, sans-serif;
  text-align:center;
  border: 1px dashed #E2202D;
  -webkit-border-radius:6px;
  border-radius:6px;
  -webkit-transform: rotate(45deg);
}

It give me that

And this is here i'm blocking... How to rotate the border without rotate the number inside ? How to style the content of a pseudo element in css ?

Thanks for any advice :)

Affianced answered 10/2, 2012 at 10:52 Comment(0)
C
8

There's no way to rotate the border and text separately. Instead, you can split the number and the border into two different pseudo-elements, :before and :after.

See: http://jsbin.com/agotuj/54/edit

.test ol {
    counter-reset: li;
    list-style-type: none;
}
.test ol > li {
    position: relative;
    list-style: none;
    margin-bottom: 20px;
    padding-left: 5px;
}
.test ol > li:before, .test ol > li:after {
    position: absolute;
    top: -2px;
    left: -24px;
    width: 21px;
    height: 21px;
    line-height: 21px;
    font-size: 16px;
}
.test ol > li:before {
    content: counter(li);
    counter-increment: li;
    color: #E2202D;
    font-weight: bold;
    font-family: "Helvetica Neue", Arial, sans-serif;
    text-align: center;
}
.test ol > li:after {
    content: '';
    border: 1px dashed #E2202D;
    border-radius: 6px;
    -webkit-transform: rotate(45deg);
       -moz-transform: rotate(45deg);
        -ms-transform: rotate(45deg);
         -o-transform: rotate(45deg);
            transform: rotate(45deg);
}
Constitution answered 10/2, 2012 at 11:9 Comment(4)
you beat me from few seconds :)Dawson
PLEASE, don't forget the W3C standard syntax for transform! Not only WebKit browsers support it. Even IE9 supports it with -ms-.Falbala
@IlyaStreltsyn: Yes, I agree. It's not in my answer already because it wasn't in the OP's code which I simply copied. I would have approved your edit had I seen it in time. Anyway, I fixed it.Constitution
I can't wait till the day prefixes become obsolete.Thales
D
-3
{"data":{"error":"HTTP Access is disabled. Requests must use SSL (HTTPS)."},"success":false,"status":400}
Dorri answered 1/10, 2017 at 15:9 Comment(1)
Absolutely non relevant as an answer and should be deleted.Jeremiahjeremias

© 2022 - 2024 — McMap. All rights reserved.