How to align button to textarea corner and keep it in same relative position while expand contract

耗尽温柔 提交于 2019-12-11 03:36:02

问题


I have a textarea and I want a couple of buttons to always be below the textarea and aligned with the text area's bottom right corner. The closest I got is shown in this fiddle http://jsfiddle.net/leopardy/2uwDT/1/ but its not even aligned all the way to the right in line with the textarea and worse when I resize the textarea via the resize grabber triangle on the bottom right corner, and I move the right line of the text area either to the right or left) the buttons become misaligned even more(even further away from right side of the textarea). One note is that the textarea has to be able to be resized, I can't have it at a set size.

html

<div class="descriptionarea">
    <span class="namefortxtarea">Description</span>
    <textarea ></textarea>
    <span class="buttonfortxtarea"><button class= "btn btn-mini description_edit">Edit</button><button class= "btn btn-mini description_submit">Submit</button></span>
</div>

css

@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');

.descriptionarea {
   width: 490px;
   position: relative;
}

.descriptionarea textarea{
    width: 490px;
    height: 20px;
}

.descriptionarea span.namefortxtarea{
    display: block;
    text-align: left;
    font-size:12px;
}

.descriptionarea span.buttonfortxtarea{
    display: block;
    text-align: right;
}

回答1:


Try removing the container's strict width, you can set a min-width instead and if you make it display: inline-block or float: left you can make sure it doesn't span the entire width of its parent.

http://jsfiddle.net/2uwDT/2/

.descriptionarea {
    min-width: 490px;
    position: relative;
    display: inline-block;
}


来源:https://stackoverflow.com/questions/17329843/how-to-align-button-to-textarea-corner-and-keep-it-in-same-relative-position-whi

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