Solved

Creating a box around link

Posted on 2004-09-13
6
172 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
  • 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now