Text align in span - html

Hello is there a simple way to align text inside span?
I found several solutions but nothing seems to work for me. Here is my code:
<?php echo Yii::t('default','Tax Amount').': ';?>
<span style="border-bottom: 1px solid; ">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($taxamount, 'EUR');?>
</span>
</span>
All I want is to align the $taxamount to the right and leave Tax Amount to the left as is. I thought it was pretty easy at first but nothing works! I also tried it with div and it worked but it messes with anything I have below that. I have three more echo’s like this below that code. I'm not very proficient with CSS and I would appreciate any help.
My full code is something like this:
<?php echo Yii::t('default','Amount').': ';?>
<span style="border-bottom: 1px solid;">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($model->credit, 'EUR');?>
</span>
<br>
<?php echo Yii::t('default','Tax').': 23%';?>
<br>
<?php echo Yii::t('default','Tax Amount').': ';?>
<span style="border-bottom: 1px solid; ">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($taxamount, 'EUR');?>
</span>
</span>
<br>
<?php echo Yii::t('default','Total').': ';?>
<span style="border-bottom: 1px solid;">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($total, 'EUR');?>
</span>
I comment out everything and I only used one solution as suggested below.
So my code now is like this:
p>span {
display: inline-block;
width: 50%;
}
p>span:last-child {
text-align: right;
}
.pull-left {
float: left;
}
.pull-right {
float: right;
}
<p><span>Tax Amount</span><span>EUR 12.50</span></p>
I use mpdf extension in Yii to print the results in pdf. So this is all my code now plus the mpdf extension.But still nothing happens!

A <span> is an inline element, the text align will work, but you'll need to give the element a width (which won't work, while its an inline element).
There are a few ways to do it, one is to display them as inline blocks inside a paragraph:
p>span {
display: inline-block;
width: 50%;
}
p>span:last-child {
text-align: right;
}
<p><span>Tax Amount</span><span>EUR 12.50</span></p>
Another way is to float them: (but I personally prefer the first method)
p>span {
display: block;
float: left;
width: 50%;
}
p>span:last-child {
text-align: right;
float: right;
}
<p><span>Tax Amount</span><span>EUR 12.50</span></p>

If your left-aligned text is inside another element (like my <div> below), you should be able to add the 'float:right' CSS style to your <span>.
<div>
Left-hand text <span style="float:right">Right-hand text</span>
</div>
float is typically used for images, but it can be used with span tags. It works by literally floating your <span> tag to the right edge of your containing element.
This should give you the behavior you're looking for, but you can also check out this question. It looks like they're trying to accomplish something similar.

Related

Text to left and image to right within same tag

I'm having some troubles aligning a piece of text along with an image that should be ( my guess ) within the same tag.
It is supossed to look like this: (Ignore the black stripe)
but it is currently looking like this:
The HTML for it is:
<span class="size-chart-disclaimer">If in doubt, measure your similar<br>
style garment and match our grid.
<img src="{{'we-use.gif' | asset_url}}"/></span>
and the CSS is:
.size-chart-disclaimer img{
float:right;
}
Could someone shed a light on the best way to achieve this ?
I suggest to use a tag for the text, and then style it.
.size-chart-disclaimer img {
float: right;
}
p {
width: 240px;
display: inline-block;
margin-top: 0px;
}
<span class="size-chart-disclaimer">
<p>
If in doubt, measure your similar
style garment and match our grid.
</p>
<img src="http://www.placehold.it/50x50"/>
</span>
Just placing the image in front of the text does the job aswell:
.size-chart-disclaimer img{
float: right;
}
<span class="size-chart-disclaimer">
<img src="http://www.placehold.it/100x50" /> If in doubt, measure your similar
<br /> style garment and match our grid.
</span>
Add following css to yout img tag: vertical-align: middle;
See this JSFiddle

how to center vertically text with adding/updating only css code and very small html code update

