Html 如何在textarea的右上角创建一个固定的浮动按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8345647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:46:17  来源:igfitidea点击:

how to create a fixed floating button on top right of textarea

htmlcss

提问by Jensen

I want to write something like the following:

我想写如下内容:

|------------------------------------------------------|</br>
|td                                                    |
| |--------------------------------------------------| |
| |textarea                          floating button | |
| |                                                  | |
| |                                                  | |
| |                                                  | |
| |                                                  | |
| |                                                  | |
| |--------------------------------------------------| |
|------------------------------------------------------|  

the outter is td element, and textarea is inside. I want a fixed floating button on the right top corner of textarea, or td. And this textarea and td is behind of this floating button. I tried to use z-index to do that, but didn't work.

外部是 td 元素,而 textarea 在里面。我想要一个固定的浮动按钮在 textarea 或 td 的右上角。而这个 textarea 和 td 在这个浮动按钮的后面。我尝试使用 z-index 来做到这一点,但没有奏效。

Also the button is a dropdown menu.

该按钮也是一个下拉菜单。

Can someone tell me how to implement this?

有人能告诉我如何实现这个吗?

Thanks

谢谢

回答by SpaceBeers

You'll be able to do this by giving the outer container position: relative;and then the inner elements:

你可以通过给外部容器position:relative;来做到这一点然后是内部元素:

position: absolute; top: 0px; right: 0px;

You can then 'layer' them with z-index.

然后,您可以使用 z-index 对它们进行“分层”。

Just because I lost out on 6 points by not including a JSFiddle - here's a demo - http://jsfiddle.net/spacebeers/WYrwf/

仅仅因为我没有包含 JSFiddle 就失去了 6 分 - 这是一个演示 - http://jsfiddle.net/spacebeers/WYrwf/

回答by ptriek

Or to see Spacebeers solution in action :-)

或者查看 Spacebeers 解决方案的实际应用 :-)

http://jsfiddle.net/e2Ggm/

http://jsfiddle.net/e2Ggm/