如何创建 Facebook 状态箭头文本框?

2023-03-17前端开发问题
7

本文介绍了如何创建 Facebook 状态箭头文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我怎样才能得到一个弯曲的文本框,比如 Facebook 状态文本框,只有 html 和 css?

How can I get a curved TextBox like the Facebook Status TextBox with html and css only?

谁能告诉我怎么做??

推荐答案

我的跨浏览器,Facebook 样式文本框的纯 CSS 版本:

My Cross-Browser, CSS-only version of the Facebook-style textbox:

如何

我在内部容器 div 上使用了 :before(具有 7px 折叠边框,三个透明,一个白色)创建一个三角形,其中边框相交,然后我将它放在具有绝对定位的文本框(覆盖文本框的边框以将三角形附加"到它).

I've used :before on the inner container div (with 7px collapsed borders, three transparents, one white) to create a triangle where the borders intersect themselves, then i placed it just over the textbox with absolute positioning (overriding the textbox's border to "attach" the triangle to it).

根据这个问题,rgba应该使用 代替 transparent 以防止 Firefox 放置不需要的边框;

According to this question, rgba should be used instead of transparent in order to prevent Firefox to put an unwanted border;

然后,为了以跨浏览器的方式为边框着色,我使用 :after 放置一个相同的三角形,大小相同,颜色相似(*) 到文本框的边框,仅比白色三角形高 1px(在顶部位置).

Then, for coloring the border in a cross-browser way, i used :after to place an identical triangle, with the same size, with a color similar(*) to the textbox's borders, just 1px higher (in top position) than the white triangle.

此时,我已使用 z-index 属性将灰色三角形置于白色三角形下方,以便其主体"(底部边框)只有 1px 可见.

At this point, i've used z-index property to place the gray triangle UNDER the white triangle, so that only 1px of its "body" (the bottom border) would have been visible.

这为箭头创建了灰色边框.

This created the gray border to the arrow.

(*) 我选择的颜色比文本框的边框颜色深一点,因为混合两个三角形会产生增亮"效果.使用#888 而不是#bbb,结果是可以接受的,并且比使用原始颜色本身更类似于原始颜色.

(*) I've chosen a color a bit darker than the textbox's borders one, because of the "brightening" effect generated by mixing the two triangles. With #888 instead of #bbb, the result is acceptable and more similar to the original color than using the original color itself.

这里是注释代码和演示:

Here is the commented code and the demo:

演示

http://jsfiddle.net/syTDv/

HTML

<div id="fbContainer">
   <div class="facebookTriangle">  
      <input type="text" id="facebookTextbox" value="some text"/>
   </div>
</div>

CSS

body {
    padding: 30px;
}


/* With this container you can put the textbox anywhere on the page,
 without disturbing the triangles's absolute positioning */
#fbContainer{
  position: relative;
}


/* some adjustments to make the textbox more pretty */
#facebookTextbox{   
   border: 1px solid #bbb !important;
   padding: 5px;
   color: gray;
   font-size: 1em;
   width: 200px;
}


/* block element needed to apply :before and :after */
.facebookTriangle{
  height: 30px;
  padding-top: 10px;
}


/* white triangle */
/* collapsing borders (because of the empty content) 
   creates four triangles, three transparents and one coloured, 
   the bottom one */    
.facebookTriangle:before {
  content: '';
  border-style: solid;
  border-width: 7px;
  border-color: rgba(255,255,255,0) rgba(255,255,255,0) 
                white rgba(255,255,255,0);
  top: -3px;
  position: absolute;
  left: 7px;
  z-index: 2; /* stay in front */
}


/* gray triangle */
/* used as border for white triangle */
.facebookTriangle:after {
  content: '';
  border-style: solid;
  border-width: 7px;
  border-color: rgba(255,255,255,0) rgba(255,255,255,0) 
                #888 rgba(255,255,255,0);  
  top: -4px;
  position: absolute;
  left: 7px;
  z-index: 1; /* stay behind */
}

希望对您有所帮助...

Hope that helps...

这篇关于如何创建 Facebook 状态箭头文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用百度地图API获取地理位置信息
首先,我们需要在百度地图开放平台上申请一个开发者账号,并创建一个应用。在创建应用的过程中,我们会得到一个密钥(ak),这是调用API的凭证。 接下来,我们需要准备一个PHP文件,以便可以在网页中调用。首先,我们需要引入百度地图API的JS文件,代码如下...
2024-11-22 前端开发问题
244

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125