Firefox上的样式占位符(Styling placeholder on Firefox)

编程入门 行业动态 更新时间:2024-10-26 06:38:14
Firefox上的样式占位符(Styling placeholder on Firefox)

我想要做的是让占位符出现在中心50%顶部和50%左侧 。 它似乎在Chrome中很好,但在Firefox 23上却没有。我在这里有一个例子。 我的风格在这里:

textarea::-moz-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; top: 50%; text-align: center; } textarea::-webkit-input-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; top: 50%; text-align: center; }

如果有人能提供帮助,我将不胜感激,谢谢!

What I want to do is to make a placeholder appear on the center 50% top and 50% left. It appears to be good in Chrome but not on Firefox 23. I have an example here. and my styles here:

textarea::-moz-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; top: 50%; text-align: center; } textarea::-webkit-input-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; top: 50%; text-align: center; }

I would appreciate if anyone could help, Thanks!

最满意答案

我尝试了一些奇怪的东西,但这似乎适合: 看到这个jsFiddle

您required在textarea上放置required属性:

<textarea placeholder="Placeholder" required="required"></textarea>

这是CSS

textarea { height: 300px; width: 300px; /* center the text by default */ text-align:center; resize: none; } /* align the text left when insert */ textarea:focus {text-align: left;} /* textarea not empty will have text align left */ textarea:not(:invalid) {text-align: left;} /* remove the red shadow of firefox if textarea is empty */ textarea:invalid {box-shadow: none;} /* hide the placeholder on focus */ textarea:focus::-moz-placeholder {opacity: 0;} textarea::-moz-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; /* the main trick to center the placeholder vertically */ line-height:300px; } textarea::-webkit-input-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; line-height: 300px; /* keep the placeholder centered under chrome */ text-align: center; }

I tried some weird stuff, but that seems to fit : See this jsFiddle

You will have to put the required attribute on you textarea :

<textarea placeholder="Placeholder" required="required"></textarea>

Here is the CSS :

textarea { height: 300px; width: 300px; /* center the text by default */ text-align:center; resize: none; } /* align the text left when insert */ textarea:focus {text-align: left;} /* textarea not empty will have text align left */ textarea:not(:invalid) {text-align: left;} /* remove the red shadow of firefox if textarea is empty */ textarea:invalid {box-shadow: none;} /* hide the placeholder on focus */ textarea:focus::-moz-placeholder {opacity: 0;} textarea::-moz-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; /* the main trick to center the placeholder vertically */ line-height:300px; } textarea::-webkit-input-placeholder { position: relative; font-size: 16px; font-style: italic; color: #ABABAB; line-height: 300px; /* keep the placeholder centered under chrome */ text-align: center; }

更多推荐

本文发布于:2023-08-01 10:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1357753.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   Firefox   placeholder   Styling

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!