Chrome 中的绝对定位?
它适用于 IE/FF,但不适用于 Chrome。
html += '<div id = "note" style = "position: absolute; background-color:'
+ newcss[0] + '; margin-left:'
+ newcss[1] + '; margin-top:'
+ newcss[2] + '; width = 100px; height = 100px;">'
+ newnote + '</div>';
基本上,我在页面中添加了一个新注释,具有随机颜色,以及从左侧和顶部的位置(存储在 newcss 中)。
IE 与 Chrome 的图片(左侧为 IE):
https://i.sstatic.net/LFZhD.png< /a>
编辑:是的,这是一个错误; width: 和 height: 将其修复为实际上正确的大小,但它们仍然全部粘贴在栏下方的同一个位置,而不是随机空格
编辑2:我最初将它们作为单独的 id (我只是在乱搞jquery看东西哈哈)
It works in IE/FF but not Chrome.
html += '<div id = "note" style = "position: absolute; background-color:'
+ newcss[0] + '; margin-left:'
+ newcss[1] + '; margin-top:'
+ newcss[2] + '; width = 100px; height = 100px;">'
+ newnote + '</div>';
Basically I am adding a new note into the page, with random colors, and position from left and top (stores in newcss).
Pic of IE vs Chrome (IE on left):
https://i.sstatic.net/LFZhD.png
EDIT: Yah that was a mistake; width: and height: fixes it to actually be the right size, but they still are all just pasted on the same spot right under the bar, rather than random spaces
EDIT2: I originally had them as separate ids (I was just messing around with jquery to see something haha)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给它 css
或只是
give it css of
or just
CSS 不正确。 Css 样式规则的格式为
key:val;
,而不是key=vale
。绝对定位允许您定义top
left
bottom
和right
值,并将对象放置在该位置(相对位置)到页面或包含元素(如果该元素设置了position:relative
))。使用它们来放置绝对元素。另外,您可能应该使用 DOM 对象而不是innerHTML。
更好的是,将永远不会改变的内容定义为样式规则,然后使用 Javascript 仅设置动态内容。
然后你所要做的就是设置
top
left
和background-color
The css is incorrect. Css Style rules are in the form
key:val;
rather thankey=vale
. Absolute positioning allows you to definetop
left
bottom
andright
values and places the object at that position ( either relative to the page or to the containing element ( if that element hasposition:relative
set )). Use those for the placement of absolute elements.Also you should probably be using the DOM objects rather than innerHTML.
Better even yet, defined the stuff that never changes as a style rule and then use the Javascript to only set the dynamic content.
Then all you have to do is set
top
left
andbackground-color
请尝试以下操作:
更改:
id
更改为class
;在一个文档中两个元素具有相同的id
是无效的。margin-left
和margin-top
更改为left
和top
。Try this instead:
Changes:
id
toclass
; it is invalid for two elements to have the sameid
in one document.margin-left
andmargin-top
toleft
andtop
.