我目前有一个与javascript代码链接的HTML页面,它允许我按下一个显示隐藏div内容的按钮。该功能工作正常,但是当按下按钮时,隐藏的div会显示在按钮上方。无论如何,它可以下降到按钮下方,而不是下降。这里是我使用的代码:按下按钮时下拉div
HTML:
<div id="spoiler1" style="display:none">
<p>1. Climb a tree<input type="checkbox"></p>
<p>2. Roll down a really big hill<input type="checkbox" ></p>
<p>3. Camp out in the wild<input type="checkbox" ></p>
<p>4. Build a den<input type="checkbox" ></p>
<p>5. Skim a stone<input type="checkbox" ></p>
<p>6. Run around in the rain<input type="checkbox" ></p>
<p>7. Fly a kte<input type="checkbox" ></p>
<p>8. Catch a fish with a net<input type="checkbox" ></p>
<p>9. Eat an apple straight from a tree<input type="checkbox" ></p>
<p>10. Play conkers<input type="checkbox" ></p>
</div>
<button id="button1" title="Click to show/hide content" type="button1" onclick="readmore1()">Adventurer ▼</button>
<div id="spoiler1" style="display:none">spoiler text</div>
的Javascript:
function readmore1(){
var spoiler1 = document.getElementById('spoiler1');
var btn = document.getElementById('button1');
if(spoiler1.style.display=='none') {
spoiler1.style.display = '';
btn.innerHTML = "Adventurer ▲";
} else {
spoiler1.style.display = 'none';
btn.innerHTML = "Adventurer ▼";
}
}
任何帮助将非常感激。
CSS:
#button1 {
display: inline-block;
font: normal 1.5em optima;
line-height: 10px;
margin-left: -10px;
margin-bottom:20px;
width: 250px;
height:60px;
border-radius:8px;
text-align: center;
vertical-align: central;
color: #fff;
border: none;
position: relative;
top: -5px;
left: 30px;
}
你可以发布你的CSS? –
你的意思是你想显示按钮下方的隐藏div吗? –
你应该永远不要多使用一次ID!扰流1被使用两次。也许位置:相对;在父divs和按钮可以解决你的问题,但要确保你应该分享你的css – caramba