我使用javascript在div中插入段落。它的作用是在单击按钮并将其作为段落附加到特定div时获取输入表单的值。问题是他们的余量太大而且我不知道如何减少它们(让它们更接近)。在这种情况下我该怎么做?
jsfiddle - 无论如何,我的代码看起来像这样:
<div id="red">
<button id="bt_1" onclick="addParagraph()">Add</button>
<form>
<input id="box_top" type="text" placeholder="Spacing is too big -->">
</form>
</div>
<div id="blue">
<!--Paragraphs that are being added here have their top and bottom margin too big, but I don't know how to fix it.-->
<!--Type something in thet input form and keep clicking the add button to see what I mean.-->
</div>
#blue {
height:100px;
width:250px;
margin-top: 10px;
float:left;
position:relative;
background-color:blue;
overflow:auto;
}
#red {
height:100px;
width:250px;
margin-top: 10px;
float:left;
position:relative;
background-color:red
}
form {
font-size: 12px;
font-family: Verdana, Arial, Sans-Serif;
display: inline-block;
}
#bt_1 {
margin-left:5px;
height:35px;
width:70px;
margin-top: 25px;
border-radius:5px;
}
function addParagraph() {
var word = document.getElementById("box_top").value;
var pMaker = document.createElement("p");
var nodeMaker = document.createTextNode(word);
pMaker.appendChild(nodeMaker);
var blueDiv = document.getElementById("blue");
blueDiv.appendChild(pMaker);
}
答案 0 :(得分:1)
您可以使用css修改边距。
#blue p{
margin:0;
}
答案 1 :(得分:0)
答案 2 :(得分:0)
只需应用css
即可#blue p {
margin: 5px;
}
或任何其他数字而不是5你要添加
答案 3 :(得分:0)
你可以简单地将这样的东西添加到css:
#blue p {
margin: 2px auto;
}
此致
答案 4 :(得分:0)
在您的css中添加: Demo
p {
line-height: normal;
margin: 0;
}