padding still active on small screen - html

I am using tables because I am making a newsletter for emails. I have a picture, where I would like some padding on desktop screen. When a person is on a mobile, there should not be any padding on the picture. The following code works for the dekstop, but when I resize my window I still have a padding on the picture, even if I set it to 0px.
Can anybody see why that is happening?
.img-position {
padding: 40px 0px 40px 0px;
}
#media only screen and (max-width: 596px) {
.img-position {
padding: 0px 0px 0px 0px;
}
}
<!-- Top Picture Start -->
<table class="row background-color__blue">
<tr>
<td class="center img-position" align="center">
<center>
<table class="container">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td>
<img width="580" height="300" src="https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300">
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
<!-- Top Picture End -->

The answer is:
#media only screen and (max-width: 596px) {
td.img-position {
padding:0px 0px 0px 0px;
}
}

The #media rule with padding changing due to desktop width change works fine for me. If you want to remove any padding of table, try to add extra css rules like in the example below (the img must be set to display:block to remove the bottom empty space). I've added yellow background to make the effect more visible.
.img-position {
padding:40px 0px 40px 0px;
}
#media only screen and (max-width: 596px) {
.img-position {
padding:0px 0px 0px 0px;
}
}
img{
display:block;
}
table{
border-collapse:collapse;
}
table *{
padding:0px;
margin:0px;
}
<!-- Top Picture Start -->
<table class="row background-color__blue" style='background-color:yellow'>
<tr>
<td class="center img-position" align="center">
<center>
<table class="container">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td>
<img width="580" height="300" src="https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300">
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
<!-- Top Picture End -->

Related

Centre elements in 3 columns within their respective widths. Align everything left when below 480px width

I have 3 things 1)phone number, 2)social icons and 3)email. First I want all three to be positioned centre in their respective widths.
Then while coming down to mobile screen size say below 480px all of them has to be left aligned and positioned below one after the other 1,2,3 (just like in responsive design).
I'm doing this for a responsive HTML email template. Help me with this!!
<tr>
<td class="cols-wrapper" style="padding-left:12px;padding-right:12px"><br>
<!--[if mso]>
<table border="0" width="576" cellpadding="0" cellspacing="0" style="width: 576px;">
<tr><td width="192" style="width: 192px;" valign="top"><![endif]-->
<table width="192" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row" style="width: 192px;">
<tr>
<td class="col" valign="top" style="padding-left:12px;padding-right:12px;">
<p>Phone: <a style="color:#00a5e7; border-bottom:none;" href="tel:+044 4000 2323">044 1234 5678</a></p>
</td>
</tr>
</table>
<!--[if mso]></td><td width="192" style="width: 192px;" valign="top"><![endif]-->
<table width="192" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row" style="width: 192px;">
<tr>
<td class="col" valign="top" style="padding-left:12px;padding-right:12px;padding-top:10px;">
<img style="float:left;" src="https://cdn0.iconfinder.com/data/icons/social-network-7/50/3-20.png">
<img style="padding:0px 8px; float:left;" src="https://cdn1.iconfinder.com/data/icons/logotypes/32/square-twitter-20.png">
<img src="https://cdn3.iconfinder.com/data/icons/social-media-chamfered-corner/154/google_plus-20.png">
</td>
</tr>
</table>
<!--[if mso]></td><td width="192" style="width: 192px;" valign="top"><![endif]-->
<table width="192" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row" style="width: 192px;">
<tr>
<td class="col" valign="top" style="padding-left:12px;padding-right:12px;">
<p><a style="color:#00a5e7; border-bottom:none;" href="" target="_top">hi#website.com</a></p>
</td>
</tr>
</table>
<!--[if mso]></td></tr></table><![endif]-->
</td>
</tr>
There are multiple points I would like to mention.
First remove this table structure in your code -- which is useless, out of fashion, and increases unnecessary complexity.
Use bootstrap and add col-md-4 in the 3 divs and put your 3 centered objects within it with div { text-align: center } and col-xs-12 in all 3 of them with div { text-align: left }, like:
<div class="col-md-4 col-xs-12>item 1 </div>
<div class="col-md-4 col-xs-12>item 2 </div>
<div class="col-md-4 col-xs-12>item 3 </div>
Even if you don't want to use a framework like bootstrap, write the same code as I told in a media query, like:
#media only screen and (max-width:1024px){
div{
display:inline-block;
width:33%;
text-align:center;
}
}
#media only screen and (max-width: 480px){
div {
display:block;
text-align:left;
}
}
try using a div for .cols-wrapper and remove the inline "float-styles" - add this CSS and you're ready to go. =)
<style media="screen">
.cols-wrapper table{
width: 33.33% !important;
text-align: center;
}
#media (max-width: 480px) {
.cols-wrapper table{
width: 100% !important;
text-align: left;
}
}
</style>

Padding on picture when under 596px

