gpt4 book ai didi

javascript - CSS:如何减少 div 中段落的边距?

转载 作者:行者123 更新时间:2023-11-28 17:35:04 25 4
gpt4 key购买 nike

我正在使用 javascript 在 div 中插入段落。它的作用是在您单击按钮并将其作为段落附加到特定的 div 时获取输入表单的值。问题是它们的余量太大,我不知道如何减少它们(使它们更接近)。在这种情况下我该怎么办?

jsfiddle- 不管怎样,我的代码是这样的:

HTML

<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>

CSS

#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;
}

JavaScript

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);
}

最佳答案

你可以用css修改边距。

#blue p{
margin:0;
}

关于javascript - CSS:如何减少 div 中段落的边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25260724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com