从here可以看出,我在对齐<div>标记时遇到了几个问题。布局是这样的:我有一个容器头部,里面有一个头部,一个脚注,在它们之间有两个向右和向左的div。我的问题是右边和页脚没有居中对齐,尽管它们应该从<body>标记继承它。
此外,由于某些原因,页面可能会向右滚动一点,而在这一小部分,背景是没有颜色的。
这是我的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Rock-paper-scissers</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script src="rps.js"></script>
<style type="text/css">
body{
width: 100%;
font: 100.01% "Trebuchet MS",Verdana,Arial,sans-serif;
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#93e1d1), to(#d4c87c));
background-image: -webkit-linear-gradient(left, #93e1d1, #d4c87c);
background-image: -moz-linear-gradient(top, #93e1d1, #d4c87c);
background-repeat: no-repeat;
}
div#footer {
width: 100%;
}
div#container {
text-align: center;
}
div.InnerLeft {
width: 50%;
position: relative;
float: left;
}
div.InnerRight {
width: 50%;
position: relative;
float: right;
}
select {
background: transparent;
width: 220px;
padding: 5px;
font-size: 16px;
border: 0px;
height: 34px;
}
img#andale {
margin-left: auto;
margin-right: auto;
margin-left: 100px;
}
</style>
</head>
<body>
<div id="container">
<img src="header.png">
<div class="InnerLeft">
<img src="uno.png"><br>
<select id="p1" onchange="change('p1','rpsleft')">
<option value=0>Choose your weapon</option>
<option value=1>Rock</option>
<option value=2>Paper</option>
<option value=3>Scissors</option>
</select>
<p><img src="rpsL.png" id="rpsleft"></p>
</div>
<div class="InnerRight">
<img src="dos.png"><br>
<select id="p2" style="margin-left:45%;" onchange="change('p2','rpsright')">
<option value=0>Choose your weapon</option>
<option value=1>Rock</option>
<option value=2>Paper</option>
<option value=3>Scissors</option>
</select>
<p><img src="rps.png" id="rpsright" style="margin-left:45%;"></p>
</div>
<div id="footer">
<img src="andale.png" id="andale" onclick="rps(document.getElementById('p1').value,document.getElementById('p2').value)"
onMouseOver="document.getElementById('andale').src='andale2.png'"
onMouseOut="document.getElementById('andale').src='andale.png'">
</div>
</div>
</body>你知道我该怎么解决这两个小问题吗?
谢谢!
附注:我试着将图片来源设置为我的dropbox和google drive账户,这样就可以在jsFiddle上看到它们,但它不起作用。关于我可以使用哪个网站,有什么建议吗?
发布于 2012-11-10 23:57:38
好的,有几件小事……
(示例:http://jsfiddle.net/mori57/cr8s8/29/)
<!-- for one, without a specified width and height
the browser doesn't know how to flow the other elements
around this object ... I used placehold.it to show you what
happens if you put in an object with actual dimensions -->
<img src="http://www.placehold.it/400x50">如果没有指定尺寸的图像,因为该图像不能由浏览器加载,所以浏览器会将其默认为一个非常小的图像,并且第一个浮动会在其前面进行包装,就像float:left要求的那样。
也可以/可以/将这些浮点数包装在一个容器中,并强制将其清除:both,这样它就可以避免浮动在头图像的前面。
其次:
<!-- Your extra space was due to the margin-left you shimmed onto
this select tag. If you take it out, the extra horiz
scrolling goes away -->
<select id="p2" onchange="change('p2','rpsright')">请记住,带有边距/inside/ another container /的对象可以“戳穿”容器的边界。因此,它将其边缘添加到其容器的边缘,并将自己推向容器的“墙”,从而增加了所需的水平空间。
https://stackoverflow.com/questions/13323376
复制相似问题