如何申请:悬停在:在CSS中的某个div之后

时间:2014-12-09 15:41:40

标签: javascript jquery html css html5

进行深入搜索,了解如何创建一些时尚的自定义文本框,以获得更好的图形外观。我有两个问题需要完成这个文本框的网格化,以便它们能够提供普通文本框的完整功能。

  1. 我无法执行:关注父div容器,虽然CSS中的代码非常好,因为当通过 Inspect Element(Chrome)时,强制元素到大于:专注它做我想做的事,但在实时它从来没有点击它的孩子或自己。
  2. 我想在子div容器(左侧黑色div )中添加:hover 效果,在该容器中展开:在转换一定数量的像素后(假设+ 20px / + 30px )。
  3. 所需和最终结果应如下图所示: Custom textfield issues

    #submitForm {
        border:2px grey inset;
        border-radius:10px;
        display:table;
        margin: 10px auto 0;
        height: 500px;
        position:relative;
        width: 800px;
    }
    #submitForm #btnSend {
        bottom:20px;
        display:block;
        height: 50px;
        position:absolute;
        right: 20px;
        width:100px;
    }
    #submitForm .highlights {
        border-bottom:5px solid #2E8DEF;
        border-radius:15px;
        float:left;
        height: 45px;
        margin-top: 40px;
        margin-left:40px;
        width: 520px;
    }
    #submitForm .highlights:focus {
        border-bottom:none;
        outline: 0;
        -webkit-box-shadow: 0px 0px 6px 2px rgba(105, 185, 250, 0.8);
        -moz-box-shadow: 0px 0px 6px 2px rgba(105, 185, 250, 0.8);
        box-shadow: 0px 0px 6px 2px rgba(105, 185, 250, 0.8);
    }
    #submitForm .tags, #submitForm .textarea {
        float:left;
        font-size: 25px;
        font-family: calibri;
        font-style: italic;
        height: 40px;
        position:absolute;
        text-align: center;
    }
    #submitForm .tags {
        border-bottom-left-radius: 10px;
        border-top-left-radius: 10px;
        background: #333333;
        color: #2E8DEF;
        height:40px;
        padding-top:5px;
        text-align: center;
        width: 120px;
        z-index:3;
    }
    #submitForm .tags:after {
        background: #333333;
        content:" ";
        display: block;
        left: 90px;
        height: 100%;
        position:absolute;
        top: 0;
        width: 30%;
        z-index:-1;
        transform-origin: bottom left;
        -ms-transform: skew(-30deg, 0deg);
        -webkit-transform: skew(-30deg, 0deg);
        transform: skew(-30deg, 0deg);
    }
    #submitForm .tags:hover {
        text-shadow: #2E8DEF 0px 0px 5px;
    }
    #submitForm .tags:after:hover {
        /* Code for expanding the skewed  .tags:after */
    }
    #submitForm .textarea {
        background-color:#F0F0F0;
        border-top-right-radius: 10px;
        border-bottom-right-radius: 10px;
        margin-left: 120px;
        overflow: hidden;
        padding-top: 5px;
        width: 400px;
        appearance: field;
        -moz-appearance: field;
        -webkit-appearance: field;
    }
    #submitForm .textarea:focus {
        outline:0;
    }
    
    <forms id='submitForm'>
        <div id='formName' class='highlights'>
            <div class='tags'>Name</div>
            <div class='textarea' contenteditable></div>
        </div>
        <div id='formSurname' class='highlights'>
            <div class='tags'>Surname</div>
            <div class='textarea' contenteditable></div>
        </div>
        <div id='formAddress'class='highlights'>
            <div class='tags'>Address</div>
            <div class='textarea' contenteditable></div>
        </div>
        <div id='formCity' class='highlights'>
            <div class='tags'>City</div>
            <div class='textarea' contenteditable></div>
        </div>
        <div id='formPhone' class='highlights'>
            <div class='tags'>Phone</div>
            <div class='textarea' contenteditable></div>
        </div>
        <button id="btnSend" type="button" onclick='submitListOfProducts()'>Submit</button>
    </forms>
    

    并且,JS小提琴的链接: http://jsfiddle.net/xa3nwhj4/1/

2 个答案:

答案 0 :(得分:2)

Vishal提供了悬停效果不起作用的原因 - 这是我对它的补充: - 只关注textarea的焦点,但你想改变父div的风格

所以我们可以将#submitForm .highlights:focus的css条目更改为#submitForm .focusedhighlights

然后让jquery做魔术:

$(".textarea").focus(function(){ //event handler, to fire when a textarea gets focused
    $(this).parent().toggleClass("focusedhighlights") //toggle class on parent element for highlight effect
});

$(".textarea").focusout(function(){ //event handler to fire, when textarea gets unfocused
    $(this).parent().toggleClass("focusedhighlights") // toggle class to remove highlight effect
});

在此处查看工作小提琴:http://jsfiddle.net/vo59rgnd/2/

答案 1 :(得分:1)

:focus无效,因为您要将焦点添加到.highlights <div>而不是input element

并扩展onhover。 CSS应该是这样的

#submitForm .tags:hover {
    text-shadow: #2E8DEF 0px 0px 5px;
    width:160px;
}
#submitForm .tags:hover:after {
    left:130px;
}

请参阅此处的演示:http://jsfiddle.net/Lrdmuzu6/