javascript - 将鼠标悬停在 div "rectange"上不起作用

标签 javascript html css

我有一个名为speech-bubble1的div,我想在其中放置一个悬停元素,它会扩大比例,但是它不起作用,我尝试过放置其他悬停属性,它们工作正常,请帮助我。

当我将鼠标悬停在对话气泡上时,我想缩放它。预先感谢您!

@import url("https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap");
:root {
  font-size: 16px;
  font-family: "Open Sans";
}

body {
  margin: 0;
  padding: 0;
  background-color: #191921;
  overflow: hidden; /* Hide scrollbars */
}

body::-webkit-scrollbar {
  width: 0.25rem;
}

body::-webkit-scrollbar-thumb {
  background: #43434f;
}

main {
  color: white;
  margin-left: 3rem;
  padding: 1rem;
}
.greetings h1 {
  padding: 0;
  margin: 0;
}
.text1 {
  position: relative;
  left: 90px;
  top: 250px;
  margin-left: 0;
  padding: 0;
  z-index: -1;
}

.text1 p {
  display: block;
  width: 100%;
  font-family: Arial;
  font-size: 20px;
  margin: 0;
  padding: 0;
  color: #25252c;
}

.speech-bubble1 {
  position: relative;
  right: 20px;
  display: inline-block;
  background-color: white;
  width: 800px;
  height: 50px;
  margin: 5px;
  padding: 25px;
  border-radius: 500px;
  animation: speech-bubble1 700ms ease-in-out 400ms;
  transform: translateX(150%);
  animation-fill-mode: forwards;
  transition: 1s ease;
}
@keyframes speech-bubble1 {
  0% {
    transform: translateX(150%);
  }
  100% {
    transform: translateX(0);
  }
}
main .speech-bubble1:hover {
  width: 584px;
  height: 712px;
  transition: 1s ease;
}
.speech-bubble2 {
  position: relative;
  right: 60px;
  display: inline-block;
  background-color: white;
  width: 800px;
  height: 90px;
  margin: 5px;
  padding: 25px;
  border-radius: 500px;
  animation: speech-bubble2 700ms ease-in-out 600ms;
  animation-fill-mode: forwards;
  transform: translateX(150%);
}
@keyframes speech-bubble2 {
  0% {
    transform: translateX(150%);
  }
  100% {
    transform: translateX(0);
  }
}

.speech-bubble3 {
  position: relative;
  right: 60px;
  display: inline-block;
  background-color: white;
  width: 800px;
  height: 55px;
  margin: 5px;
  padding: 25px;
  border-radius: 500px;
  animation: speech-bubble2 700ms ease-in-out 800ms;
  animation-fill-mode: forwards;
  transform: translateX(150%);
}
@keyframes speech-bubble3 {
  0% {
    transform: translateX(150%);
  }
  100% {
    transform: translateX(0);
  }
}
span {
  font-weight: bold;
  font-size: 20px;
  margin: 0;
  padding: 0;
  font-family: Arial Rounded MT;
}

.Aljon {
  width: 484px;
  height: 612px;
  position: absolute;
  left: 65%;
  bottom: 0;
  background-size: contain;
  background-repeat: no-repeat;
  margin: 0;
  padding: 0;
  background-image: url(../Resources/Aljon.png);
  animation: aljon-load 300ms ease 200ms;
  transform: translateY(150%);
  animation-fill-mode: forwards;
  transition: 1s ease;
}
@keyframes aljon-load {
  0% {
    transform: translateY(150%);
  }
  100% {
    transform: translateX(0);
  }
}
.Aljon:hover {
  width: 584px;
  height: 712px;
  transition: 1s ease;
}
.navbar {
  position: fixed;
  background-color: var(--bg-primary);
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  text-align: center;
  animation: nav-load 600ms ease-in-out;
}
@keyframes nav-load {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(0);
  }
}
.navbar-nav {
  list-style: none;
  padding: 110px 0 0 0;
  margin: 0;
  flex-direction: column;
  align-items: center;
  height: 100%;
  bottom: 30px;
  position: relative;
  background-color: #23232e;
}

.nav-item a {
  display: block;
  text-decoration: none;
  background: #23232e;
  color: #ffffff;
  padding: 10;
  margin: 2px 0;
  width: 200px;
  display: flex;
  align-items: center;
  margin-left: -173px;
  transition: 0.2s ease;
}

