【问题标题】:CSS hover element after hover parent element悬停父元素后的CSS悬停元素
【发布时间】:2018-05-03 11:49:40
【问题描述】:

我有一个带有两个背景图像的分屏。在每一边我都有一个 image.png 和一个 image-hover.png。当我将光标放在背景图像或 image.png 上时,我想将 image-hover.png 放在 image.png 的顶部。

我设法做到了,但是当我将光标放在背景图像上时,悬停在 image.png 上激活,当我将光标拖到 image.png 上时,悬停消失。

这是我的页面:http://loopaa.com/split/

这是我的代码:

@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600,800');

html, body {
  height: 100%;
  min-height: 18em;
background: linear-gradient(90deg, #534591 50%, #e2d649 50%);
}


.stanga {
  background-image: url("http://loopaa.com/split/left-side.png");
  height: 100%;
}
    
.dreapta {
  background-image: url("http://loopaa.com/split/right-side.png");
  height: 100%;
}

.split-pane {
  padding-top: 22%;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  height: 100%;
  font-size: 2em;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight:300;
}


.split-pane > div {
  position: relative;
  top: 40%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  text-align: center;
}
.split-pane > div .text-content {
  line-height: 1.6em;
  margin-bottom: 1em;
}
.split-pane > div .text-content .big {
  font-size: 2em;
  text-decoration:none;
}


#cf{margin: auto;
    width: 400px;}

#cf .left-cheery{
    width: 400px;
    height: 360px;
    background: url(http://loopaa.com/split/cc.png);
    border:0;
    transition: all 0.35s ease-in-out;
}

