【问题标题】:I want to make a circle button with text and different text on hover CSS我想在悬停CSS上制作一个带有文本和不同文本的圆形按钮
【发布时间】:2015-07-03 09:44:34
【问题描述】:

我正在尝试制作一个带有标签/文本的圆形按钮(我在考虑提交按钮或链接到另一个页面),然后当您将鼠标悬停时它具有不同的文本。我已经能够单独找到所有这些东西的教程,但我不能完全让它们发挥作用。

目前我有:

HTML

<div class='button'>
     <a href='activities.php'>
          <div class='text'> hello world </div>
          <img src="/Images/budapest.jpg">
     </a>
</div>

CSS

.button img { /*http://codeitdown.com/css-round-buttons/*/
    display:                block;
    width:                  30vmin;
    height:                 30vmin;
    line-height:            50px;
    border:                 2px;
    border-radius:          50%;
    color:                  #000000;
    text-align:             center;
    text-decoration:        none;
    background:             #000000;
    font-size:              20px;
    font-weight:            bold;
    z-index:                1;
}
.text{
    display:                block;
}
.text:hover {
    display:                none;
    z-index:                2;
}

.button input[type=submit].nav  {
    font-family:            'Optima', sans-serif;
    height:                 auto;
    width:                  auto;
    background:             #111111;
    border-radius:          1vmin;
    color:                  #FFFFFF;
    font-size:              2vmin;
    z-index:                2;
}

该按钮当前是我想要的图像 - 是的,并且确实重定向到正确的页面。但是,文本“hello world”总是显示(而不是仅在悬停时),位于图像上方(而不是在其顶部),我可以单击它或按钮来重定向我。另外,当我悬停时如何改变文本?

更新

剩下的问题是文本不在按钮/图像内。

我的代码

.button img { /*http://codeitdown.com/css-round-buttons/*/
  display:				block;
  width:					30vmin;
  height:					30vmin;
  line-height:			50px;
  border: 				2px;
  border-radius: 			50%;
  color:					#000000;
  text-align:				center;
  text-decoration:		none;
  background: 			#000000;
  font-size:				20px;
  font-weight:			bold;
  z-index: 				1;
}
.button .text-after {
  display: 				none;
}
.button:hover .text-after {
  display: 				inline;
}
.button:hover .text-before {
  display: 				none;
}
<div class='button'>
  <a href='activities.php'>
    <span class="text-before">Before</span>
    <span class="text-after">After</span>
    <img src="/Images/budapest.jpg">
  </a>
</div>

【问题讨论】:

标签: html css


【解决方案1】:

不要在&lt;a&gt; 内使用&lt;div&gt;最糟糕的噩梦!链接内的除法?内联内的阻塞?)。

第二次使用这样的两个文本容器:

<div class='button'>
     <a href='activities.php'>
          <span class="text-before">Before</span>
          <span class="text-after">After</span>
          <img src="/Images/budapest.jpg">
     </a>
</div>

使用这个 CSS:

.button .text-after {display: none;}
.button:hover .text-after {display: inline;}
.button:hover .text-before {display: none;}

更新片段

我的代码

.button img { /*http://codeitdown.com/css-round-buttons/*/
  display:				block;
  width:				30vmin;
  height:				30vmin;
  line-height:			50px;
  border: 				2px;
  border-radius: 		50%;
  color:				#000000;
  text-align:			center;
  text-decoration:		none;
  background: 			#333333;
  font-size:		    20px;
  font-weight:			bold;
  z-index: 				1;
}
.button .text-after {
  display: 				none;
}
.button:hover .text-after {
  display: 				inline;
}
.button:hover .text-before {
  display: 				none;
}

.button a {
  text-align: center;
  display: block;
  width: 89.6875px; /* should be the width of image*/
  line-height: 89.6875px;
  position: absolute;
  z-index: 9;
  left: 0;
  top: 0;
}

.button {
  position: relative;
  z-index: 9;
}

.button img {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
}
<div class='button'>
  <a href='activities.php'>
    <span class="text-before">Beforexd</span>
    <span class="text-after">After</span>
    <img src="/Images/budapest.jpg">
  </a>
</div>

以上是我所做的,但不幸的是它没有工作。我不知道为什么,但我可以给你一个不同的解决方案:

.round-img-button {
  width: 100px;
  height: 100px;
  position: relative;
}

.round-img-button a,
.round-img-button img {
  position: absolute;
  width: 100px;
  height: 100px;
  left: 0;
  top: 0;
  z-index: 1;
}

.round-img-button a {
  z-index: 2;
  color: #fff;
  text-decoration: none;
  text-align: center;
  line-height: 100px;
}

.round-img-button a .after {
  display: none;
}

.round-img-button:hover a .after {
  display: inline;
}

.round-img-button:hover a .before {
  display: none;
}
<div class="round-img-button">
  <a href="#">
    <span class="after">Hover</span>
    <span class="before">Normal</span>
  </a>
  <img src="http://lorempixel.com/100/100" alt="" />
</div>

【讨论】:

【解决方案2】:

请尝试

.button a:hover .text {
    display:                none;
    z-index:                2;
}

【讨论】:

    【解决方案3】:

    这里有一个例子http://jsfiddle.net/josedvq/Jyjjx/45/可以回答你的问题。

    <div class="round-button"><div class="round-button-circle"><a href="http://example.com" class="round-button">Button!!</a></div></div>
    

    【讨论】:

    • 这不能回答问题。
    猜你喜欢
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多