gpt4 book ai didi

html - 如何在类似 metro 的 web GUI 中定位图标? (包括图像)

转载 作者:太空狗 更新时间:2023-10-29 14:13:39 24 4
gpt4 key购买 nike

我创建了一个简单、轻量级的 GUI,类似于 Microsoft Metro UI .它由一组 float 元素组成,可以根据屏幕大小灵活调整大小: enter image description here

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index2</title>
<style type="text/css">
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
html{
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
}
div.tiles{
background-color:black;
padding:50px;
}
div.tiles div{
border-radius:2px;
padding:10px;
margin:5px;
color:white;
background-color:#666;
display:marker;
cursor:pointer;
float:left;
width:25px;
height:25px;
}
div.tiles div:hover{
transition:background-color 1s;
-moz-transition:background-color 1s;
-webkit-transition:background-color 1s;
background-color:#060;
-moz-transform:rotate(6deg);
}
div.tiles div.icon{
position:relative;
bottom:0px;
left:0px;
z-index:10;
background-color:red;
}
div.tiles div.w1{width:25px;}
div.tiles div.w2{width:80px;}
div.tiles div.w3{width:160px;}
div.tiles div.w4{width:190px;}

div.tiles div.h1{height:25px;}
div.tiles div.h2{height:80px;}
div.tiles div.h3{height:160px;}
div.tiles div.h4{height:190px;}
</style>
</style>
</head>
<body>
<div class="tiles clearfix">
<div class="w4 h2">
mattberg@live.com <div class="icon">icon</div>
</div>
<div class="w4 h2">
RSS
</div>
<div class="w4 h2">
13
</div>
<div class="w2 h2">
IE
</div>
<div class="w2 h2">
Photo
</div>
<div class="w4 h2">
Now Playing
</div>
<div class="w4 h2">
Photo <div class="icon">icon</div>
</div>
<div class="w2 h2">
Shop
</div>
<div class="w2 h2">
SMS
</div>
<div class="w4 h2">
Weather <div class="icon">icon</div>
</div>
<div class="w4 h2">
Investment
</div>
<div class="w1 h1">
Lilly
</div>
<div class="w1 h1">
Lilly
</div>
<div class="w1 h1">
Lilly
</div>
<div class="w1 h1">
Lilly
</div>
<div class="w1 h1">
Lilly
</div>
<div class="w1 h1">
Lilly
</div>
<div class="w1 h1">
Lilly
</div>
</div>
</body>
</html>

我在 div 中定位图标元素时遇到问题。这是我的:

enter image description here

这就是我想要的:

enter image description here

换句话说,我希望能够绝对定位平铺 div 元素中的元素。我尝试了各种 CSS 定位技术(相对、固定、绝对)但无法解决。我怀疑这是因为图 block 是 float 元素?

如何设计每个磁贴的内容,而不管它在网页中的位置如何?

最佳答案

使 tile div 相对定位,使图标绝对定位。

.tiles > div {
float: left;
position: relative;
}

.tiles > div .icon {
position: absolute;
bottom: 0;
left: 0
}

通过相对定位,tile div 变为 containing block为其绝对定位的 child 。相关元素定位just like topleft 为零或未定义时的普通(静态)元素。

关于html - 如何在类似 metro 的 web GUI 中定位图标? (包括图像),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9430220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com