<tbody>
<tr>
<td valign="top" align="center" bgcolor="#3f76bf" style="background-position: center; background-size: cover; border-radius: 6px; background-color: #3f76bf; background-image: url('https://mcusercontent.com/73b8e8571a2f854d4f817a5c8/images/1a986052-d10d-4bf7-890f-133862bc982f.png')" background="https://mcusercontent.com/73b8e8571a2f854d4f817a5c8/images/1a986052-d10d-4bf7-890f-133862bc982f.png">
I would like to make the image in the td tag a hyper link, never imagined I would be spending 5 hours on this simple question. Seems I can not just wrap in tag. So frustrated and appreciative of your help.
I wrote up a more semantic way for doing what you're doing. Of course I don't know what the rest of your code looks like and you may have to tweak things. Generally it's not a good idea to use tables for layout. But I don't know how you're using it so I keep it as is.
(Tables should only be used for tabular data)
From the comments I can see you're using this in an HTML email where using tables for layout is still appropriate due to bad support for modern features. I have in-lined the styles for you in the example
<table>
<tbody>
<tr>
<td style="text-align: center;background-color: #3f76bf;">
<a href="https://yoururl.tld">
<img style="max-width: 100%;" src="https://mcusercontent.com/73b8e8571a2f854d4f817a5c8/images/1a986052-d10d-4bf7-890f-133862bc982f.png" alt="Describe the content of the image for someone who can't see the image">
</a>
</td>
</tr>
</tbody>
</table>
Update
I have since learned why they would use background images (for the images to be an equal grid) and for that I wanted to also add a solution which might be closer to your specific use case. Just a reminder to everyone that below code should not be used anywhere but in emails.
/* Ignore this CSS completely for your example */
/* It's just here for the example in SO to look nice */
td {
width: 100px;
height: 200px;
}
<table>
<tbody>
<tr>
<td
valign="top"
align="center"
bgcolor="#3f76bf"
style="
position: relative;
background-position: center;
background-size: cover;
border-radius: 6px;
background-color: #3f76bf;
background-image: url('https://mcusercontent.com/73b8e8571a2f854d4f817a5c8/images/1a986052-d10d-4bf7-890f-133862bc982f.png');
"
background="https://mcusercontent.com/73b8e8571a2f854d4f817a5c8/images/1a986052-d10d-4bf7-890f-133862bc982f.png"
>
<a href="https://yoururl.tld" style="
position: absolute;
top: 0;
right: 0;
botom: 0;
left: 0;
">
</a>
</td>
</tr>
</tbody>
</table>
Try putting a SPAN element inside the element. It should expand to fill the space. Wrap your link around the Span and put your link-able content inside the span
<td><span>CLICK ME DON KICK ME</span></td>
If span does not work try using a element or a .
This question already has answers here:
Set opacity of background image without affecting child elements
(15 answers)
Closed 5 years ago.
I know that some say that you should use background rgba(0, 0, 0, 0.5); like that, but that is only for color, not pictures and it also does not remake the picture into black and white.
I am asking for background picture transparency and black and white transformation and I know I could use for example opacity: 0.5; for picture background, but that also makes the text withing the box transparent too and it does not make it black and white either.
I only want the background picture of the div box to be semi transparent and transform into black and white at the same time, maybe it is two different codes for it.
I know of the solution that I could use 2 div boxes inside each other were one has the semi transparent background and another the text that way not effecting the opacity of one box to the other, but I wonder if there is a solution to only use one div box for both background and text without effecting the text when using semi transparency plus color or opacity on the background image.
For example if there was something similar to like:
background-opacity: 0.5;
or
background-image-opacity: 0.5;
Although I know that does not exist in CSS, so some solution to that please?
UPDATE: My CSS used now:
#LinksLayer1
{ position:absolute; left:0px; top:-8px; width:100%; height:100%; z-index:3; }
.TDOnLinks
{ font: 12px Arial, Helvetica, sans-serif; }
.TDLinks
{ background-Color: #EEF4FD; background-repeat: repeat; background-attachment: fixed; background-position: center center; background-image:url('../Pictures/2/P_13.jpg'); }
Works well as #LinksLayer1 is one box (the outer box) that contains .TDOnLinks tables and fonts for it, then the .TDLinks table is with the background. But as you understand and I know, it does not give a transparent background.
Simplified my HTML and JavaScript code:
<script language="JavaScript">
function moveover(txt){
window.status = txt;
}
function fillitin(sitepoints,sitename,Dest,siteextrinfo,sitepage){
moveover(sitepoints);
document.SeekLoadLink.sitepoints.value=sitepoints;
document.SeekLoadLink.sitename.value=sitename;
document.SeekLoadLink.Dest.value=Dest;
document.SeekLoadLink.siteextrinfo.value=siteextrinfo;
document.SeekLoadLink.sitepage.value=sitepage;
window.setTimeout("prepare()",3500);
}
</script>
<form method="Post" action="" name="SeekLoadLink">
<div id="LinksLayer1">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="TDLinks"><tr><td valign="top" align="center">
Blablabla Head Text
<table width="100%" border="1" cellspacing="2" cellpadding="2">
<tr>
<td width="33%" valign="top"><b>**,A,B,C,D,E,F,G</b></td>
<td width="33%" valign="top"><b>H,I,J,K,L,M,N,O</b></td>
<td width="33%" valign="top"><b>P,Q,R,S,T,U,V,W,X,X,Y,Z</b></td>
</tr>
<tr>
<td width="33%" valign="top" class="TDOnLinks"><!-- A,B,C,D,E,F,G -->
Blablabla **,A,B,C,D,E,F,G
</td><td width="33%" valign="top" class="TDOnLinks"><!-- H,I,J,K,L,M,N,O -->
Blablabla H,I,J,K,L,M,N,O
</td><td width="33%" valign="top" class="TDOnLinks"><!-- P,Q,R,S,T,U,V,W,X,X,Y,Z -->
Blablabla LINK <img src="../../Menu_js/imgmini/Link_Icon2.gif" width="16" height="16" border="0"> YouTube.com<br>
</td>
</tr>
</table>
</td></tr></table>
</div>
<div class="DivLinkInfo2">
<table height="100%" width="99%" border="0" cellspacing="0" cellpadding="0" class="TEXTLinksMasage" style="direction: ltr;"><tr><td align="left" valign="top" colspan="2">
<nobr><input type="text" name="sitepoints" size="10" class="TEXTLinkPonits" maxlength="255" text value="Ranking" contenteditable="false"><input type="text" name="sitename" size="30" class="TEXTLinkName" maxlength="255" text value="Name" contenteditable="false">URL:<input type="text" name="Dest" class="TEXTLinkPage" size="49" maxlength="255" value="Address" contenteditable="false"></nobr>
</td></tr><tr><td align="left" valign="top" width="1px">
<Textarea class="TEXTLinkExtraInfo" name="siteextrinfo" cols="28" rows="4" contenteditable="false">
Extra
Inforomation and Pros / Cons
</Textarea>
</td><td align="right" valign="top">
<Textarea class="TEXTLinkInfo" name="sitepage" cols="87" rows="4" contenteditable="false">
Page Resume, Information and Comments...
</Textarea>
</td></tr></table></td></tr></table>
</div>
</form>
NOTE: I need no font codes for the text in the box, as the box uses the font body CSS already working well. The box only has CSS for background and nothing else. Not even size as the size is regulated by other CSS codes that work. I only need to effect the background in the box, nothing else.
I tried this:
div.TDLinks:after
{ background-repeat: repeat; background-attachment: fixed; background-position: center center; background-image:url('../Pictures/2/P_13.jpg'); opacity : 0.5; position: absolute; z-index: -1; }
and
.TDLinks:after
{ background-repeat: repeat; background-attachment: fixed; background-position: center center; background-image:url('../Pictures/2/P_13.jpg'); opacity : 0.5; position: absolute; z-index: -1; }
But it did not work, what did I do wrong? Could my JavaScript be blocking it?
NOTE: I know there are others with similar questions and answers, but it is only similar and not the same question, because nobody has asked of having only one box for this solution with picture background, all the other solutions can be solved by having two div boxes, but I need it all with one div box without effecting the text in that box or they ask of color background and that is a totally different thing.
NOTE:
This is not a repeat question of this "Set opacity of background image without affecting child elements" because that asks of transparent background color, I ask of transparent background PICTURE or IMAGE. Look at the question and its codes plz..
This question does not repeat this one:
Set opacity of background image without affecting child elements
Yes, you can use a pseudo element:
div.bg {
width: 200px;
height: 200px;
display: block;
position: relative;
text-align:center;
font-size:20px;
font-weight:bold;
text-transform:uppercase;
}
div.bg:after {
content: "";
background: url('https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a');
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
<div class="bg">text here</div>
I want to remove the padding between the rows and between the two lines of text:
<br />
Please see the explanation below:
http://79.170.44.112/activate-enterprise.co.uk/wp-content/uploads/2014/09/meet-the-team-image.jpg
My table html can be seen at: http://jsfiddle.net/63nzsht1/
My webpage can be seen at:
http://79.170.44.112/activate-enterprise.co.uk/meet-the-team/
The text is in a separate row (both lines of text in the same cell).
Many thanks!
P.S. Tried
cellpadding="0" cellspacing="0"
But I'm still getting the spacing issue, think it must be being pulled from somewhere else?
There are multiple things causing a gap between the image and the text:
Because images are displayed inline, there is a reserved gap beneath inline elements to make way for letter descenders. Display your images as blocks or alter their vertical alignment to lost the gap.
Your table cells display their content in the middle, vertically, by default. So your text is vertically aligned in the middle, not the top. They also have a default padding, remove this.
Your table has border spacing by default, which can be removed with border-spacing:
img { display:block; }
table { border-spacing:0; }
td { vertical-align:top; padding:0; }
JSFiddle
Try cellpadding="0" cellspacing="0" properties at the table!
The cellpadding and cellspacing attributes are supported in all major browsers.
<table cellpadding="0" cellspacing="0" >
<tr>
<th>h1</th>
<th>h2</th>
</tr>
<tr>
<td>m</td>
<td>m</td>
</tr>
</table>
table {
line-height:0.8em;
}
td {
padding:0;
margin:0;
vertical-align:top;
}
img {
display:block;
}
http://jsfiddle.net/63nzsht1/9/
Try adding
padding: 0;
line-height: 12px;
to element td which has text in it (define class for that).
http://jsfiddle.net/63nzsht1/10/
You need to set the padding to 0px and set the line height to a specific number:
The distance between lines will change using line height.
th, td {
padding: 0px;
line-height: 10px;
}
<a href="/cilla/" style=" line-height: 1;">
<span style=" display: block; line-height: 1.7;">Managing Director</span>
<span style="display: block;"> Cilla McKay</span>
</a>
one of way to solve ur problem
I'm trying to style an email for gmail. Most of it displays just fine but Gmail is refusing to display the wrapper div apparently. I had a very similar wrapper working before so I can't figure out where the problem is coming from:
<div style=\"border: 1px solid black; width: 595px; height: 842px; background-color: white; border-radius: 10px; text-align: center; padding-top: 6px;\">AAA</div>
(The \" quotes are for PHP)
Gmail seems to remove the wrapper completely and display and div with no style.
It is best practice to use tables for html-email. Divs and css when applied to divs have inconsistent support across email clients, particularly Gmail, which is probably what is causing issues for you.
Your html code should instead look like this:
<table width="595" height="842" align="right" bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid black; border-radius: 10px; padding-top: 6px;">
<tr>
<td>
AAA
</td>
</tr>
</table>
Note that in many places I've used the old html methods instead of css. This is the best method for html-email.
I'm using a master page and I have a table that I want to show a border around so that it shows around each cell in the table. Here's the code I'm trying to put a border around:
<table class="mainTable" style="border-color:#DDDDDD;">
<tr>
<td class="masterBannerTop" colspan="6" >
<img style="border: none; display: block; margin: 0 auto;" alt="Travel Joan's Blog Banner" src="Website%20Photos/HeadBanner.jpg" />
</td>
</tr>
<tr>
<td class="masterBannerNav">HOME</td>
<td class="masterBannerNav">ABOUT ME</td>
<td>
... And it goes on from there. Here's the CSS:
.mainTable
{
width: 90%;
margin-left: 5%;
margin-right: 5%;
border-spacing: 30px;
border-color:#999999;
}
No matter what color I put in, it doesn't work in any of the browsers. I mean, there's only a couple places where I can put the color. Even if i try to use just CSS or in-line style elements, it still doesn't seem to want to work.
try setting
border:1px solid #999999;
in your css instead of fiddling around with table attributes! Try to avoid using these attributes because it makes changing the style of your site more difficult and the code more verbose for people that have to maintain it. Good luck and let me know how it goes :)
style="border: 1px solid black"
Perhaps also make sure you set border-width: 1px or something along those lines?
Do
<table border="1"> ... </table>
to get borders around your table and between cells.
Do
<table style="border:'1px solid #DDDDDD'"> ... </table>
or
.mainTable {
border:'1px solid #DDDDDD';
...
}
or
.mainTable {
border-size:1px;
border-style:solid;
...
}
to get borders around your table.