.nav-item a:hover {
  margin-left: -5;
  color: #ffffff;
  font-weight: bold;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
  box-shadow: 15px 5px 5px -5px rgba(0, 3, 7, 0.8);
}

li i#active {
  filter: grayscale(0) opacity(1);
  background-color: #14141a;
}
li a#active {
  filter: grayscale(0) opacity(1);
  background-color: #14141a;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

li i {
  color: white;
  font-size: 27px;
  padding: 0;
  filter: grayscale(100%) opacity(0.1);
  width: 100%;
  text-align: right;
  transition: 0.2s ease;
}
Li i:hover {
  color: white;
  filter: grayscale(0) opacity(1);
  text-align: right;
  transition: 0.2s ease;
}

.logo h1 {
  font-family: Rustico;
  font-size: 35px;
  margin: 0;
  padding: 0;
  background: -webkit-linear-gradient(rgb(255, 7, 7), rgb(14, 14, 255));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}
.logo h1:hover {
  transition: 0.6s ease-in-out;
  cursor: pointer;
  transform: rotateZ(360deg);
}
.logo p {
  color: #ececec;
  position: relative;
  bottom: 35px;
  font-size: 10px;
  font-family: APEX;
  text-align: center;
}

hr {
  border: 2px solid white;
  padding: 0 5px;
  margin: 0;
}
.wrapper {
  display: flex;
  flex-direction: column;
}
.wrapper .icon {
  padding: 10px;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: relative;
  z-index: 2;
  transition: 0.1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.wrapper .icon span {
  color: #0c0c0c;
  padding: 0;
  margin: 0;
  display: block;
  height: 40px;
  width: 40px;
  background: #fff;
  border-radius: 50%;
  position: relative;
  z-index: 2;
  box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.1);
  transition: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.wrapper .icon span i {
  line-height: 40px;
  font-size: 25px;
  text-align: center;
}
.wrapper .icon .tooltip {
  position: absolute;
  left: 80px;
  z-index: 1;
  background: #fff;
  color: #fff;
  padding: 10px 18px;
  font-size: 20px;
  font-weight: 500;
  border-radius: 25px;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.1);
  transition: 0.4s ease-in-out;
}
.wrapper .icon:hover .tooltip {
  left: 50px;
  top: 8px;
  opacity: 1;
  transition: 0.1s ease-in-out;
}

.wrapper .icon:hover span {
  color: #fff;
  filter: opacity(1);
}
.wrapper .icon:hover span,
.wrapper .icon:hover .tooltip {
  text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.4);
}
.wrapper .facebook:hover span,
.wrapper .facebook:hover .tooltip,
.wrapper .facebook:hover .tooltip:before {
  background: #3b5999;
}

.wrapper .youtube:hover span,
.wrapper .youtube:hover .tooltip,
.wrapper .youtube:hover .tooltip:before {
  background: #de463b;
}
#loading {
  position: fixed;
  width: 100%;
  height: 100vh;
  background: #51516a url(../Resources/Loader.gif) no-repeat center center;
  filter: opacity(0.1);
  z-index: 99999;
}

/* Small screens */
@media only screen and (max-width: 600px) {
  .navbar {
    bottom: auto;
    width: 100vw;
    height: 3rem;
  }

  .navbar-nav {
    flex-direction: row;
    bottom: auto;
    width: 100vw;
    height: 3rem;
  }

  .wrapper .icon span {
    margin-left: 450px;
    bottom: 30px;
  }
  .wrapper .icon:hover .tooltip {
    right: 100;
    top: 0;
    opacity: 1;
    transition: 0.4s ease-in-out;
  }
}

/* Large screens */
@media only screen and (min-width: 600px) {
  .navbar {
    top: 0;
    width: 3rem;
    height: 100vh;
  }
}
<div class="text1">
<div class="speech-bubble1">
<p>Nice to meet you and welcome to my Website!
I'm <span>Aljon Gabriel A. Valdez</span> and I am a <span>Bachelor's of Science in Information Technology graduate.</span>
</p>
</div>

最佳答案

因为您已经给了 z-index: -1; 删除或使其成为 z-index:

@import url("https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap");
:root {
    font-size: 16px;
    font-family: "Open Sans";
}

body {
    margin: 0;
    padding: 0;
    background-color: #191921;
    overflow: hidden; /* Hide scrollbars */
}

body::-webkit-scrollbar {
    width: 0.25rem;
}

