Why is my image not aligning in the center? - html

I am not able to figure out why my image in between the label is not aligning to the center , even though I have declared the css inline , but the priority is not working.
I have declared text-align as left in the <style> tag , but I want only this particular tag to align center and not others.
here is my html ,
<td class="ospy_td" style="background-color:#ddd;border-bottom-left-radius:5px;style=text-align:center">
<label class="ospy_lab" style="text-align:center">
<img id="bt" src="img/bt.png" width="30" height="29" />
</label>
</td>
Here is my CSS, which is deined within a tag in the same html page,
.ospy_td, label {
text-align: left;
vertical-align: middle;
cursor: default;
font-weight:normal;
color:#0066c0;
};

I see a couple of errors here in CSS and usage of html elements.
But one them that creates the issue, is the style= inside style attribute:
<td class="ospy_td" style="background-color:#ddd;border-bottom-left-radius:5px;
style=
text-align:center"
>
Delete this "style=" and thing will work.
My suggestion code change (jsFiddle):
HTML
<table>
<tr>
<td class="ospy_td">
<i class="ospy_lab" />
</td>
<tr>
</table>
CSS
table {
width: 100%;
}
td {
background: #66f;
text-align: center;
}
.ospy_td {
background-color: #ddd;
border-bottom-left-radius: 5px;
cursor: default;
vertical-align: middle;
}
i.ospy_lab {
background-image: (img/bt.png);
background-position: center center;
background-repeat: no-repeat;
font-weight: normal;
color: #0066c0;
display: inline-block;
height: 29px;
width: 30px;
}

.ospy_td, label {
text-align: left; // this is your problem, change to center
}
you forgot a semicolon here
style="text-align:center"
change to
style="text-align:center;"

Related

How to align two headers in the same row?

