4

我正在尝试使用屏幕顶部选项卡的 css值将双尖括号设置为:after伪元素中的内容。以下是相关代码:transformrotate(90deg)

.header {
  -moz-transition: top .5s ease;
  -webkit-transition: top .5s ease;
  -o-transition: top .5s ease;
  transition: top .5s ease;
  position: absolute;
  left: 0;
  right: 0;
  top: -60px;
  height: 80px;
  background-color: #2d2;
}

.header.in-top {
  top: 0;
}

.header-tab {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 20px;
  text-align: center;
  color: #000;
  -moz-transition: color .5s ease;
  -webkit-transition: color .5s ease;
  -o-transition: color .5s ease;
  transition: color .5s ease;
}

.header-tab:hover {
  color: #e22;
}

.header-arrow:after {
  font-size: 20px;
  line-height: 1;
  -moz-transform: rotate(90deg);
  -webkit-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  -o-transform: rotate(90deg);
  transform: rotate(90deg);
}

.header .header-arrow:after {
  content: "\00bb";
}

.header.in-top .header-arrow:after {
  content: "\00ab";
}
<div class="header">
  <div class="header-tab" data-toggle="in-top">
    <span class="header-arrow"></span>
  </div>
</div>

data-toggle属性在 JavaScript 中用于切换in-top类,以切换双尖括号的方向,以及通过将标题下拉来显示标题的内容。我指定的transform属性似乎什么也没做。有什么解决办法吗?

4

3 回答 3

7

Use display: inline-block on the pseudo-element. Alternatively, inline-table or block should also work.

See jsFiddle.

Your pseudo-element is displayed inline by default, which makes it a nontransformable element. From the CSS Transforms Working Draft specification:

transformable element

A transformable element is an element in one of these categories: an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose ‘display’ property computes to ‘table-row’, ‘table-row-group’, ‘table-header-group’, ‘table-footer-group’, ‘table-cell’, or ‘table-caption’</p>

于 2013-08-15T04:15:33.157 回答
1

You need to set the pseudo-element as a block or inline-block element:

.header-arrow:after {
  display: block;
}

The specification says rotation should work on inline elements, but in WebKit based browsers it doesn't works: https://www.webkit.org/blog/130/css-transforms/

于 2013-08-15T04:15:44.157 回答
0

仅当您在类或选择器中使用display:inline-block;or属性时,旋转属性才会应用于伪元素(之后/之前) 。display:inline-block;

.className:before{
   -webkit-transform: rotateZ(180deg); /* Safari */
  transform: rotateZ(180deg); /* Standard syntax */
    display: inline-block;
}
于 2019-01-17T06:27:39.803 回答