我一直在为我的实习写一个概念设计时遇到困难,即时通过六个可点击的元素(它们是图片)去寻找页面。一旦点击了其他人,其他人就会消失,活跃的人就会移动到顶部。我通过使用左侧定位和jquery来完成所有这些工作。然而,在左侧定位的情况下,这些元素将以不同的屏幕分辨率移动。所以我决定使用浮动,所以有位置将是不变的。我需要左边浮动的元素与右对齐的浮线垂直排列。这是它目前的样子的截图。 click here这就是我想要的样子。 finished look格式化浮动元素在同一水平
这里是我当前的代码
<html>
<head>
<title> Div Blocks</title>
<style type="text/css">
body {
background: url(bgp.jpg) no-repeat fixed center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height:100%;
width:100%;
}
div.sep {
clear: both;
}
div.full
{
left:50%;
height:auto;
width:auto;
}
a{
cursor : url("nav.png"), pointer;
}
div.one a
{
top:50px;
float:left;
width: 400px;
height: 100px;
text-decoration:none;
background:url("branding.png");
background-repeat:no-repeat;
padding-bottom:35px;
}
div.one a:hover
{background: url("brandingalt.png");
background-repeat:no-repeat;
}
div.one a:active
{background: url("brandingalt.png");
background-repeat:no-repeat;
}
div.two a
{
top:264px;
float:left;
width: 400px;
height: 100px;
text-decoration:none;
background:url("marketing.png");
background-repeat:no-repeat;
padding-bottom:35px;
}
div.two a:hover
{background: url("marketingalt.png");
background-repeat:no-repeat;
}
div.three a
{
top:457px;
float:left;
width: 500px;
height: 100px;
text-decoration:none;
background:url("ecommerce.png");
background-repeat:no-repeat;
padding-bottom:20px;
}
div.three a:hover
{background: url("ecommercealt.png");
background-repeat:no-repeat;
}
div.r1 a
{
top:50px;
float:right;
width: 400px;
height: 100px;
text-decoration:none;
background:url("webdesign.png");
background-repeat:no-repeat;
padding-bottom:25px;
}
div.r1 a:hover
{background: url("webdesignalt.png");
background-repeat:no-repeat;
}
div.r2 a
{
top:254px;
float:right;
width: 450px;
height: 150px;
text-decoration:none;
background:url("optimization.png");
background-repeat:no-repeat;
padding-bottom:20px;
}
div.r2 a:hover
{background: url("optimizationalt.png");
background-repeat:no-repeat;
}
div.r3 a
{
top:457px;
float:right;
width: 400px;
height: 75px;
text-decoration:none;
padding-bottom: 20px;
background:url(packaging.png);
background-repeat:no-repeat;
}
div.r3 a:hover
{background: url("packagingalt.png");
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div class="one">
<a href="#" value="Branding" class="go" ></a>
</div><div class="sep"></div>
<div class="r1">
<a href="#"class="go" ></a>
</div><div class="sep"></div>
<div class="two">
<a href="#" class="go"></a>
</div><div class="sep"></div>
<div class="r2">
<a href="#"class="go" ></a>
</div><div class="sep"></div>
<div class="three">
<a href="#"class="go" ></a>
</div><div class="sep"></div>
<div class="r3">
<a href="#"class="go" ></a>
</div><div class="sep"></div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
$("a").click(function(event){
event.preventDefault(); // prevent the link from changing the location
$(this)
.closest("div") // select the parent div of the link
.siblings() // select all the siblings of the div
.hide("slow") // hide them
setTimeout(function() {
$(".go").animate({top: "0"}, "slow");},1500);
});
这里是我的旧代码
<html>
<head>
<title> Div Blocks</title>
<style type="text/css">
html {
background: url(bgo.jpg) no-repeat fixed center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
a{
cursor : url("nav.png"), pointer;
}
div.one a
{
position:absolute;
top:50px;
left:60px;
width: 400px;
height: 100px;
text-decoration:none;
background:url("branding.png");
background-repeat:no-repeat;
padding-bottom:35px;
}
div.one a:hover
{background: url("brandingalt.png");
background-position: 0px 0px;
background-repeat:no-repeat;
}
div.one a:active
{background: url("brandingalt.png");
background-position: 0px 0px;
background-repeat:no-repeat;
}
div.two a
{
position: absolute;
top:264px;
left:60px;
width: 400px;
height: 100px;
text-decoration:none;
background:url("marketing.png");
background-repeat:no-repeat;
padding-bottom:35px;
}
div.two a:hover
{background: url("marketingalt.png");
background-position:0px 0px;
background-repeat:no-repeat;
}
div.three a
{
position: absolute;
top:457px;
left:56px;
width: 500px;
height: 100px;
text-decoration:none;
background:url("ecommerce.png");
background-repeat:no-repeat;
padding-bottom:20px;
}
div.three a:hover
{background: url("ecommercealt.png");
background-position: 0 0px;
background-repeat:no-repeat;
}
div.r1 a
{
position: absolute;
top:50px;
left:900px;
width: 400px;
height: 100px;
text-decoration:none;
background:url("webdesign.png");
background-repeat:no-repeat;
padding-bottom:25px;
}
div.r1 a:hover
{background: url("webdesignalt.png");
background-position: 0px 0px;
background-repeat:no-repeat;
}
div.r2 a
{
position: absolute;
top:254px;
left:900px;
width: 450px;
height: 150px;
text-decoration:none;
background:url("optimization.png");
background-repeat:no-repeat;
padding-bottom:20px;
}
div.r2 a:hover
{background: url("optimizationalt.png");
background-repeat:no-repeat;
}
div.r3 a
{
position: absolute;
top:457px;
left:900px;
width: 400px;
height: 75px;
text-decoration:none;
padding-bottom: 20px;
background:url(packaging.png);
background-repeat:no-repeat;
}
div.r3 a:hover
{background: url("packagingalt.png");
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div class="one">
<a href="#" value="Branding" class="go" ></a>
</div>
<div class="two">
<a href="#" class="go"></a>
</div>
<div class="three">
<a href="#"class="go" ></a>
</div>
<div class="r1">
<a href="#"class="go" ></a>
</div>
<div class="r2">
<a href="#"class="go" ></a>
</div>
<div class="r3">
<a href="#"class="go" ></a>
</div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
$("a").click(function(event){
event.preventDefault(); // prevent the link from changing the location
$(this)
.closest("div") // select the parent div of the link
.siblings() // select all the siblings of the div
.hide("slow") // hide them
setTimeout(function() {
$(".go").animate({top: "0"}, "slow");},1200);
});
</script>
如果它会更容易修复旧代码,以使元素常数会更好。
能否详细介绍一下如何使用(display:table/table-cell) – matture
也许这个[jsfiddle](http://jsfiddle.net/NXZzN/)可以更好地解释它。 – kojiro
之前我尝试重新编码整个事情我有几个问题, 1.我能够使用悬停效果来更改图像 2.我仍然能够使用jquery函数来隐藏元素并提高点击时他们中的一个到顶部? – matture