<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>填充</title>
<style type="text/css">
#box1{
display:inline;
width:80px;
height:50px;
padding:50px 10px 40px 10px;
border:1px solid red;
text-align:center;
margin:1px;
}
#box2{
display:inline;
width:80px;
height:50px;
padding:50px 10px 40px 10px;
border:1px solid red;
text-align:center;
margin:1px;
}
</style>
</head>
<body>
<div id="box1">盒子1</div>
<div id="box2">盒子2</div>
</body>
</html>
为何他们不能贴合在一起?
我都把margin设为0了。
你们好像都没有注意他写的是“display:inline;”,把这个改成“display:inline-block;”后,然后在“#box2“加个“margin:-5px;”就行了
你们好像都没有注意他写的是“display:inline;”,把这个改成“display:inline-block;”后,然后在“#box2“加个"margin:-5px"就行了。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>填充</title>
<style type="text/css">
body {
font-size: 0;
}
* {
margin: 0;
padding: 0;
}
#box1 {
display: inline;
padding: 50px 10px 40px 10px;
border: 1px solid red;
text-align: center;
font-size: 20px;
}
#box2 {
display: inline;
padding: 50px 10px 40px 10px;
border: 1px solid red;
text-align: center;
font-size: 20px;
}
</style>
</head>
<body>
<div id="box1">盒子1</div>
<div id="box2">盒子2</div>
</body>
</html>
加float:left 或者 直接在你这个代码的基础上 给它的父元素 也就是body 设置一个font-size大小为0
加个左浮动,然后外边距为0
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>填充</title> <style type="text/css"> div{ width:80px; height:50px; padding:50px 10px 40px 10px; border:1px solid red; text-align:center; float: left; } </style> </head> <body> <div id="box1">盒子1</div> <div id="box2">盒子2</div> </body> </html>
我是从后面。
float: left;
margin:1px; margin要为0
改成<div id="box1">盒子1</div><div id="box2">盒子2</div>,两行写成一行,
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>填充</title>
<style type="text/css">
#box1,#box2{
display:inline;
width:80px;
height:50px;
padding:50px 10px 40px 10px;
border:1px solid red;
text-align:center;
margin:0;
float:left;
}
</style>
</head>
<body>
<div id="box1">盒子1</div>
<div id="box2">盒子2</div>
</body>
</html>