作者:aaron飞飞 | 来源:互联网 | 2023-01-05 23:35
图像是目标.我需要在框内正确定位每种颜色.它也必须位于浏览器的中心.我得到的结果正是图像只是单词.我真的在寻找一种更好的方法,因为我不得不猜测左下像素.我也知道它可以做得更好,真的很想学习如何.
.border{
border: 2px solid black;
width: 500px;
height: 700px;
margin:25px 450px;
padding: 1px;
}
#one {
background: red;
height:100px;
}
#two{
background: yellow;
height:600px;
width:100px;
}
#three {
background: blue;
height:550px;
width:300px;
position: relative;
left: 100px;
bottom: 600px;
}
#four{
background: yellow;
height: 600px;
width:100px;
position: relative;
left:400px;
bottom: 1150px;
}
#five{
background: green;
height:50px;
width:300px;
position: relative;
left: 100px;
bottom: 1200px;
}
1> Obsidian Age..:
个人而言,我会选择使用基于百分比的测量,这样你只需要更新width
和height
上.border
本身.对于.border
,我分别使用vw
和vh
单位为width
和height
,以便根据视口的大小调整表的大小.
请注意,您可能还希望使用类而不是ID,这样您就可以拥有多个表.我在我的示例中使用了类,并且还替换了名称以使位置标识符更加明显.
我还选择为元素#middle
和#bottom
元素创建一个容器,将它们视为一个单独的"列".通过这种方式,你可以使用float
对齐#left
,#middle_container
并且#right
列彼此相邻,而不必担心width
的#bottom
.
您可以通过添加margin: 0 auto
来使整个事物居中.border
,这是表示不应该有任何垂直边距的简写,并且应该自动计算水平边距(水平边缘使相关元素居中).
这可以在以下内容中看到:
.border {
border: 2px solid black;
width: 50vw;
height: 100vh;
padding: 1px;
margin: 0 auto;
}
.top {
background: red;
width: 100%;
height: 20%;
}
.left,
.middle_container,
.right {
float: left;
}
.left {
background: yellow;
width: 20%;
height: 80%;
}
.middle_container {
width: 60%;
height: 80%;
}
.middle {
background: blue;
height: 80%;
}
.bottom {
background: green;
height: 20%;
bottom: 0;
}
.right {
background: yellow;
width: 20%;
height: 80%;
}