html - 为什么在div中添加文本时会出现空隙?

标签 html vertical-alignment css

当我将文本添加到 textboxsquare 时,它​​会在 Div 上方添加一个空格,这是为什么?我该如何制作它,以便没有这个空间,只是与另一个保持一致? http://jsfiddle.net/wK6dp/1/

CSS

#textbox {
   border: 1px solid #848484;
   -moz-border-radius-topleft: 30px;
   -webkit-border-top-left-radius: 30px;
   border-top-left-radius: 30px;
   -moz-border-radius-topright: 30px;
   -webkit-border-top-right-radius: 30px;
   border-top-right-radius: 30px;
   outline:0;
   height:auto;
   display: block;
   box-sizing: border-box;
   width: 300px;
   padding-left:20px;
   padding-right:20px;
   background-color: #f47924;
   margin: 0px;
   font-family: 'Droid Sans', sans-serif;
   text-align:center;
   color:white;
}

#textboxSquare {
   display:inline-block;
   box-sizing: border-box;
   width: 150px;
   height: 150px;
   border: 1px solid #848484;
}

HTML

<div id="textbox">
    <h3>John Smith</h3>
</div>
<div id="textboxSquare"></div>
   <div id="textboxSquare">
       Copy Pasta pasta <br />
       Copy Pasta pasta <br />
       Copy Pasta pasta <br   />
       Copy Pasta pasta<br />
   </div>
</div>

最佳答案

使用vertical-align:top:

jsFiddle

#textboxSquare {
display: inline-block;
box-sizing: border-box;
width: 150px;
height: 150px;
border: 1px solid #848484;
vertical-align: top;    /*   added   */
}

关于html - 为什么在div中添加文本时会出现空隙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20185510/

相关文章:

html - 为什么这个 css vertical-align 不起作用

html - 根据行数动态地在 <div> 中垂直居中 <table>?

html - 如果我在其中插入文本,盒子就会跳闸

css - 使 <li> 列表图像可点击并保持格式

html - 使用 css3 flex 的砌体布局

html - 如何更改动画以使箭头向左?

css - 为文本区域制作一个标签,放在它旁边,但垂直居中对齐

html - 分页前 : avoid; Why is there still a page break?

javascript - asp.net/javascript,为什么文本框 onChange 事件不触发?

javascript - 如何删除 PowerBI Embedded iframe 滚动条(JavaScript API)?