Solved

Creating a box around link

Posted on 2004-09-13
6
178 Views
Last Modified: 2008-03-06
I am new to CSS and I was wondering if there is anyway to have a colored box around a link. The box will have a specfic background color, specfic height of 25, and no specfic width (it should adjust to fit the width of the cell it is in). The text in the box should be centered in the middle of the box. If you need more information please let me know. Thanks.
0
Comment
Question by:thecode101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 15

Accepted Solution

by:
Daydreams earned 125 total points
ID: 12048084
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<style type="text/css">
 a, a:link    {background-color:orange;text-decoration: none;display:block;height:25px;text-align:center;}
 a:visited {text-decoration: none;}
 a:hover   {background-color:yellow;text-decoration: none;}
</style>
<body>
<table><tr>
<td><a href="somelink.html">Click here</a></td></tr>
</table>
</body>
</html>
0
 
LVL 3

Author Comment

by:thecode101
ID: 12056358
Daydreams,
Thanks for your help that is what I want, except the text is not vertically aligned in the middle of the box. Is there anyway to make this change?
0
 
LVL 15

Expert Comment

by:Daydreams
ID: 12057371
Hi thecode101,

You could use padding:

(I changed the css somewhat here and added padding)

a {display: block; height:25px;background-color:blue;padding:10px; }
a:link    {text-align:center;text-decoration: none;}
a:visited {text-decoration: none;}
a:hover   {background-color:yellow;text-decoration:none;}

If you only want padding on the top and bottom, you can specify:
 padding-top:5px; padding-bottom:5px;

..or any value of padding you like.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:thecode101
ID: 12057492
Thanks for your help, I will give you the points since you help give me the right idea. What I did instead was use:

 display:table-cell;
 height:25px;
 width:500em;  //If there is a better way to make it fill the width of the cell let me know =)
 text-align:center;
 vertical-align: middle

Since the width is set to such a high number, the width of each cell that it is in will never be greater then that. So, it takes up the whole width of the cell.

I don't know why but 100% width didn't work for me.
0
 
LVL 15

Expert Comment

by:Daydreams
ID: 12058155
>width:500em;  //If there is a better way to make it fill the width of the cell let me know

width:auto;
0
 
LVL 3

Author Comment

by:thecode101
ID: 12058191
I tried that but it does the same thing as 100% it only covers the text and not the width of the cell.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question