English 中文(简体)
添加div至具有绝对地位的母方
原标题:Add div to parent with absolute position

我有一个家长Div 有时尚位置 相对和情侣Divs 里面的情侣Divs 与时尚绝对一样

<div id="container" style="position:relative;width=400px;height=400px;">
<div style="top:20px;left:20px;width:20px;height:20px;"></div>
<div style="top:40px;left:40px;width:20px;height:20px;"></div>
<div style="top:60px;left:60px;width:20px;height:20px;"></div>
</div>

如何在 div 中添加新的 div 和 < code> = " container" 和 < code > top= "0px" 左键= "0px" ?

最佳回答
$( #container ).append(
    $( <div/> ).css({top: 0px ,left: 0px })
);

这里举个活生生的例子:http://jsfiddle.net/AWYbD/

问题回答

首先, 要小心地将“ 位置: 绝对” 设置在您的内部 divs 上方 、 左方 等 声明 。 使用 上方 、 左方 等 声明 时, 这并不隐含设置 。

添加一个新的 div (我假设使用jquery),

只是做做

$( #container ).append( <div style="position:asbolute; top: 0px; left: 0px;"></div> );




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签