【发布时间】:2021-01-20 20:50:44
【问题描述】:
我正在尝试制作一个如图所示的盒子。
但我的小盒子的边框位于大盒子的内部,而不是坐在大盒子边框的顶部。
我需要让粉红色的“鸡肉”小盒子正好位于灰色大盒子的右上角。
<!DOCTYPE html>
<html>
<head>
<title>Coursera Assignment 1</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<style type="text/css">
* {
box-sizing: border-box;
margin:0px;
font-family: Helvetica, Arial, sans-serif;
line-height: 1.3;
}
h2.chicken {
background-color: #D59898;
border: 2px solid black;
text-align: center;
width: 100px;
margin: 0px 10px 0px 0px;
float: right;
margin-right: 0px;
}
div.chicken {
background-color: grey;
border: 2px solid black;
width: 30%;
position: relative;
}
p.chicken {
clear: right;
padding: 10px;
}
</style>
</head>
<body>
<h1>Our Menu</h1>
<div class="chicken">
<h2 class="chicken">Chicken</h2>
<p class="chicken">Spacing: Pay attention to the spacing shown in the mockup illustrations. Note the spacing between sections (both horizontal and vertical). Note the horizontal spacing between the edges of the section and the edges of the browser window. Also, note the spacing between the dummy text in each section and the edges of the section. Lastly, make sure the dummy text is "pushed down" enough so it</p>
</div>
</body>
</html>
【问题讨论】:
-
这是一个简单的,设置为较小的框边框-左和下,右和上将取自父 :)
-
谢谢 我最初尝试过,但使用了错误的边框技术:0px 0px 2px 2px;感谢您向我展示正确的方法!
-
只需将
border-right: 0和border-top: 0添加到h2.chicken