I am trying to align two headers, an h1 and h2 element, in the same row.
I used this code to create a number in a circle which represents the first header and a headline "Device name" which is the second header:
.circle {
border-radius: 45%;
width: 30px;
height: 20px;
padding: 0.5px;
background: #E6354A;
border: 3px solid #E6354A;
color: #FDFEFE;
text-align: left;
font-size: 5px;
}
<table cellpadding='0' cellspacing='0' border='0' border-collapse='collapse' style='width:98%; text-align: center; margin: 0 auto;'>
<tr>
<td colspan='4' <div style='clear:both'>
<div class='circle'>
<h1 style='font-weight: bold; text-align: left; font-size: 13px; margin-top: 0;'>" + obj.value[0].DEVICE_OVERALL_SCORE.toFixed(2) + "</h1>
</div>
<h2 style='font-weight: light; text-align: left; font-size: 16px; margin-top: 0;'> Device name: " + grci.name + " </h2>
</div>
<hr />
</td>
</tr>
</table>
For some reason the circle with the number inside appears in one row and the device name header appears in a row beneath it. Can someone tell me how to make them appear side by side?
It is due to fact that divs and headings are block elements by default, which means they take up all of the space and make other block elements have a separate row. To change this, you would require either to float them, set them as flex, grid, or inline-block element.
I approached to set them as inline-block since it is the fastest, but it really comes down to requirements.
<style>
.circle {border-radius: 45%;width: 30px;height: 20px;padding: 0.5px;background: #E6354A;border: 3px solid #E6354A;color: #FDFEFE;text-align: left;font-size: 5px;}
.circle, h2 {display: inline-block;}
</style>
<table cellpadding='0' cellspacing='0' border='0' border-collapse ='collapse' style='width:98%; text-align: center; margin: 0 auto;'>
<tr>
<td colspan='4'>
<div style= 'clear:both'>
<div class='circle'>
<h1 style='font-weight: bold; text-align: left; font-size: 13px; margin-top: 0;'>" + obj.value[0].DEVICE_OVERALL_SCORE.toFixed(2) + "</h1>
</div>
<h2 style = 'font-weight: light; text-align: left; font-size: 16px; margin-top: 0;'> Device name: " + grci.name + " </h2>
</div>
<hr />
</td>
</tr>
</table>
you can't have 2 header side by side at the same time, because the definition of header is a one row at the top of the table. So make sure you use the correct definitions.
Wrap the headers in a div and make it flex
<style>
div {
display: flex;
}
h1 {
widht: 50%;
}
</style>
<div>
<h1>HEADER1</h1>
<h1>HEADER2</h1>
</div>
Flex direction is row by default, note that I apply width: 50% to create two even columns. You may want to align and justify as well, have a look at align-items and justify-content properties.

Force float:right?

I have a custom html box within Joomla with the following
<span style="color: #FFFFFF; font-size: 1em; padding-top:5px;">
<p style="float: right; display: inline-block; white-space: nowrap; margin-bottom: 5px;"><img src="/images/telephone_call_contact.png"> 0000000000</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;"><img src="/images/email_envelope.png"> contact#email.co.uk</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;"><img src="/images/shop_open.png"> Open 7 Days 5:00pm-11:00pm </p>
</span>
This works fine. However, when the browser is resized down to a certain level one will come undone until you resize even further.
Similarly, at another dimension they'll also not align properly.
Does anyone know why this behaviour is occurring?
EDIT: As Antonio suggested, adding clear:both to p in the CSS partially resolved this issue. Now the issue occurs only on the first line (when it didn't before)
Add clear:both to your p css rules
example.
I think that adding a clear:right should solve your issue, but I can't be so sure as the images in your snippet do not load.
<span style="color: #FFFFFF; font-size: 1em; padding-top:5px;">
<p style="float: right; display: inline-block; white-space: nowrap; margin-bottom: 5px;"><img src="/images/telephone_call_contact.png"> 0000000000</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;clear:right;"><img src="/images/email_envelope.png"> contact#email.co.uk</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;clear:right;
"><img src="/images/shop_open.png"> Open 7 Days 5:00pm-11:00pm </p>
</span>
You would better forget using inline styles for your markup, as it has SEO downsides. instead use an external stylesheet.
Also, your markup has some problems, so you'd better do it like this:
.details{
text-align: right;
background-color: #744C27;
}
.details span{
display: inline-block;
vertical-align: middle;
color: #FFFFFF;
font-size: 1em;
white-space: nowrap;
}
.icons{
width: 32px;
height: 32px;
margin-right: 20px;
background-repeat: no-repeat;
}
.phone{ background-image: url( 'images/telephone_call_contact.png' ) }
.email{ background-image: url( 'images/email_envelope.png' ) }
.shop{ background-image: url( 'images/shop_open.png' ) }
<div class="details">
<div><span class="icons phone"></span><span>0000000000</span></div>
<div><span class="icons email"></span><span>contact#email.co.uk</span></div>
<div><span class="icons shop"></span><span>Open 7 Days 5:00pm-11:00pm</span></div>
</div>

div width and height alignment for all levels of zooming

Html code:
<div class="CorpPerformance">
<div class="row">
<div class="DashboardTitle">
3 Month
</div>
<div class="DashboardScore" style="font-weight:bold">
<a class="redirectLink" data-criteria-corporatesummarycategory="none" data-criteria-corporatesummaryexpand="0" data-criteria-customerpay="" data-criteria-expressservice="" data-criteria-maintenanceplan="" data-criteria-modelname="" data-criteria-rspenddate="" data-criteria-rspstartdate="" data-criteria-warrantypay="" data-criteria-yearmodel="" data-criteria-department="Sales" data-criteria-reportperiod="[Collection Date].[Calendar].[Calendar Month].&[October 2014]" data-criteria-summaryperiod="3MONTH" href="/Corporate/OFSSurveySummary">950</a>
</div>
<div class="DashboardIcon">
<a class="bootstrap-modal" data-criteria-chartcustomerpay="" data-criteria-chartexpressservice="" data-criteria-chartmaintenanceplan="" data-criteria-chartmodelname="" data-criteria-chartmodelyear="" data-criteria-chartwarrantypay="" data-criteria-chartdepartment="SALES" data-criteria-chartmeasurename="Response Default Computation" data-criteria-chartmeasuretype="score" data-criteria-chartorganization="" data-criteria-chartpagetitle="NSSI Trend" data-criteria-chartreportperiod="[Collection Date].[Calendar].[Calendar Month].&[October 2014]" data-criteria-chartsummaryperiod="3MONTH" data-criteria-charttitle="NSSI" data-criteria-chartwheretuple="[Questionnaire].[Questionnaire].[Question].&[OFSP]&[OFSP13011]" href="/Trend" modal-no-resize="True" upper="NSSI Trend"><span>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAAAZCAYAAACM9limAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHxSURBVFhH7Zg9SEJRFMcdW4QmcRI3xclNcYiGBocGB4dqMQTXdHdoFRqsoCAtJEiMKCpCHkHkECFJUNQgNqgEIQ19DIFBw8n/8SkUPft66n31fnBArnLh/O69556roQHp8WEYSOctuhgFhBdTLN5RLndN2WxZHukNQoopFGrk9W6S1Zogu32FhofXyeFI0cBAnHy+HUqlLunh4Vn+dWfq9RcWG4+f0sjIBnk8aZ5vcHC+kfgMz/URQolBspHIIdlsyxSLnVCl8ih/0wRJbm9f0eSkREbjHJlMC5wkYmIiS4GAxEJbY2bzIsvEZ8w7O3vKkhCfiRVGDFYOuwMr+1Vqtad2oonEOU1NHZAkldtj78V+h76LyedvWIjfv8uJikLfxGA1x8b2yO1O8+qKRs/FYFeMjm5xHclkivKoePRMTKuw4qaZnj7mQioyPRETDjeFoLCKLqRF18XgGh0f3/ty3yEKXRODnYGeQqmBEp2uiMHuQIeKnkKrqC6mVLqnoaGMpqUAVcXg+rVYlrht1zqqiMHRwfsFDZvWiqwSvxaTTF5wS6/VIqvEj8Wcnd3yq9XlWqNq9eePNVHpKAZvGCSPY4JuFREK7fMOcTpXhXzjqEVHMQDJ45hASjR6RMGgxP+q/XU+FfNf0cUo0Bajx/sw0CuzQYKdi8e4ggAAAABJRU5ErkJggg==">
</span></a> </div>
<div class="CvalNational">
<span style="color:#fff;font-weight:bold;">
National
</span>
</div>
<br>
</div>
</div>
JSfiddle link :
http://jsfiddle.net/8nbyc9m7/
Output without zoom :
if i zoom to 110% or 150% or 60% zooming it gives different output. that means last section is not aligned properly.
with zoom:
how to maintain the same output for all levels of zooming in all browsers.
Setting the container to have a width equals to the parent container does the trick for me
http://jsfiddle.net/kursion/8nbyc9m7/2/
Btw... you should probably concider doing a simple table ?
.CorpPerformance {
padding-left: 5px; <----------- changed
display: table;
border: 2px solid gray;
border-radius: 5px;
vertical-align: middle;
line-height: 30px;
width: 340px; <----------- changed
}
.CorpPerformance .DashboardTitle {
width: 80px; <----------- changed
}
.CorpPerformance .DashboardScore {
width: 40px; <----------- changed
}
.CorpPerformance .DashboardIcon {
width: 100px; <----------- changed
}
.CorpPerformance .CvalNational {
width: 119px; <----------- changed
text-align: center;
border-left: 1px dotted black;
background-color: gray;
}
80px + 40px + 100px + 119px + 1px(border) = 340px
And I removed the padding
.CorpPerformance .row > div {}
Edit: with a table... it's much more easier and zoom works ! Check the link in my comment
http://jsfiddle.net/victor_007/8nbyc9m7/3/
* {
box-sizing:border-box;
}
use box-sizing:border-box; which gives border and padding from inside and set the width exactly which you want
Here is your solution.
What I did is to correct your table and remove the width of the last cell so that it can be flexible. I have used table and tr and td instead of div as it will make your css lighter.
If you can't or don't want to change your div for table, tr and td, you can always add the following css on your div: display: table; to replace table, display: table-row; to replace tr, and display: table-cell; to replace td. The result will be the same.
.CorpPerformance {
border: 2px solid gray;
border-radius: 5px;
vertical-align: middle; /* it's defined for the whole table so you don't need to write it again */
line-height: 30px;
max-width: 343px;
border-spacing: 0; /* important for Chrome browser that add spacing */
}
img {
max-width: 100%;
vertical-align: middle;
border: 0;
}
.CorpPerformance > td {
padding: 0 5px 3px; /* I've just simplified the writing */
}
.CorpPerformance .DashboardTitle {
width: 110px;
}
.CorpPerformance .DashboardScore {
width: 25px;
}
.CorpPerformance .DashboardIcon {
width: 75px;
}
.CorpPerformance .CvalNational { /* no width anymore */
text-align: center;
border-left: 2px dotted black;
background-color: gray;
color: #fff; /* I've remove your span to put the css here, if you can do this it's best to keep html free of css */
font-weight: bold;
}
<table class="CorpPerformance">
<tr>
<td class="DashboardTitle">3 Month</td>
<td class="DashboardScore" style="font-weight:bold"> <a class="redirectLink" data-criteria-corporatesummarycategory="none" data-criteria-corporatesummaryexpand="0" data-criteria-customerpay="" data-criteria-expressservice="" data-criteria-maintenanceplan="" data-criteria-modelname="" data-criteria-rspenddate=""
data-criteria-rspstartdate="" data-criteria-warrantypay="" data-criteria-yearmodel="" data-criteria-department="Sales" data-criteria-reportperiod="[Collection Date].[Calendar].[Calendar Month].&[October 2014]" data-criteria-summaryperiod="3MONTH"
href="/Corporate/OFSSurveySummary">950</a>
</td>
<td class="DashboardIcon">
<a class="bootstrap-modal" data-criteria-chartcustomerpay="" data-criteria-chartexpressservice="" data-criteria-chartmaintenanceplan="" data-criteria-chartmodelname="" data-criteria-chartmodelyear="" data-criteria-chartwarrantypay="" data-criteria-chartdepartment="SALES"
data-criteria-chartmeasurename="Response Default Computation" data-criteria-chartmeasuretype="score" data-criteria-chartorganization="" data-criteria-chartpagetitle="NSSI Trend" data-criteria-chartreportperiod="[Collection Date].[Calendar].[Calendar Month].&[October 2014]"
data-criteria-chartsummaryperiod="3MONTH" data-criteria-charttitle="NSSI" data-criteria-chartwheretuple="[Questionnaire].[Questionnaire].[Question].&[OFSP]&[OFSP13011]" href="/Trend" modal-no-resize="True" upper="NSSI Trend"><span>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAAAZCAYAAACM9limAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHxSURBVFhH7Zg9SEJRFMcdW4QmcRI3xclNcYiGBocGB4dqMQTXdHdoFRqsoCAtJEiMKCpCHkHkECFJUNQgNqgEIQ19DIFBw8n/8SkUPft66n31fnBArnLh/O69556roQHp8WEYSOctuhgFhBdTLN5RLndN2WxZHukNQoopFGrk9W6S1Zogu32FhofXyeFI0cBAnHy+HUqlLunh4Vn+dWfq9RcWG4+f0sjIBnk8aZ5vcHC+kfgMz/URQolBspHIIdlsyxSLnVCl8ih/0wRJbm9f0eSkREbjHJlMC5wkYmIiS4GAxEJbY2bzIsvEZ8w7O3vKkhCfiRVGDFYOuwMr+1Vqtad2oonEOU1NHZAkldtj78V+h76LyedvWIjfv8uJikLfxGA1x8b2yO1O8+qKRs/FYFeMjm5xHclkivKoePRMTKuw4qaZnj7mQioyPRETDjeFoLCKLqRF18XgGh0f3/ty3yEKXRODnYGeQqmBEp2uiMHuQIeKnkKrqC6mVLqnoaGMpqUAVcXg+rVYlrht1zqqiMHRwfsFDZvWiqwSvxaTTF5wS6/VIqvEj8Wcnd3yq9XlWqNq9eePNVHpKAZvGCSPY4JuFREK7fMOcTpXhXzjqEVHMQDJ45hASjR6RMGgxP+q/XU+FfNf0cUo0Bajx/sw0CuzQYKdi8e4ggAAAABJRU5ErkJggg==" /></span></a>
</td>
<td class="CvalNational">Test National</td>
</tr>
</table>

Facebook login button style

I have this code to display a login facebook button
<span style="float:right; height:40px; line-height:45px;vertical-align:top;
font-size:14px; padding-right:10px; "><?php if($this->tank_auth->is_logged_in())
{ echo "Welcome " .anchor('profile',$this->tank_auth->get_username())." | ".anchor
('profile/find_friends','Find Friends')." | ".anchor('auth/logout','Logout');}
else {?><?php echo anchor('auth/login','Login'); ?> |
<fb:login-button v="2" perms="" length="long"
onlogin='window.location="https://graph.facebook.com/oauth/authorize?client_id=<?php echo
$this->config->item('facebook_app_id'); ?>&redirect_uri=<?php echo site_ur
('auth_other/fb_signin'); ?>&r="+window.location.href;'></fb:login-button><?php } ?></span>
<div style="clear:both"></div>
this code converts to this when I browse the page :
<fb:login-button v="2" perms="" length="long"
onlogin="window.location="https://graph.facebook.com/oauth/authorize?
client_id=372198139465874&
redirect_uri=http://allviralvideo.org/auth_other/fb_signin&r="+window.location.href;"
login_text="" class=" fb_iframe_widget" fb-xfbml-state="rendered" fb-iframe-plugin-
query="app_id=372198139465874&locale=en_US&sdk=joey">
**<span style="vertical-align: bottom; width: 69px; height: 22px; ">**<iframe
name="f1d6c3fee8" width="1000px" height="1000px" frameborder="0" allowtransparency="true"
scrolling="no" title="fb:login_button Facebook Social Plugin" style="border-top-style: none;
border-right-style: none; border-bottom-style: none; border-left-style: none; border-width:
initial; border-color: initial; width: 69px; height: 22px; visibility: visible; "
src="http://www.facebook.com/plugins/login_button.php?app_id=372198139465874&channel=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D28%23cb%3Df11db3306c%26domain%3Dallviralvideo.org%26origin%3Dhttp%253A%252F%252Fallviralvideo.org%252Ff72d2ade4%26relation%3Dparent.parent&locale=en_US&sdk=joey" class=""></iframe></span></fb:login-button>
I want to remove vertical-align: bottom; from bold section. I added vertical-align: top; to parent tags but it suppresses them. Is there any way to remove this?
You can target the span in your CSS using whatever is the immediate parent of your Facebook button. Something like:
.parent span {
vertical-align: top !important;
}
Since it's generating in-line styles, you'll need to use the !important or else it will be overridden.
you also be able to target the fb element directly in the CSS, but I've never worked with it so I can't be sure.

Alignment of Buttons Next to Images

I'm having some trouble aligning buttons and small images from a jscript source... Here's a link to the photo slider on the right, where the pink buttons need lining up with the preview images: http://www.inside-guides.co.uk/brentwood/local-tradesmen/roofers-and-roofing-services/ace-roofing-co-ltd.html
Here's the code:
<div id="photos-preview">
<input class="photos-btn" type="button" onclick="slidePrev();" value="<<" />
<% for i = 0 to ubound(images)
%><img src="/includes/tn.asp?src=<%=server.URLEncode(images(i))%>&w=30" style="margin:3px;cursor:pointer" onclick="$('.MainImage').fadeOut(500).hide(0,function(){$('#MainImage<%=images(i)%>').fadeIn(500)});" /><%
next %>
<input class="photos-btn" type="button" onclick="slideNext();" value=">>" />
</div>
And the CSS:
#photo-slider {float:right;width:275px;margin:5px;border:1px
solid #B2B2D4;}
#main-photos {text-align:center;height:200px;padding:8px 0;}
#photos-preview {text-align:center;}
.photos-btn {background-color:#b21589;cursor:pointer;color:#fff;font-size:9px;font-weight:bold;padding:4px;}
Any ideas much appreciated.
Try this css:
#photos-preview img, #photos-preview input {
vertical-align: middle;
}
Here is a preview:
http://jsfiddle.net/k6sWJ/
Change the .photos-btn css class to:
.photos-btn {
background-color: #B21589;
cursor: pointer;
color: white;
font-size: 9px;
font-weight: bold;
padding: 4px;
margin-top: 2px;
vertical-align: top;
}
try to add vertical-align: top; for .photos-btn
make 2 css for next and previous button
and add following to your css
photo-btn-prev {
float :left;
}
photo-btn-next { float : right;}