如何在工具提示中显示按钮

时间:2017-05-13 21:18:05

标签: php html css

我的项目中有一个工具提示。 我喜欢做的是在我的工具提示中添加活动按钮。 问题是工具提示显示的是HTML标记而不是按钮 ...

这是我工作的效果:-) enter image description here

贝娄是我的代码。

请有人帮忙。谢谢。

/* Frame */

.frame {
  height: 150px;
  max-width: 1170px;
  /*line-height: 130px;*/
/*  overflow:visible !important;*/
}

.frame ul {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 100%;
  font-size: 14px;

}

.frame ul li {
  float: left;
  width: 232px;
  height: 100%;
  margin: 0 2px 0 0;
  padding: 0;
  background: #f1f1f1;
  color: #00b5f6;
  text-align: center;
  cursor: default;
  display:flex;
}

.frame ul li:hover{
  color: #fff;
  background: #00b5f6;

  
}


/* setup tooltips */
.tooltip {
  position: relative;
  z-index:1;
}
li .tooltip{
	overflow:visible;
}
.tooltip:before,
.tooltip:after {
  position:absolute;
  display:inline-block;
  opacity: 0;
  pointer-events: none;
  width:225px;

}
.tooltip:after {
	border-right: 6px solid transparent;
	border-top: 6px solid #00b5f6; 
  border-left: 6px solid transparent;
  content: '';
  height: 0;
    top: -5px;
    left: 20px;
  width: 0;
  display:none;
  

}
.tooltip:before {
  background: #00b5f6;
  border-radius: 2px;
  color: #fff;
  content: attr(data-title);
  font-size: 12px;
  padding: 6px 10px;
  top: 0px;
  left: 0px;
  white-space: nowrap;
  height:118px;
  max-width:212px !important;
  display:block;
  word-wrap: break-word;
  text-align: left;
  white-space: pre-line;
}

/* expand */
.tooltip.expand:before {
  transform: scale3d(.2,.2,1);
  transition: all .2s ease-in-out 0.5s;
}
.tooltip.expand:after {
  transform: translate3d(0,6px,0);
  transition: all .2s ease-in-out 0.5s;
}
.tooltip.expand:hover:before,
.tooltip.expand:hover:after {
  opacity: 1;
  transform: scale3d(1,1,1);
}
.date_event{
	text-align:left; width:232px; position:absolute; padding: 5px 0 0 5px; font-style: italic; max-height:20px; z-index:-1;
}
.suwak{
	width:232px; height:150px; margin-left:auto; margin-right:auto; overflow-y:visible; overflow-x:hidden; border:solid 1px #000;
}
.title_event{
	font-size:16px; font-weight:bold; width:232px; height:130px; vertical-align: middle !important; display: table-cell !important; margin-left:auto; margin-right:auto;
}
	  <?php $tooltip = "Lorem ipsum dolor sit amet enim.";
	   $tooltip = $tooltip."<div class='btn_google'>google</div>"; ?>

<div class="suwak">
<div class="frame" id="basic">
  <li class="tooltip expand" data-title="<?php echo $tooltip;?>">
      <div class="date_event">02.02.2017</div>
      <div style="text-align: center; width:232px;">
        	<div class="title_event">Some title</div>
      </div>
  </li>
</div>
</div>

2 个答案:

答案 0 :(得分:1)

不需要li,只需将其更改为div

即可

另外,为什么不在隐藏显示它时添加隐藏的div块作为工具提示容器(就像工具提示一样):

.expand:hover>div {
  display: none;
  height: 148px;
  width: 232px;
}

.mytitle {
  display: none;
}

.expand:hover>.mytitle {
  display: block;
  background: red;
}

&#13;
&#13;
/* Frame */

.frame {
  height: 150px;
  max-width: 1170px;
  /*line-height: 130px;*/
  /*  overflow:visible !important;*/
}

.frame ul {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 100%;
  font-size: 14px;
}

.frame ul li {
  float: left;
  width: 232px;
  height: 100%;
  margin: 0 2px 0 0;
  padding: 0;
  background: #f1f1f1;
  color: #00b5f6;
  text-align: center;
  cursor: default;
  display: flex;
}

.frame ul li:hover {
  color: #fff;
  background: #00b5f6;
}


/* setup tooltips */

.tooltip {
  position: relative;
  z-index: 1;
}

li .tooltip {
  overflow: visible;
}

.tooltip:before,
.tooltip:after {
  position: absolute;
  display: inline-block;
  opacity: 0;
  pointer-events: none;
  width: 225px;
}

