开发者

HTML / CSS: Hide Text and Show Border

开发者 https://www.devze.com 2023-02-03 22:45 出处:网络
How can I show only the bord开发者_JAVA百科er of a div, but not the text using CSS?This is not well supported by IE, but you could use:

How can I show only the bord开发者_JAVA百科er of a div, but not the text using CSS?


This is not well supported by IE, but you could use:

#mydiv { color:rgba(0,0,0,0); border:1px solid #000 }

This makes the text color fully transparent, but leaves the border visible.


A simple cross-browser solution is the Phark "text indent" method. It's usually used for image replacement.

div.example {
   border: 2px solid red;
   /* Hide text inside "off left" */
   text-indent: -10000px;
   /* Make sure to set a width and height */
   height: 100px;
   width: 100px;
}

Pros:

  • Doesn't need any extra elements
  • Works in screen-readers

Cons:

  • Doesn't work in IE5


You can make the text the same color as the div's background. Or nest the text inside another div.

0

精彩评论

暂无评论...
验证码 换一张
取 消