body::-webkit-scrollbar-thumb {
    background: #43434f;
}

main {
    color: white;
    margin-left: 3rem;
    padding: 1rem;
}
.greetings h1 {
    padding: 0;
    margin: 0;
}
.text1 {
    position: relative;
    left: 90px;
    top: 250px;
    margin-left: 0;
    padding: 0;
    z-index: 1;
}

.text1 p {
    display: block;
    width: 100%;
    font-family: Arial;
    font-size: 20px;
    margin: 0;
    padding: 0;
    color: #25252c;
}

.speech-bubble1 {
    position: relative;
    right: 20px;
    display: inline-block;
    background-color: white;
    width: 800px;
    height: 50px;
    margin: 5px;
    padding: 25px;
    border-radius: 500px;
    animation: speech-bubble1 700ms ease-in-out 400ms;
    transform: translateX(150%);
    animation-fill-mode: forwards;
    transition: 1s ease;
}

.speech-bubble1:hover {
    width: 100%;
}

@keyframes speech-bubble1 {
    0% {
        transform: translateX(150%);
    }
    100% {
        transform: translateX(0);
    }
}
main .speech-bubble1:hover {
    width: 584px;
    height: 712px;
    transition: 1s ease;
}
.speech-bubble2 {
    position: relative;
    right: 60px;
    display: inline-block;
    background-color: white;
    width: 800px;
    height: 90px;
    margin: 5px;
    padding: 25px;
    border-radius: 500px;
    animation: speech-bubble2 700ms ease-in-out 600ms;
    animation-fill-mode: forwards;
    transform: translateX(150%);
}
@keyframes speech-bubble2 {
    0% {
        transform: translateX(150%);
    }
    100% {
        transform: translateX(0);
    }
}

.speech-bubble3 {
    position: relative;
    right: 60px;
    display: inline-block;
    background-color: white;
    width: 800px;
    height: 55px;
    margin: 5px;
    padding: 25px;
    border-radius: 500px;
    animation: speech-bubble2 700ms ease-in-out 800ms;
    animation-fill-mode: forwards;
    transform: translateX(150%);
}
@keyframes speech-bubble3 {
    0% {
        transform: translateX(150%);
    }
    100% {
        transform: translateX(0);
    }
}
span {
    font-weight: bold;
    font-size: 20px;
    margin: 0;
    padding: 0;
    font-family: Arial Rounded MT;
}

.Aljon {
    width: 484px;
    height: 612px;
    position: absolute;
    left: 65%;
    bottom: 0;
    background-size: contain;
    background-repeat: no-repeat;
    margin: 0;
    padding: 0;
    background-image: url(../Resources/Aljon.png);
    animation: aljon-load 300ms ease 200ms;
    transform: translateY(150%);
    animation-fill-mode: forwards;
    transition: 1s ease;
}
@keyframes aljon-load {
    0% {
        transform: translateY(150%);
    }
    100% {
        transform: translateX(0);
    }
}
.Aljon:hover {
    width: 584px;
    height: 712px;
    transition: 1s ease;
}
.navbar {
    position: fixed;
    background-color: var(--bg-primary);
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    text-align: center;
    animation: nav-load 600ms ease-in-out;
}
@keyframes nav-load {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(0);
    }
}
.navbar-nav {
    list-style: none;
    padding: 110px 0 0 0;
    margin: 0;
    flex-direction: column;
    align-items: center;
    height: 100%;
    bottom: 30px;
    position: relative;
    background-color: #23232e;
}

.nav-item a {
    display: block;
    text-decoration: none;
    background: #23232e;
    color: #ffffff;
    padding: 10;
    margin: 2px 0;
    width: 200px;
    display: flex;
    align-items: center;
    margin-left: -173px;
    transition: 0.2s ease;
}

.nav-item a:hover {
    margin-left: -5;
    color: #ffffff;
    font-weight: bold;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    box-shadow: 15px 5px 5px -5px rgba(0, 3, 7, 0.8);
}

li i#active {
    filter: grayscale(0) opacity(1);
    background-color: #14141a;
}
li a#active {
    filter: grayscale(0) opacity(1);
    background-color: #14141a;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

li i {
    color: white;
    font-size: 27px;
    padding: 0;
    filter: grayscale(100%) opacity(0.1);
    width: 100%;
    text-align: right;
    transition: 0.2s ease;
}
Li i:hover {
    color: white;
    filter: grayscale(0) opacity(1);
    text-align: right;
    transition: 0.2s ease;
}

