Align elements in td in one line

99封情书 提交于 2019-12-11 22:54:19

问题


I have a table where in head row there are 2 textareas and 2 buttons. http://jsfiddle.net/8qzmxwa9/1/ I use margin: 0 auto;

style='white-space:nowrap;'

on elements to make them be in one line. But as you can see at fiddle they are a little bit uneven. How can I make them stay in one line.


回答1:


textarea
{
  text-align: center;
  height: 35px;
  width: 280px;
  margin: 0 auto;
  font-size: 27px;

    vertical-align: bottom;
}

DEMO




回答2:


Add the same vertical-align to everything and remove the padding for textareas so they don't grow bigger. Like this:

table, th, td 
{
   border: 1px solid black;
   font-size: 27px;
    vertical-align:middle;
    display:inline-block;
}
textarea
{
  text-align: center;
  height: 35px;
  width: 280px;
  margin: 0 auto;
  font-size: 27px;
    padding:0;
} 
button
{
  margin: 0 auto;
  font-size: 27px;
}



回答3:


You can use display flex property to align items in one line :-

Suppose you have 3 buttons in a parent div, like this :-

<div class='parent'>
  <button class='child'> Button 1 </button>
  <button class='child'> Button 2 </button>
  <button class='child'> Button 3 </button>
</div>

Now apply display: flex on parent and flex: 1 property on all the children you want to be aligned.

CSS file for the above HTML code will look like this,

.parent {
  display: flex;
}

.child {
  flex: 1;
}

Link for the above code

Link of answer for the question asked



来源:https://stackoverflow.com/questions/25800296/align-elements-in-td-in-one-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!