I have some html code generated by Wordpress plugin and I want to center vertically the text on the right.I cannot change the HTML code because it's generated by plugin (I have to check if Im allowed to modify its soruce code). In HTML code only DIV tag can be swapped or modified in any way.
But my idea is if this text can be center vertically only by updating existing CSS class definitions and changing only starting and ending DIVs in HTML code?
jsFiddle demo
HTML code:
<div>
<a class="tptn_link" rel="bookmark" href="http://localhost/wordpress/?p=30">
<img class="tptn_thumb" border="1" style="max-width:100px;max-height:100px;" title="Post for TaxTips" alt="Post for TaxTips" src="http://localhost/wordpress/wp-content/plugins/top-10/timthum…2Ftaxhug%2Fimages%2Ffeatured-taxtips.png&w=60&h=60&zc=1&q=75"></img>
</a>
<span class="tptn_after_thumb">
<a class="tptn_link" rel="bookmark" href="http://localhost/wordpress/?p=30">
<span class="tptn_title">
Post for TaxTips
</span>
</a>
<span class="tptn_list_count">
(14)
</span>
</span>
</div>
CSS code:
.tptn_thumb{
margin-right: 10px;
float: left;
}
/* popular post title*/
.tptn_after_thumb{
}
.tptn_after_thumb:after {
content: " ";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
If tptn_thumb has a fixed height you can use line-height: 42px; on tptn_title
EDIT:
Sorry, read "vertically" instead of "horizontally". My solution is for a vertical alignment.
EDIT2:
You need to add this css code:
.tptn_title {
line-height: 42px;
}
and remove the line-height from .tptn_thumb{
See the updated FIDDLE

Having issues applying padding to divs created through WordPress

I have two half width divs that have the same class but are assigned posts through WordPress. Currently I have them lined up with full width posts above and below, but, I need to apply 5px of padding to both but not on the edges, i.e. left post has right padding, right post has left padding and I can't think for the life of me how to do this. I tried using different post formats and checking which format the post was and applying padding based on that but it didn't work as intended. For some reason, it pushed the divs to the center and had padding in the wrong places. Firstly here's my PHP structure with the if/else:
<?php if (has_post_format('status')) : ?>
<div class = "twocolumnpost left">
<div <?php post_class() ?>>
<?php if (has_post_thumbnail()) : ?>
<div class = "post-thumb">
<?php the_post_thumbnail(); ?>
<div class = "caption">
<h4><?php the_title(); ?></h4>
<p><?php echo get_the_date(); ?></p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php elseif (has_post_format('gallery')) : ?>
<div class = "twocolumnpost right">
<div <?php post_class() ?>>
<?php if (has_post_thumbnail()) : ?>
<div class = "post-thumb">
<?php the_post_thumbnail(); ?>
<div class = "caption">
<h4><?php the_title(); ?></h4>
<p><?php echo get_the_date(); ?></p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
As you can see it has padding on both the left and right sides (it should line up with the post above) and not enough in the middle. The CSS I used for this is:
.twocolumnpost .post {
float: left;
display: block;
width: 50%;
padding: 10px 0px;
}
.twocolumnpost.left {
padding-right: 0px;
}
.twocolumnpost.right {
padding-left: 0px;
}
.twocolumnpost img, .twocolumnpost iframe {
max-width: 440px;
max-height: 294px;
width: 100%;
padding: 0;
}
Now what I'd like it to be like is this:
BUT with 10px of padding in the center of the two posts but NOT the sides i.e. 5px right on the left post, 5px left on the right post. The only difference with the second image is that the max-width of the pictures are set to 450px instead of 400px and obviously have no left or right padding.
No matter what I try it doesn't line up properly, and I'm at a loss. Any help would be greatly appreciated. Ideally this could be done without the need for two different post types so it applies correctly to any twocolumnpost but the structure as is works too. Thanks!
Live sit is here: http://suburbia.comoj.com/wordpress/
There are several ways of resolving this issue, but it depends on what kind of users (and browsers) do you want to support. If you don't mind using modern standards (therefore leaving some users on legacy browsers behind), you can use the the calc property:
.twocolumnpost {
width: calc(50% - 10px);
padding: 10px 0px;
}
.twocolumnpost.left {
float: left;
}
.twocolumnpost.right {
float: right;
}
p/s: You don't need to declare the display: block property when you set floats — that's the default behavior for floats anyway.
Even better, you can take advantage of CSS flexbox, but you need to set the parent of .twocolumnpost to have flex display. Let's say the parent has the class name of .twocolumnpost-parent:
.twocolumnpost-parent {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.twocolumnpost .post {
width: calc(50% - 10px);
}
You can see the proof-of-concept fiddle here: http://jsfiddle.net/teddyrised/DMy7r/
Update: On a related note, I have written a jQuery script to do the exact same, but with gallery images. Perhaps you can adapt it to your needs: Responsive Photosets. Not exactly relevant, but addresses the same issue that you are currently facing.
It could be just a white space issue.
You can either so something like have an html comment between your divs killing the whitespace or you can float the divs over. You might have to rework the containing elements to make sure the floats don't do crazy things. But floating the left and right columns (twocolumnpost) should have them flush against each other (unless there is padding/margin on them).
In short I think the gap is being created by the whitespace between the divs with the twocolumnpost class. If you float this two next to eachtoher or remove the whitespace you should be able to have them flush against each other.

CSS Floating an element next to a PHP echoed element

I have a php function that creates a that includes some information in it and a picture (plain HTML) i want to float the picture left and the echoed php function right.
[IMG] [ blah ]
What currently is happening is the image appears above the echoed function
Here is some of the code:
PHP Function Declaration:
function create($preTag ,$name , $description , $downloadlink) {
echo " <div>
<h3>$preTag $name</h3> <ln>
<br>
<h2>$description </h2>
<br>
<h2><a href= $downloadlink >Click here to download!</a> </h2>
</div>
";
}
PHP Function Call:
create("Game:" , "Pong Clone", "A small pong clone. Completed: [Feb 21, 2013]" , "https://github.com/Bevilacqua/Pong");
CSS For div:
div {
border-radius: 2em;
background-color: #ffffa6;
border: .3em solid white;
float: right;
display: inline;
}
CSS For img:
img {
float: left;
display: inline;
}
HTML For img: (Just a test Image)
<a href="www.google.com">
<img src="http://www.dsga.org/images/tournament_sign_up_button.gif">
</a>
Check if you image isn't too big.
I tried your code and it works fine with a smaller image. With a big image (width) it will not have enough space to be next to it.
I did exactly as Patrick Brouwers and I came to the same answer : Your image is just too big. Here is a Fiddle to show it.
http://jsfiddle.net/kEwan/
float:right;
and
float:left;
work fine.
Try to resize the width of the result windows, and you'll see it.
Note : Be careful with you link of the tag, because it should have double quotes around it.

css not showing inline

The way I like for my code to displayed is
Name1
Name2 Jim
The way it is doing now is:
Name1 Name2 Jim
How can I change it so that it looks like the way I want it to?
CSS
.display-left {
float: left;
width: 200px;
text-align: left;
font-weight:bold
}
.display-right {
text-align: left;
}
HTML
<div class="display-left">Name1: </div>
<div class="display-right" > </div>
</div>
<div>
<div class="display-left">Name2: </div>
<div class="display-right">Jim </div>
</div>
Easiest way is to add a clear:left; to your .display-left class. And a float:left; to your display-right class
http://jsfiddle.net/f5cUx/3/
.display-left {
float: left;
width: 200px;
text-align: left;
font-weight:bold;
clear:left;
}
.display-right {
text-align: left;
float:left;
}
The "clear" property specifies on which sides other floating elements are not allowed.
I also just noticed you had wrapped each "row" in a div. In that case you could just put a new class on those "wrapper" divs that clears the float.
http://jsfiddle.net/f5cUx/4/
if you add:
display: block;
to your .display-left class, it would probably work. try it on!
Add display:block to .display-right; . This tells the HTML to say "please take up the whole line" . You could use <br> tags, but this would be good only for one example. After that it is a waste of code
You can also try adding clear:both; to display-right
This tells the HTML to say "break out of the float and always stay below the float"
put a <br> in your html after name1 but before name2 this should do what you want or try <p></p