Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Simple CSS New Window Hack
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Markshall" data-source="post: 329512" data-attributes="member: 1872"><p>Got a little bored and decided to write this up, it's simply a little CSS hack that targets 'a' elements with the target of either _blank or _new, which means links attached to the 'a' element will open in a new page, then it places a little background image of a new window icon that I grabbed from Google next to it.</p><p></p><p>Many sites use this for accessibility, but they decide to add a class of 'newwindow' (or something similar) to the 'a' element, whereas this removes the need for an additional class name so long as the target is either _blank or _new</p><p></p><p>Code is below:</p><p>[HTML]<!DOCTYPE html></p><p><html lang="en"></p><p> <head></p><p> <meta charset="UTF-8"></p><p> <title>New Window</title></p><p> <style></p><p> body {</p><p> font-family: "Helvetica", sans-serif;</p><p> font-size: 1em;</p><p> line-height: 1.2;</p><p> }</p><p> </p><p> /*</p><p> select elements whose target is '_blank' or '_new'</p><p> meaning the attached link will open in a new page</p><p> */</p><p> a[target="_blank"],</p><p> a[target="_new"] {</p><p> background: url('newwindow.png') no-repeat center right;</p><p> height: 12px;</p><p> width: 14px;</p><p> padding-right: 20px;</p><p> }</p><p> </style></p><p> </head></p><p> </p><p> <body></p><p> <ul></p><p> <li><a href="http://google.co.uk" target="_blank">Google UK</a></li></p><p> <li><a href="index.html">Home page</a></li></p><p> <li><a href="http://eminem.com" target="_new">Eminem</a></li></p><p> <li><a href="http://facebook.com" target="_blank">Facebook</a></li></p><p> <li><a href="about.html">About this website</a></li></p><p> </ul></p><p> </body></p><p></html>[/HTML]</p><p></p><p>Here is the link to the icon: <a href="http://i.imgur.com/Na5Kr1u.png" target="_blank">http://i.imgur.com/Na5Kr1u.png</a></p><p></p><p>Or you can view it on <a href="http://codepen.io/Markshall/pen/ZYVMjq" target="_blank">CodePen</a></p><p></p><p>Hope it helps,</p><p>Mark</p></blockquote><p></p>
[QUOTE="Markshall, post: 329512, member: 1872"] Got a little bored and decided to write this up, it's simply a little CSS hack that targets 'a' elements with the target of either _blank or _new, which means links attached to the 'a' element will open in a new page, then it places a little background image of a new window icon that I grabbed from Google next to it. Many sites use this for accessibility, but they decide to add a class of 'newwindow' (or something similar) to the 'a' element, whereas this removes the need for an additional class name so long as the target is either _blank or _new Code is below: [HTML]<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>New Window</title> <style> body { font-family: "Helvetica", sans-serif; font-size: 1em; line-height: 1.2; } /* select elements whose target is '_blank' or '_new' meaning the attached link will open in a new page */ a[target="_blank"], a[target="_new"] { background: url('newwindow.png') no-repeat center right; height: 12px; width: 14px; padding-right: 20px; } </style> </head> <body> <ul> <li><a href="http://google.co.uk" target="_blank">Google UK</a></li> <li><a href="index.html">Home page</a></li> <li><a href="http://eminem.com" target="_new">Eminem</a></li> <li><a href="http://facebook.com" target="_blank">Facebook</a></li> <li><a href="about.html">About this website</a></li> </ul> </body> </html>[/HTML] Here is the link to the icon: [URL]http://i.imgur.com/Na5Kr1u.png[/URL] Or you can view it on [URL='http://codepen.io/Markshall/pen/ZYVMjq']CodePen[/URL] Hope it helps, Mark [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Simple CSS New Window Hack
Top