.tooltip:after {
  border-right: 6px solid transparent;
  border-top: 6px solid #00b5f6;
  border-left: 6px solid transparent;
  content: '';
  height: 0;
  top: -5px;
  left: 20px;
  width: 0;
  display: none;
}

.tooltip:before {
  background: #00b5f6;
  border-radius: 2px;
  color: #fff;
  content: attr(data-title);
  font-size: 12px;
  padding: 6px 10px;
  top: 0px;
  left: 0px;
  white-space: nowrap;
  height: 118px;
  max-width: 212px !important;
  display: block;
  word-wrap: break-word;
  text-align: left;
  white-space: pre-line;
}


/* expand */

.tooltip.expand:before {
  transform: scale3d(.2, .2, 1);
  transition: all .2s ease-in-out 0.5s;
}

.tooltip.expand:after {
  transform: translate3d(0, 6px, 0);
  transition: all .2s ease-in-out 0.5s;
}

.tooltip.expand:hover:before,
.tooltip.expand:hover:after {
  opacity: 1;
  transform: scale3d(1, 1, 1);
}

.date_event {
  text-align: left;
  width: 232px;
  position: absolute;
  padding: 5px 0 0 5px;
  font-style: italic;
  max-height: 20px;
  z-index: -1;
}

.suwak {
  width: 232px;
  height: 150px;
  margin-left: auto;
  margin-right: auto;
  overflow-y: visible;
  overflow-x: hidden;
  border: solid 1px #000;
}

.title_event {
  font-size: 16px;
  font-weight: bold;
  width: 232px;
  height: 130px;
  vertical-align: middle !important;
  display: table-cell !important;
  margin-left: auto;
  margin-right: auto;
}

.expand:hover>div {
  display: none;
}

.mytitle {
  height: 0px;
  width: 0px;
  display: none;
}

.expand:hover>.mytitle {
  height: 150px;
  width: 232px;
  display: block;
  background: red;
}
&#13;
<div class="suwak">
  <div class="frame" id="basic">
    <div class="expand" data-title="">
      <div class="mytitle">my title <button>123</button><button>123</button></div>
      <div class="date_event">02.02.2017</div>
      <div style="text-align: center; width:232px;">
        <div class="title_event">Some title</div>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以在不使用Javascript的情况下执行此操作。删除li并以一种简单的方式执行此类操作:

&#13;
&#13;
.box{
	width: 200px;
	height: 100px;
	position: relative;
	background-color: silver;
	text-align: center;
}
	
.box:hover .tip{
	display: block;
}
	
.tip{
	display: none;
	background-color: yellow;
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
}
&#13;
<div class="box">

	<div class="tip">
		This is tip content and this is <button>button</button> in it
	</div>

	Box content

</div>
&#13;
&#13;
&#13;

<强>更新

来自您在评论中提供的链接(uw.edu.pl)这就是您要做的事情:

&#13;
&#13;
ul{
		list-style: none;
	}

	ul.main{
		display: inline-block;
		margin-top: 50px;
	}

	ul.main>li{
		width: 200px;
		height: auto;
		position: relative;
		background-color: silver;
		text-align: center;
	}
	
	ul li ul{
		display: none;
	}
	
	ul li a{
		display: block;
		height: 100%;
        text-decoration: none;
        color: white;
	}
	
	ul li:hover ul{
		display: block;
	}
	
	ul.tip{
		display: none;
		background-color: yellow;
		position: absolute;
		bottom: 100%;
		padding: 0;
		
		height: auto;
		left: 0;
		right: 0;
		z-index: 1;
	}
&#13;
<ul class="main">
	
		<li>
		
			<a href="#">Box content 1</a>
			
			<ul class="tip">
				<li>
					This is tip content and this is <button>button1</button> in it
				</li>
			</ul>
		</li><li>
		
			<a href="#">Box content 2</a>
			
			<ul class="tip">
				<li>
					This is tip content and this is <button>button2</button> in it
				</li>
			</ul>
		
		</li><li>
		
			<a href="#">Box content 3</a>
			
			<ul class="tip">
				<li>
					This is tip content and this is <button>button3</button> in it
				</li>
			</ul>
		
		</li><li>
		
			<a href="#">Box content 4</a>
			
			<ul class="tip">
				<li>
					This is tip content and this is <button>button4</button> in it
				</li>
			</ul>
		
		</li>
		
	
	</ul>
&#13;
&#13;
&#13;