开开心心happyheart 2023-04-01 03:33 采纳率: 81.8%
浏览 13
已结题

关于#html#的问题:CSS在from表单中失效

CSS文件

/* 按钮样式 */
.btn {
  font-size: 17px;
  background: transparent;
  border: none;
  padding: 1em 1.5em;
  color: #ffedd3;
  border-radius: .5rem;
  text-transform: uppercase;
  position: relative;
  transition: .5s ease;
}

/* 按钮前置元素 */
.btn::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 0;
  background-color: #00f0ff;
  transition: .5s ease;
}

/* 鼠标悬停时按钮样式 */
.btn:hover {
  color: #1e1e2b;
  transition-delay: .5s;
}

/* 鼠标悬停时按钮前置元素 */
.btn:hover::before {
  width: 100%;
}

/* 按钮后置元素 */
.btn::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 0;
  width: 100%;
  background-color: #ff0000;
  border-radius: .5rem;
  transition: .4s ease;
  z-index: -1;
}

/* 鼠标悬停时按钮后置元素 */
.btn:hover::after {
  height: 100%;
  transition-delay: 0.4s;
  color: aliceblue;
}

HTML文件(from表单前)

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="stylesheet" type="text/css" href="./btn属性.css">
</head>
<body>
<button id="likeBtn" class="btn" onclick="like()">
点赞
</button>
</body>

这样可以正常运行CSS。
HTML(from表单后)

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="stylesheet" type="text/css" href="./btn属性.css">
</head>
<body>
<form action="http://127.0.0.1:610/" target="_blank" method="POST">
<input type="button" name="text" value="点赞" class="btn" onclick="like()">
</form>
</button>
</body>

这下CSS就失效了。
有谁可以解决嘛?

  • 写回答

1条回答 默认 最新

  • 夜郎king 2022博客之星IT其它领域TOP 12 2023-04-01 08:45
    关注

    失效是什么情况?如果是因为加了form的原因,可以在样式前面加上form的修饰,表示作用于form下面的btn

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月16日
  • 已采纳回答 4月8日
  • 创建了问题 4月1日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效