.logo h1 {
    font-family: Rustico;
    font-size: 35px;
    margin: 0;
    padding: 0;
    background: -webkit-linear-gradient(rgb(255, 7, 7), rgb(14, 14, 255));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
}
.logo h1:hover {
    transition: 0.6s ease-in-out;
    cursor: pointer;
    transform: rotateZ(360deg);
}
.logo p {
    color: #ececec;
    position: relative;
    bottom: 35px;
    font-size: 10px;
    font-family: APEX;
    text-align: center;
}

hr {
    border: 2px solid white;
    padding: 0 5px;
    margin: 0;
}
.wrapper {
    display: flex;
    flex-direction: column;
}
.wrapper .icon {
    padding: 10px;
    text-align: center;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    position: relative;
    z-index: 2;
    transition: 0.1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.wrapper .icon span {
    color: #0c0c0c;
    padding: 0;
    margin: 0;
    display: block;
    height: 40px;
    width: 40px;
    background: #fff;
    border-radius: 50%;
    position: relative;
    z-index: 2;
    box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.1);
    transition: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.wrapper .icon span i {
    line-height: 40px;
    font-size: 25px;
    text-align: center;
}
.wrapper .icon .tooltip {
    position: absolute;
    left: 80px;
    z-index: 1;
    background: #fff;
    color: #fff;
    padding: 10px 18px;
    font-size: 20px;
    font-weight: 500;
    border-radius: 25px;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.1);
    transition: 0.4s ease-in-out;
}
.wrapper .icon:hover .tooltip {
    left: 50px;
    top: 8px;
    opacity: 1;
    transition: 0.1s ease-in-out;
}

.wrapper .icon:hover span {
    color: #fff;
    filter: opacity(1);
}
.wrapper .icon:hover span,
.wrapper .icon:hover .tooltip {
    text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.4);
}
.wrapper .facebook:hover span,
.wrapper .facebook:hover .tooltip,
.wrapper .facebook:hover .tooltip:before {
    background: #3b5999;
}

.wrapper .youtube:hover span,
.wrapper .youtube:hover .tooltip,
.wrapper .youtube:hover .tooltip:before {
    background: #de463b;
}
#loading {
    position: fixed;
    width: 100%;
    height: 100vh;
    background: #51516a url(../Resources/Loader.gif) no-repeat center center;
    filter: opacity(0.1);
    z-index: 99999;
}

/* Small screens */
@media only screen and (max-width: 600px) {
    .navbar {
        bottom: auto;
        width: 100vw;
        height: 3rem;
    }

    .navbar-nav {
        flex-direction: row;
        bottom: auto;
        width: 100vw;
        height: 3rem;
    }

    .wrapper .icon span {
        margin-left: 450px;
        bottom: 30px;
    }
    .wrapper .icon:hover .tooltip {
        right: 100;
        top: 0;
        opacity: 1;
        transition: 0.4s ease-in-out;
    }
}

/* Large screens */
@media only screen and (min-width: 600px) {
    .navbar {
        top: 0;
        width: 3rem;
        height: 100vh;
    }
}
<div class="text1">
            <div class="speech-bubble1">
            <p>Nice to meet you and welcome to my Website!
            I'm <span>Aljon Gabriel A. Valdez</span> and I am a <span>Bachelor's of Science in Information Technology graduate.</span>
            </p>
            </div>

1"

.text1 {
  position: relative;
  left: 90px;
  top: 250px;
  margin-left: 0;
  padding: 0;
  z-index: -1;
}

并添加:

.speech-bubble1:hover {
  width: 100%;
}

关于javascript - 将鼠标悬停在 div "rectange"上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65317570/

相关文章:

javascript - 使用 php 和 javascript 从数据库删除项目之前插入确认

javascript - Html 和 js 文件/OS X

javascript - <Div> 中的随机图像来自数组

html - @font-face 或 Web-font 哪个更可取?

javascript - 如何在 JavaScript 中创建执行 Sigma 符号计算的函数?

javascript - 我们可以在同一个页面中使用AJAXToolKit和Jquery吗

html - 选择选项CSS

jquery - 使用jquery高度动态获取两个嵌套框的高度?

javascript - WebRTC视频聊天

javascript - NodeJS 从多个 http 请求中获取数据