I am making a test site to practice Practice Page. I have set up a logo and a picture in the foundation framework for emails. The site is responsive now. The picture with the racoon there is a padding on 40px on the top and bottom. When I go down under 596px there is still the padding even if I tried to set the padding to 0px.
When I reach 596 px I need to padding to go to 0px, but why does that not work now? I can make it work setting a !important on media only screen. But that is bad coding behaviour, right?
There is a lot of CSS in the framework. Therefore I made a fiddle
Desktop CSS
.img-position {
padding:40px 0px 40px 0px;
}
Mobile CSS
#media only screen and (max-width: 596px) {
.img-position {
padding:0px 0px 0px 0px;
}
}
HTML
<body>
<table class="body" data-made-with-foundation>
<tr>
<td class="float-center" align="center" valign="top">
<center>
<!-- Logo Start -->
<table align="center" class="wrapper header float-center background-color__white">
<tbody>
<tr>
<td class="wrapper-inner">
<table align="center" class="container" style="background-color:transparent">
<tbody>
<tr>
<td>
<table class="row collapse">
<tbody>
<tr>
<th class="img-headline">
<center>
<img src="http://www.fontmagic.com/files/animal-silence.gif" alt="TestPicture" align="center" class="float-center" width="250" height="80">
</center>
</th>
<th class="expander"></th>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!-- Logo End -->
<!-- Top Picture Start -->
<table class="row background-color__blue">
<tr>
<td class="center img-position" align="center">
<center>
<table class="container">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td>
<img width="580" height="300" src="http://animalhumanhealth.com/wp-content/uploads/2016/07/racoon1.png">
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
<!-- Top Picture End -->
<!-- Row 1 End -->
<!-- Email Button End -->
</center>
</td>
</tr>
</table>
</body>
Add
.img-position {
padding:40px 0px 40px 0px;
}
above media queries which you have defined. Here is working fiddle working fiddle
The padding (or the space) that appears at 596px originates from the container class here:
table.body .container {
width: 95% !important;
}
So change the above to:
table.body .container {
width: 100% !important;
}
here's working example https://jsfiddle.net/sdk3dsyt/ your #media-query goes before you defined the initial paddings, that is why your #media-query rules are overriden
When more than 1 overlapping styles are applied to the same element, only the last style is visible https://developer.tizen.org/dev-guide/web/2.3.0/org.tizen.mobile.web.appprogramming/html/guide/w3c_guide/dom_guide/html_priorities_css.htm

Why aren't the images in my HTML table aligning properly?

I'm currently building an email signature, a simple 4 images sectioned off in a square 2x2 table.
The problem I'm currently facing is I can't remove the spacing between the td's at the moment.
<style>
d, tr, img { padding: 0px; margin: 0px; border: none; display: block; }
table { border-collapse: collapse; }
</style>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<img src="http://bubblei.co.uk/NDz2UL.png" ></img>
</td>
<td>
<img src="http://bubblei.co.uk/BMSIqd.png"></img>
</td>
</tr>
<td>
<img src="http://bubblei.co.uk/VcOrDE.png" ></img>
</td>
<td>
<img src="http://bubblei.co.uk/DlwKjq.png"></img>
</td>
</tr>
</table>
Can anyone tell me where I'm going wrong, or point me in the right direction? much appreciated!
Your images all have different size. I've taken the liberty to smoothly change one of them, and the result is already way better. You should align them and honer the same dimensions on all images.
<style>
d, tr, img { padding: 0px; margin: 0px; border: none; display: block; }
table { border-collapse: collapse; }
</style>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<img src="http://i.imgur.com/tBrf7Fu.png" >
</td>
<td>
<img src="http://bubblei.co.uk/BMSIqd.png">
</td>
</tr>
<td>
<img src="http://bubblei.co.uk/VcOrDE.png" >
</td>
<td>
<img src="http://bubblei.co.uk/DlwKjq.png">
</td>
</tr>
</table>

Why image not fit to table cell height in html?

I want to split screen to two area left and right,in right segment show a image and in right segment show textbox,for that purpose write this html code:
<table style="width:100%">
<tr>
<td style="width:50%;height:100%;" align="center">
<img src="../Content/45.png" style="display:block;height:100%;width:100%;" />
</td>
<td style="width:50%;">
behzad
</td>
</tr>
</table>
but when i run the html page ,image not fit to the table column height,and i must scroll the browser to see all of the page,i want just fit to the screen height,my out put i this :
Use viewport units vh/vw, and to keep aspect ratio on the image, set the style on the image to display:block;max-width:50vw;max-height:100vh
html, body {
margin: 0;
}
table {
border-collapse: collapse;
}
td {
padding: 0;
vertical-align: top;
}
<table style="width:100vw">
<tr>
<td style="width:50vw;height:100vh;" align="center">
<img src="http://lorempixel.com/600/600/animals" style="display:block;max-width:50vw;max-height:100vh" />
</td>
<td style="width:50vh;">
behzad
</td>
</tr>
</table>
in this case you'd better use background-image instead of <img> to avoid stretching
check the following demo
html,body{
height:100%;
}
table{
height:100%;
}
<table style="width:100%">
<tr>
<td style="width:50%;height:100%;background-image:url(http://placehold.it/600x600)" align="center">
</td>
<td style="width:50%;">
behzad
</td>
</tr>
</table>
emphasized text
instead of this section
<img src="../Content/45.png" style="display:block;height:100%;width:100%;" />
try this section
<img src="../Content/45.png" height="50%" />
I hope it works

How to make the div width fit the table which inside the div?

If the table is inside the div and the width of the table is uncertain, which can be even wider than the screen width, how to make the div containing that table adjust the table width? Since the div has been set padding: 10px, when the table exceeds the screen width, the padding-right turns invisible.
Here is the code:
<div class="panel-body">
<table class="table table-hover table-bordered"></table>
</div>
I found a method.
.panel-body{
display: inline-block;
padding: 10px;
}
the key why it can work is "display".You could learn the differences from block,inline,and inline-block.
hope it helps
I think you want something like this
JSFiddle
HTML
<div class="panel-body">
<table class="table table-hover table-bordered" border=1>
<tr>
<td> R1C1 </td>
<td> R1C2 </td>
</tr>
<tr>
<td> R2C1 </td>
<td> R2C2 </td>
</tr>
<tr>
<td> R3C1 </td>
<td> R3C2 </td>
</tr>
</table>
</div>
CSS
html, body
{
width:100%;
margin:0%;
}
.panel-body
{
margin:0%;
width:100%;
background:#ccc;
height:auto;
padding:5px 0px;
}
.panel-body table
{
margin:0;
width:100%;
text-align:center;
}