php - 选择文本框时如何更改div的css属性

标签 php html css authentication forum

<分区>

我已经尝试了一段时间,想弄清楚如何更改使用 php 函数调用的登录面板的不透明度。在 css 中,我已经在 css 中尝试过了

.container
{
    background: #FFF;
    opacity: 0.6;
    width: 320px;
    height: 500px;
    align-content: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    padding: 30px 30px;
    transition: 0.3s;
}
.container:hover
{
    opacity: initial;
    transition: 0.3s;
}
.container input[type="text"]:focus .container
{
    opacity: initial;
    transition: 0.3s;
}

当输入被聚焦时改变 .container 元素的不透明度 但它不起作用有什么办法可以解决这个问题 顺便说一句,输入是这样的形式

<div class="container">
            <form action="validatelogin.php" method="POST">
                <p>Username:</p>
                <input type="text" name="usernameinput" id="usernameinput" />
                <p>Password:</p>
                <input type="Password" name="passwordinput" id="passwordinput" />
                <br />
                <div style="margin-top:10px;">
                    <input type="submit" value="Login" />
                    <button type="button" onclick="location.href=\"register.html\";">Register</button>
                </div>
            </form>
        </div>        

最佳答案

https://jsfiddle.net/97py6vgj/23/是我的解决方案。当我在容器上检测到 mousedown 时,我刚刚使用了 jQuery。为了更改 css,我使用了 .css() 方法。然后,我做了一个技巧,你可以检测到元素外部的点击,并使其恢复正常。您可以相应地对其进行编辑。

我将在此处添加代码段。

var stay = 0;
$('input').mousedown(function() {
	$(".container").css("opacity", "initial");
  stay = 1;
});
$(window).mousedown(function () {
    $('.container').css("opacity", "0.6")
    stay = 0;
});
 
$('.container').mousedown(function (event) {
    
    event.stopPropagation();
});
$('.container').mouseenter(function() {
  $(this).css("opacity", "initial");
  $(this).css("transition", "0.3s");
});
$('.container').mouseleave(function() {
  if(stay == 0) {
  $(this).css("opacity", "0.6");
  $(this).css("transition", "0.3s");
  } else {$(this).css("opacity", "initial");}
});
.container
{
    background: #FFF;
    opacity: 0.6;
    width: 320px;
    height: 500px;
    align-content: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    padding: 30px 30px;
    transition: 0.3s;
}
.container input[type="text"]:focus .container
{
    opacity: initial;
    transition: 0.3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
            <form action="validatelogin.php" method="POST">
                <p>Username:</p>
                <input type="text" name="usernameinput" id="usernameinput" />
                <p>Password:</p>
                <input type="Password" name="passwordinput" id="passwordinput" />
                <br />
                <div style="margin-top:10px;">
                    <input type="submit" value="Login" />
                    <button type="button" onclick="location.href=\'register.html\';">Register</button>
                </div>
            </form>
        </div>

我不确定这是否是您想要的,但您来了。

关于php - 选择文本框时如何更改div的css属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50185427/

上一篇:html - 绝对位置 div 不工作 css

下一篇:html - 某些 css 样式表未加载

相关文章:

jquery - 滚动(鼠标触摸边框时向左/向右)行为类似于 Windows 8,但使用 jQuery

css - 带有相邻 Div 的假 CSS 插入(从上方和下方)

php - 将 DateTime 转换为 Date Doctrine php

javascript - 创建了一个选项卡但点击后无法正常工作 - jQuery 问题/新手

javascript - 如何验证股市数据

php - 如何向客户发送 WooCommerce 新订单电子邮件?

CSS 代码在 Firefox 和 IE 中不起作用

html - 具有基于视口(viewport)高度的最大高度的元素。图像内应缩放并保持比例

php - 在关联(数组)上找到 Doctrine\Common\Collections\ArrayCollection 类型的实体,但期待(其他)

javascript - 提交表单后无法检索 POST 数据