Solved

Creating a box around link

Posted on 2004-09-13
6
177 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
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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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 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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

726 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