我添加了一个按钮,我希望它在点击时显示下面的表格

时间:2016-12-09 15:00:19

标签: css

我对此感到有些迷茫,我添加了一个按钮,让桌子完成并隐藏起来。我现在需要的只是在点击按钮时显示它。我知道这很容易,但我的大脑已经消失了。

这是html:

<div class="lotteryresults">

<button class="button button5"><b>+</b></button>
<h2>December</h2>
<p2>A responsive table will display a horizontal scroll bar   if           the       screen is too 
small to display the full content. Resize the browser window to see    the effect:</p2>

<div class="button5-content">
<div style="overflow-x:auto;">
<table>

<tr>
  <td>£1000</td>
  <td>£75</td>
  <td>£50</td>
  <td>£25</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
  <td>£10</td>
</tr>
<tr>
  <td>11533</td>
  <td>22978</td>
  <td>12456</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
  <td>67849</td>
 </tr>

</table>
</div>
</div></div>

这是CSS:

  .button {
background-color: #434343; 
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
float: right;
}
.button5 {border-radius: 80%;size: 60px;}
.button:active {
 background-color: #a1a0a0;
 box-shadow: 0 5px #666;
 transform: translateY(4px);
 }

table {
border-collapse: collapse;
width: 100%;
max-width: 1000px;margin:auto;border: 1px solid white;
}

th, td { margin:auto;
text-align: left;
padding: 6px;border: 2px solid #dadada;
}
p2 {font-family: source sans pro;padding-left:15px;padding-top: -20px;}

h2 {font-family: 
source sans pro;fontsize:45px;paddingleft:15px;color:purple;}

tr:nth-child(even){background-color: #b4b4b4;
margin:auto;align:center;font-family: source sans pro;}

tr:nth-child(odd){background-color: #7a7a7a;
font-family: source sans pro;font-weight:bold;}

.lotteryresults {background-color: #dadada;
width:100%;max-width:1200px;margin:auto;}

.button5-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 1000px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);}

.button5:hover .button5-content {
display: block;
}

2 个答案:

答案 0 :(得分:2)

您可以使用

实现此目的
  • checkboxlabel
  • 并且可以定位它们,因为checkbox将不可见,但label只能看到position: absolute

如下所示

&#13;
&#13;
.button {
  background-color: #434343; 
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  float: right;
}
.button5 {border-radius: 80%;size: 60px;}
.button:active {
  background-color: #a1a0a0;
  box-shadow: 0 5px #666;
  transform: translateY(4px);
}

table {
  border-collapse: collapse;
  width: 100%;
  max-width: 1000px;margin:auto;border: 1px solid white;
}

th, td { margin:auto;
  text-align: left;
  padding: 6px;border: 2px solid #dadada;
}
p2 {font-family: source sans pro;padding-left:15px;padding-top: -20px;}

h2 {font-family: 
  source sans pro;fontsize:45px;paddingleft:15px;color:purple;}

tr:nth-child(even){background-color: #b4b4b4;
  margin:auto;align:center;font-family: source sans pro;}

tr:nth-child(odd){background-color: #7a7a7a;
  font-family: source sans pro;font-weight:bold;}

.lotteryresults {background-color: #dadada;
  width:100%;max-width:1200px;margin:auto;}

.button5-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 1000px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);}

input[type=checkbox] {
  position: absolute;
  top: -9999px;
  left: -9999px;
}

label {
  display:block;
  background: #08C;
  padding: 5px;
  border: 1px solid rgba(0,0,0,.1);
  border-radius: 2px;
  color: white;
  font-weight: bold;
}

input[type=checkbox]:checked ~ .button5-content {
  display: block;
}


input[type=checkbox] {
	position: absolute;
	top: -9999px;
	left: -9999px;
}

label {
	display: block;
	background: #08C;
	padding: 5px;
	border: 1px solid rgba(0,0,0,.1);
	border-radius: 2px;
	color: white;
	font-weight: bold;
}

input[type=checkbox]:checked ~ .to-be-changed {
	color: red;
}
&#13;
<div class="lotteryresults">

  <label class="button button5" for="toggle">+</label>
  <input class="button" type="checkbox" id="toggle">

  <!-- <button class="button button5"><b>+</b></button> -->
  <h2>December</h2>
  <p2>A responsive table will display a horizontal scroll bar   if           the       screen is too 
    small to display the full content. Resize the browser window to see    the effect:</p2>

  <div class="button5-content">
    <div style="overflow-x:auto;">
      <table>

        <tr>
          <td>£1000</td>
          <td>£75</td>
          <td>£50</td>
          <td>£25</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
          <td>£10</td>
        </tr>
        <tr>
          <td>11533</td>
          <td>22978</td>
          <td>12456</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
          <td>67849</td>
        </tr>

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

希望这会以某种方式帮助你(y)。

有关参考,请查看本文 - http://tympanus.net/codrops/2012/12/17/css-click-events/

答案 1 :(得分:1)

这将帮助您入门:

<span class="div1" tabindex="0">Hide Me</span>
<span class="div2" tabindex="0">Show Me</span>


body {
  display: block;
}
.div1:focus ~ .showMe {
  display: none;
}
.div2:focus ~ .showMe {
  display: block;
}

<p class="showMe" >Show and hide me</p>