JavaScript 居中对齐
如何将整个脚本居中对齐?我以前从未真正用 JavaScript 编写过代码,我只想修改一个快速书签。我已经尝试过像align=center这样的东西来处理脚本的不同组件,但没有运气。 js 有类似
(在 html 中)的东西吗?谢谢
编辑:基本上我希望它集中在页面上
function dEmbed(){
var iframe = document.createElement("iframe");
iframe.src = 'http://www.google.com';
iframe.style.width = w+'px';
iframe.style.height= h+'px';
iframe.style.border= "0";
iframe.style.margin= "0";
iframe.setAttribute("scrolling","no");
iframe.setAttribute("id","NAME");
document.body.insertBefore(iframe, document.body.firstChild);
}
How can I align the entire script to center? I've never actually coded before in javascript and I just want to modify a quick bookmarklet. I've tried stuff like align=center for different components of the script but no luck. Is there something like <center>
(in html) for js?
Thanks
EDIT: basically i want this to be centered on a page
function dEmbed(){
var iframe = document.createElement("iframe");
iframe.src = 'http://www.google.com';
iframe.style.width = w+'px';
iframe.style.height= h+'px';
iframe.style.border= "0";
iframe.style.margin= "0";
iframe.setAttribute("scrolling","no");
iframe.setAttribute("id","NAME");
document.body.insertBefore(iframe, document.body.firstChild);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过使用
text-align: center
将 iframe 注入到现有的 div 中来实现这一点。这是示例: http://jsfiddle.net/MarkKramer/PYX5s/4/
I was able to achieve this by injecting the iframe into an existing div with
text-align: center
.Here is the example: http://jsfiddle.net/MarkKramer/PYX5s/4/
您无法将脚本居中,它看起来不像任何东西,所以没有任何东西可以居中。
如果脚本生成一些 HTML,那么您可以将生成的元素居中。这应该使用应用于生成元素的常用 CSS 技术来完成。
(
和
align
属性为 已于 1998 年弃用,不应使用)。You can't centre a script, it doesn't look like anything so there is nothing to centre.
If the script generates some HTML, then you can to centre the generated elements. This should be done using the usual CSS techniques applied to the generated element.
(
<center>
and thealign
attribute were deprecated in 1998 and shouldn't be used).尝试更改:
至:
如果不起作用,请在评论中告诉我。
好的,尝试这个更改,将:更改
为:
并将:更改
为:
Try changing:
To:
If it doesn't work, let me know in a comment.
OK, try this change instead, change:
to:
And change:
To: