保证金顶部不会移动个别元素

问题描述 投票:0回答:2

我正在尝试使用名称框创建一个水平的注释框,因为文本框已固定在顶部。当我尝试在文本区域和表单上应用margin-top时,它会移动名称框和整个配置文件。有没有办法将文本区域向下移动,而不会影响其他任何内容。这是我的代码:

body {
	margin: 0;
}
p.name {
	font-family: "Roboto";
	margin-top: 90px;
	margin-left: 50px;
	margin-bottom: 0;
	border: 1px solid black;
	display: inline-block;
	padding: 20px 70px;
	font-size: 25px;
}
div.info {
	margin-left: 50px;
	border: 1px solid black;
	padding: 20px 13.5px 20px;
	border-top: none;
	display: inline-block;
	margin-bottom: 0;
}
div.date {
	margin-left: 50px;
	border: 1px solid black;
	border-top: none;
	display: inline-block;
	padding: 0px 17px 0px;
	text-align: center;
}
form {
	display: inline-block;
	margin-left: 100px;
}
textarea {
  width: 300px;
  height: 150px;
  display: inline-block;
  padding: 12px 20px;
  box-sizing: border-box;
  border: 2px solid #ccc;
  border-radius: 4px;
  background-color: #f8f8f8;
  font-size: 16px;
  resize: none;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="profile.css">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
</head>
<body>
<p class="name">henWrek</p>
<form>
<label for="fname">Profile Comments:</label>
<br>
<textarea>Enter your comment here...</textarea>
</form>
<br>
<div class="info">
<img src="default.jpg" height="200" width="210">
</div>
<br>
<div class="date">
<p>Joined: 11/1/2018</p>
<p>Last Online: 11/9/2018 3:21PM</p>
<p>Post Count: 2</p>
</div>
</body>
</html>
html css margin
2个回答
0
投票

另一种选择是在label标签上放置一个位置,此标签具有相对位置,您可以根据需要更改顶部和右侧。

body {
	margin: 0;
}
p.name {
	font-family: "Roboto";
	margin-top: 90px;
	margin-left: 50px;
	margin-bottom: 0;
	border: 1px solid black;
	display: inline-block;
	padding: 20px 70px;
	font-size: 25px;
}
  
div.info {
	margin-left: 50px;
	border: 1px solid black;
	padding: 20px 13.5px 20px;
	border-top: none;
	display: inline-block;
	margin-bottom: 0;
}
label{
    position:relative;
    top:50px;
    right:100px;
}
div.date {
	margin-left: 50px;
	border: 1px solid black;
	border-top: none;
	display: inline-block;
	padding: 0px 17px 0px;
	text-align: center;
}
form {
	display: inline-block;
	margin-left: 100px;
}
textarea {
  width: 300px;
  height: 150px;
  display: inline-block;
  padding: 12px 20px;
  box-sizing: border-box;
  border: 2px solid #ccc;
  border-radius: 4px;
  background-color: #f8f8f8;
  font-size: 16px;
  resize: none;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="profile.css">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
</head>
<body>
<p class="name">henWrek</p>
<form>
<label class="label-prueba" for="fname"> Profile <br> Comments:</label>
<br>
<textarea>Enter your comment here...</textarea>
</form>
<br>
<div class="info">
<img src="default.jpg" height="200" width="210">
</div>
<br>
<div class="date">
<p>Joined: 11/1/2018</p>
<p>Last Online: 11/9/2018 3:21PM</p>
<p>Post Count: 2</p>
</div>
</body>
</html>

0
投票

我已经看到你的代码并找到了你的问题,我的建议是在你的.textarea类中添加两个属性,那就是position:relativetop根据你的要求。

textarea{
   position:relative;
   top:100px;
}
© www.soinside.com 2019 - 2024. All rights reserved.