【问题标题】:Text is not rotating with button文本不随按钮旋转
【发布时间】:2015-08-14 09:19:09
【问题描述】:

我需要在按钮旋转的同时旋转文本。由于某种原因,当我将鼠标悬停在按钮上时,文本当前正在消失。文本不应消失;它应该与我在这个项目中使用 Chrome 的按钮一起旋转。

http://codepen.io/matosmtz/pen/oXBaQE

HTML

<body>
  <div class = "container">
    <section class="3d-button">
      <h2>Animated Button</h2>
      <p class="btn_perspective">
        <button class="btn btn-3d btn-3da">Submit</button>
      </p>
    </section>
  </div>
</body>

CSS

html, body {
    font-size: 100%;
    padding: 0;
    margin: 0;
    height: 100%;
    border: 0;
}

body {
    font-family: Lekton;
    background: rgb(245,245,245);
}

a {
    color: #888;
    text-decoration: none;
}

.container {
    padding: 0;
    margin: 0;
    height: 100%;
    background: #fff;
    position: relative;
}

.container > section {
    margin: 0 auto;
    padding: 6em 3em;
    text-align: center;
}

h2 {
    margin: 20px;
    text-align: center;
    text-transform:uppercase;
    letter-spacing: 1px;
    font-size: 2em;
}

.btn {
    border:none;
    position: relative;
    background: rgb(245,245,245);
    padding: 15px 40px;
    display: inline-block;
    text-transform: uppercase;
    margin: 15px 30px;
    color: inherit;
    letter-spacing: 2px;
    font-size: .9em;
    outline: none;
    -webkit-transition: all 0.4s;
    transition: all 0.4s;
    cursor: pointer;
}

.btn:after {
    content: "";
    position: absolute;
    z-index: -1;
    -webkit-transition: all 0.4s;
    transition: all 0.4s;
}

.btn_perspective {
    -webkit-perspective: 800px;
    perspective: 800px;
    display: inline-block;
}

.btn-3d {
    display: block;
    background: #5cbcf6;
    color: white;
    outline: 1px solid transparent;
    transform-style: preserve-3d;
}

.btn-3d:active {
    background: #55b7f3;
}

.btn-3da:after {
    width: 100%;
    height: 42%;
    left: 0;
    top: -40%;
    background: #53a6d7;
    transform-origin: 0% 100%;
    transform: rotateX(90deg);
}

.btn-3da:hover {
    transform: rotateX(-45deg);
}

【问题讨论】:

  • 你的 codepen 不工作
  • 这很奇怪!我只是仔细检查了它,它工作正常。该按钮应在悬停时旋转并在悬停时返回其原始状态。
  • 顺便说一下,代码被定制为只能在谷歌浏览器上运行。
  • 您是否正在寻找这样的解决方案(适用于所有主要网络浏览器):infosoft.biz
  • 最终我希望它可以在所有浏览器上运行,但我省略了所有使其与其他浏览器兼容的代码,因为我目前正在使用 Chrome 进行原型设计。我将添加代码以使其立即与 Mozilla 一起使用。

标签: html css


【解决方案1】:

这是更新后的代码笔:http://codepen.io/anon/pen/KpaGYd

将以下代码添加到您的按钮:

.btn-3da:after {
 z-index:1;
}

.btn-3da:hover {
  position:relative;
  z-index:2;
}

【讨论】:

    【解决方案2】:

    您可以看看这个纯 CSS3 解决方案(适用于所有主要网络浏览器:DEMO):

    /*ROTATE*/
    .divRotate 
    {
        -moz-transition     : all 0.8s;
        -webkit-transition  : all 0.8s;
        -o-transition       : all 0.8s;
        transition          : all 0.8s;
    }
    .divRotate:hover 
    {
    
        -moz-transform      : rotate(360deg);
        -webkit-transform   : rotate(360deg);
        -o-transform        : rotate(360deg);
        transform           : rotate(360deg);
    }
    

    将 div 元素添加到您的 HTML 并引用 class = 'divRotate'

    希望这可能会有所帮助。最好的问候,

    【讨论】:

    • 嗨,Alex,您的解决方案在 2D 空间中旋转图像;但是,我正在尝试在 3D 空间中旋转图像。
    • 是的,没错。以防万一,你有一个替代版本。最好的问候,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    相关资源
    最近更新 更多