gpt4 book ai didi

html - 与文档流一起使用的固定大小的 div/span

转载 作者:太空宇宙 更新时间:2023-11-04 05:14:42 24 4
gpt4 key购买 nike

我正在尝试使用 HTML/CSS/JavaScript 制作一个 iOS 风格的切换开关。在这一点上,我对结果非常满意。我在让它作为一个可以与其他内容内联的元素时遇到了很多麻烦。如果我将容器元素设为跨度,内容的结构就会“分崩离析”。任何恢复该内容的尝试(例如显示: block )都会修复内容,但会再次中断流程。

当前版本是 here , 并转载如下。所有资源(mootools 和 handle 图像)都在线且绝对链接,如果您有尝试任何修复的冲动。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Slider experiment</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js"></script>

<style type="text/css">

.slider {
border : thin solid #808080;
display : block;
width : 90px;
overflow : hidden;
font-family : sans-serif;
font-size : 80%;
margin : 10px;

cursor : pointer; /* We don't want the text selection cursor here */

-moz-border-radius : 3px;
-webkit-border-radius : 3px;
-khtml-border-radius : 3px;
border-radius : 3px;

opacity : 0.99; /* Completely transparent isn't clickable in Firefox */
}

.slider div {
width : 200px; /* More than enough for contents, to avoid wrapping */
display : block;

position : relative; /* So that the z-index has an effect */
z-index : -1;

}

.slider div span {
text-align : center;
line-height : 19px;
padding-top : 1px;
height : 19px;
float : left;
width : 62px;
font-weight : bold;

-moz-border-radius : 2px;
-webkit-border-radius : 2px;
-khtml-border-radius : 2px;
border-radius : 2px;

}


.slider div span.tab {
padding-top : 0px;
width : 32px;
margin-left : -3px;
margin-right : -3px;

position : relative; /* So that the z-index has an effect */
z-index : 0;
}

.slider div span.on {
background-color : #4040ff;
color : #E0E0E0;
}

.slider div span.off {
background-color : #E0E0E0;
color : #a0a0a0;
}

</style>

<script type="text/javascript">
<!--
function switchOff(itm)
{
console.log("Switching off");
itm.fx.start('-60px');
itm.state = 0;
}

function switchOn(itm)
{
console.log("Switching on");
itm.fx.start('0px');
itm.state = 1;
}

window.addEvent('domready', function() {

$$('.slider').each( function(itm) {

itm.fx = new Fx.Tween(itm.getChildren()[0], {duration: '125', property: 'margin-left'});
itm.state = 1;
itm.addEvent('click', function() {
if (itm.state==1)
{
switchOff(itm);
}
else
{
switchOn(itm);
}
});
});
});

//-->
</script>

</head>
<body>
<div style="width: 400px; margin: 10px">
Switch :
<div class="slider">
<div><span class="on">ONLINE</span><span class="tab"><img src="http://azureblue.org/so/handle.png" width=32px height=20px></span><span class="off">OFFLINE</span></div>
</div>

<div class="slider">
<div><span class="on">ON</span><span class="tab"><img src="http://azureblue.org/so/handle.png" width=32px height=20px></span><span class="off">OFF</span></div>
</div>

</div>
</body>
</html>

我真正希望能够做的是可以选择将控件放置在流中的任何位置,这样我可以根据需要将两个控件并排放置,或者放在连续的行上。

(是的,它应该是一个合适的 Mootools 类——那是下一个工作!)

最佳答案

您可以使用display: inline-block

你仍然会有 block 属性、宽度、高度、填充、边距属性,但仍然很容易在内联布局(即表单或其他一些布局)中显示。

关于html - 与文档流一起使用的固定大小的 div/span,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8457143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com