.stanga:hover .left-cheery{
    background: url(http://loopaa.com/split/cc-hover.png) !important;
    transition: all 1s ease-in;   
}






#cf .right-cheery{
    width: 400px;
    height: 360px;
    background: url(http://loopaa.com/split/cc2.png);
    border:0;
    transition: all 0.35s ease-in-out;
}

.dreapta:hover .right-cheery{
    background: url(http://loopaa.com/split/cc2-hover.png) !important;
    transition: all 1s ease-in;   
}



.split-pane button, .split-pane a.button-left, .split-pane a.button-right {
  font-family: 'Open Sans', sans-serif;
	font-weight:800;
  background: none;
  border: 1px solid #3b3277;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  width: 15em;
  padding: 0.7em;
  font-size: 0.5em;
  text-decoration: none;
  color: #3b3277;
  display: inline-block;
  cursor: pointer;
  -moz-transition: all 0.2s ease-out;
  -o-transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
  transition: all 0.2s ease-out;
}
.split-pane button:hover, .split-pane a.button-left:hover {
  text-decoration: none;
  background-color: #3b3277;
  border-color: #3b3277;
  cursor: pointer;
}

.button-left{border: 1px solid #e1d622 !important;color:#e1d622 !important;margin-bottom:6px;}
.button-left:hover{background-color:#e1d622 !important;color:#3b3277 !important;}

.button-right{border: 1px solid #3b3277 !important;color:#3b3277 !important;margin-bottom:6px;}
.button-right:hover{background-color:#3b3277 !important;color:#e1d622 !important;}

.uiux-side.split-pane button:hover, .split-pane a.button-left:hover {
  color: #ffffff;
}
.frontend-side.split-pane button:hover, .split-pane a.button-left:hover {
  color: blue;
}

#bg-logo{ border-radius: 50%;
	width: 125px;
	height: 125px; 
    background:#ffffff;
    margin: auto;
    padding-top:38px;
}

#split-pane-or {
  font-size: 2em;
  color: white;
  font-family: 'Open Sans', sans-serif;
  text-align: center;
  width: 100%;
  position: absolute;
  top: 43.5%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}

.big {
  font-size: 2em;
}

#slogan {
  position: absolute;
  width: 100%;
  z-index: 100;
  text-align: center;
  vertical-align: baseline;
  top: 0.5em;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-size: 1.4em;
}

#slogan img {
  height: 0.7em;
}
.text-content p{
	text-transform:uppercase;
	font-size:1.6rem;
	font-weight:600;
	line-height: 140%;
	margin-top:12px;
}
.big {
	font-weight:800;
}











@media only screen and (max-width: 1368px) {
    .split-pane {}
    .split-pane > div .text-content .big {font-size: 1em;}
    .split-pane > div .text-content {line-height: 1em;margin-bottom: 0;}
    .text-content p{margin-top: 8px;font-size: 1.4rem;}
}




@media only screen and (max-width: 1025px) {

.split-pane{}

.split-pane > div .text-content .big {font-size: 1.4em;}

#cf .left-cheery{
    width: 200px;
    height: 180px;
    background: url(http://loopaa.com/split/cc-min.png);
}
.stanga:hover .left-cheery{
    background: url(http://loopaa.com/split/cc-min-hover.png) !important;
}

#cf {width:200px;}

#cf .right-cheery{
    width: 200px;
    height: 180px;
    background: url(http://loopaa.com/split/cc-min.png);
}
.dreapta:hover .right-cheery{
    background: url(http://loopaa.com/split/cc-min-hover.png) !important;
}
}


@media (max-width:801px) and (min-width:738px) {
    #bg-logo{display:none;}
   .split-pane {}
   .split-pane > div .text-content {line-height: 1.6em;margin-bottom: 10px;}
}



@media only screen and (max-width: 737px) {
    #bg-logo{display:none;}
    .split-pane {padding-top: 5%;}
    .split-pane > div .text-content .big {font-size: 1em;}
    .split-pane > div .text-content {line-height: 1em;margin-bottom: 0;}
    .text-content p{margin-top: 8px;font-size: 1.4rem;}
}



@media only screen and (max-width:569px){
    
    #cf{display:none;}
    .split-pane > div .text-content .big {font-size: 1em;}
    .split-pane > div .text-content {line-height: 1em;margin-bottom: 0;}
    .text-content p{margin-top: 8px;font-size: 1.4rem;}
}

@media only screen and (max-width:568px){
    
    #cf{display:none;}
    .split-pane > div .text-content .big {font-size: 0.9em;}
    .split-pane > div .text-content {line-height: 1em;margin-bottom: 0;}
    .text-content p{margin-top: 8px;font-size: 1rem;}
}
<head>
  <meta charset="UTF-8">
  <title>Cheerup</title>
  
  <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
</head>

<body>
  <div class='split-pane col-xs-12 col-sm-6 stanga' id="body-half-color">
  <div>
      
    <div id="cf">
        <div class="left-cheery"></div>
    </div>
    
    <div class='text-content' style="color:#e1d622;">
      <!--<div class="bold">Photobooth for</div>-->
      <div class='big'>CORPORATE CHEERY</div>
      <p>Oferim experiențe memorabile, pline de zâmbete și veselie,<br /> la orice tip de eveniment business</p>
    </div>
    <a class='button-left'>
      AFLA CUM
    </a>
  </div>
</div>
<div class='split-pane col-xs-12 col-sm-6 dreapta'>
  <div>
 
 
    <div id="cf">
        <div class="right-cheery"></div>
    </div>
 
    <div class='text-content' style="color:#3b3277;">

      <div class='big'>PRIVATE PARTY CHEERY</div>
      <p>Cu noi, distracția primează în rândul celor alături de care ai ales să<br /> petreci una din cele mai importante zile din viața ta</p>
    </div>
    <a class='button-right'>
      AFLA CUM
    </a>
  </div>
</div>
<div id='split-pane-or'>
  <div id="bg-logo">
    <img src='http://loopaa.com/split/logo-cheerup-mic.png' />
  </div>
</div>
  
</body>

我希望我的描述正确并且您理解问题所在。

【问题讨论】:

  • 请分享您的代码。
  • 你是否同时为背景图片和正面图片应用悬停?
  • 看起来悬停只适用于每一侧的一个部分,请尝试在每一侧的整个 div 上添加悬停
  • 我在帖子中添加了我的代码,很抱歉错过了。
  • @dan6657 将鼠标悬停在每个(左右)的整个部分上,但是“.stanga:hover .left-cheery”会出现问题。

标签: html css hover mousehover


【解决方案1】:

我通常用来解决 CSS 问题的方法是在所有内容周围加上彩色边框 - 我在此处对您的代码进行了此操作:

http://jsfiddle.net/kNB3c/429/

然后你可以看到你的悬停在哪个部分失败(因为你已经为边框着色)所以它在上面的蓝色部分失败..这是#split-pane-or

这是你的中间标志部分,这需要它的宽度减少到大约 20%(或者你希望那个部分有多小)

您可以将#split-pane 中的宽度属性设置为如下所示:

margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
width: 20%;

或者使宽度更小,以便您可以将更多鼠标悬停在该部分上..

附:不错的设计!

【讨论】:

    猜你喜欢
    • 2013-08-01
    • 1970-01-01
    • 2011-07-01
    • 2013-07-12
    • 1970-01-01
    • 2021-07-12
    • 2013-12-07
    • 1970-01-01
    • 2017-04-19
    相关资源
    最近更新 更多