Javascript 在网页上水平对齐时钟

Javascript 在网页上水平对齐时钟,javascript,html,css,Javascript,Html,Css,我希望时钟在我正在设计的网页上显示不同的时区。为此,我嵌入了一个名为qlock的webiste中的javascript文件。HTML代码如下: <script type="text/javascript"> qlock_city_name="Adelaide"; qlock_gmt_offset=9.5; qlock_bg_color="#000000"; qlock_text_color="#ffffff"; qlock_dst_week1=1; qlock_dst_dow1=7;

我希望时钟在我正在设计的网页上显示不同的时区。为此,我嵌入了一个名为qlock的webiste中的javascript文件。HTML代码如下:

<script type="text/javascript">
qlock_city_name="Adelaide";
qlock_gmt_offset=9.5;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
</script>
<script type="text/javascript" src="http://www.qlock.com/live/qlock.js"></script>

<script type="text/javascript"><!--
qlock_city_name="Melbourne";
qlock_gmt_offset=10;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
//--></script>
<script type="text/javascript" src="http://www.qlock.com/live/qlock.js"></script>

qlock_city_name=“阿德莱德”;
qlock_gmt_偏移量=9.5;
qlock_bg_color=“#000000”;
qlock_text_color=“#ffffff”;
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
这样做的目的是将阿德莱德和墨尔本的时钟一个接一个地显示出来。 有没有办法将它们水平地相邻显示?

用div把钟包起来,把浮子给它

<div class="left"><script type="text/javascript">
qlock_city_name="Adelaide";
qlock_gmt_offset=9.5;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
</script>
<script type="text/javascript" src="http://www.qlock.com/live/qlock.js"></script>
    </div>
<div class="left">
<script type="text/javascript"><!--
qlock_city_name="Melbourne";
qlock_gmt_offset=10;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
//--></script>
<script type="text/javascript" src="http://www.qlock.com/live/qlock.js"></script>
    </div>

您可以将时钟上的css属性设置为向左浮动

#qlock1, #qlock2{
    float: left;
}
演示


另外,您可以为所有时钟设置一个公共类,而不必担心css中的每个id

我的方法是将脚本放在一个简单的表中

<table style="table-layout:fixed;width:600px;">
  <tr height="30">
    <td width="150"><script type="text/javascript"><!--
qlock_city_name="Melbourne";
qlock_gmt_offset=10;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
//--></script>
<script type="text/javascript" src="qlock.js"></script>
</td>
    <td width="200"><script type="text/javascript">
qlock_city_name="Adelaide";
qlock_gmt_offset=9.5;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
</script>
<script type="text/javascript" src="qlock.js"></script>
</td>
    <td width="250">CSS table layout cell 3</td>
  </tr>
</table>

qlock_city_name=“阿德莱德”;
qlock_gmt_偏移量=9.5;
qlock_bg_color=“#000000”;
qlock_text_color=“#ffffff”;
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
CSS表格布局单元3

里面没有多少HTML。这是javascript。将它们包装在div中并向左浮动您的第二个左
div
未关闭。这工作非常好。但是,我有7个时钟要显示,在第3个时钟之后,接下来的四个将显示在下一行中..我如何强制所有7个将显示在一个水平行中您必须为显示此时钟的容器设置固定宽度。。tats为什么在溢出后显示在下一行。尝试为父容器设置更大的宽度。没有父容器。代码完全如您所建议的那样。上面的每一行只需再重复4次,每一次都包装在您所建议的div中。不,我不是在说我的代码,我的代码是正确的,您可以将其放在网页的某个位置,因此,你必须看看网页中有多少可用空间,这样7个时钟就可以放进去。也许是这样,@Amistad希望7个时钟水平对齐。与CSS浮动相比,table方法可以更系统地完成这项工作。
<table style="table-layout:fixed;width:600px;">
  <tr height="30">
    <td width="150"><script type="text/javascript"><!--
qlock_city_name="Melbourne";
qlock_gmt_offset=10;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
//--></script>
<script type="text/javascript" src="qlock.js"></script>
</td>
    <td width="200"><script type="text/javascript">
qlock_city_name="Adelaide";
qlock_gmt_offset=9.5;
qlock_bg_color="#000000";
qlock_text_color="#ffffff";
qlock_dst_week1=1;
qlock_dst_dow1=7;
qlock_dst_month1=10;
qlock_dst_week2=1;
qlock_dst_dow2=7;
qlock_dst_month2=4;
</script>
<script type="text/javascript" src="qlock.js"></script>
</td>
    <td width="250">CSS table layout cell 3</td>
  </tr>
</table>