[英]How do I make the text my button toggles to appear right next to my button instead of on a new line?
這是我的代碼
<script type="text/javascript">
function toggle(obj) {
var obj=document.getElementById(obj);
if (obj.style.display == "block") obj.style.display = "none";
else obj.style.display = "block";
}
<body>
<button type="button" style="width: 150px; height: 50px;"
onClick="toggle('miniDisplay')"> minicom </button>
<div id="miniDisplay" style="display:none;">
<p style="text-align:center;">connect to minicom and display</p></div>
</body>
當前,文本在按鈕所在的位置下方顯示一行。 我希望它顯示在同一行上。 我知道它是居中對齊的,它位於另一行按鈕的下方。
在您的JavaScript中將“阻止”更改為“內聯阻止”。
您的div是一個塊級元素,這意味着它將擴展以占據其容器的整個寬度。 改為將其更改為inline-block。
function toggle(obj) {
var obj=document.getElementById(obj);
if (obj.style.display == "inline-block") obj.style.display = "none";
else obj.style.display = "inline-block";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.