I'm trying to align text of different sizes on different levels. See the image below to see what I want:
Here is the code I'm trying but it does not seem to work.
div {
background: #1FA3A2;
padding: 50px;
color: #fff;
font-family: sans-serif;
}
<div>
<span style="vertical-align:text-top; font-size:14px;">$</span>
<span style="font-size:30px; vertical-align:top;">199</span>
<span style="font-size:14px; vertical-align:bottom;">/month</span>
</div>
Any help would be really appreciated!
You can specify the line height of the spans as well, and therefore influence the vertical alignment.
div {
background: #1FA3A2;
padding: 50px;
color: #fff;
font-family: sans-serif;
}
<div>
<span style="vertical-align:top; font-size:14px;">$</span>
<span style="font-size:30px; line-height:27px; vertical-align:bottom;">199</span>
<span style="font-size:14px; line-height:16px; vertical-align:bottom;">/month</span>
</div>
You can use the positions and top css attributes to solve the miner alignment issue in your code. See the updated code. Recommending to write the style alone (Instead of inline styles). The given style (top: 'value';) the following code may change based on the overall style which you are planing to give (same as like the picture with the question)
<div>
<span class="dlr">$</span>
<span style="font-size:30px; vertical-align:top;">199</span>
<span class="perd" >/month</span>
</div>
.dlr{
vertical-align:text-top;
font-size:14px;
position:relative;
top:6px;}
.perd{
font-size:14px;
vertical-align:bottom;
position:relative;
top:-4px;}
Here are the Demo
Try:
.a{font-size:12px; vertical-align:text-top; }
.b{font-size:30px; vertical-align:middle}
.c{font-size:12px; vertical-align:sub;}
With:
<div>
<span class="a">$</span>
<span class="b">199</span>
<span class="c">/month</span>
</div>
http://jsfiddle.net/z03cynrp/1/
HI now used to this after or before css property as like this
div > span{
position:relative;
display:inline-block;
vertical-align:top;color:#fff;
}
div > span:after{
position:absolute;
content:"$";
font-size:14px;
top:4px;
left:-6px;
}
div > span:before{
position:absolute;
content:"/month";
font-size:14px;
bottom:3px;
right:-38px;
}
div{background:blue; padding:20px 0; text-align:center;}
<div>
<span style="font-size:30px; vertical-align:top;">199</span>
</div>
This has to do with the fact that all the three of them do not have the same line-heights. I could modify your code to align as you wanted.
span {
line-height: 32px;
}
<div>
<span style="font-size:14px; vertical-align:text-bottom">$</span>
<span style="font-size:30px;">199</span>
<span style="font-size:14px;">/month</span>
</div>
PS: Dont use inline style unless you absolutely have to
Related
So i've read multiple times that putting display:inline-block; in your span will fix it. But i just can't get it to work for me. Probably i just missed something, but i would like help on this.
<html>
<head>
<style>
#font-face {
font-family:myRobotoRegular;
src:url(fonts/Roboto-Regular.ttf);
}
#font-face {
font-family:myRobotoBold;
src:url(fonts/Roboto-Bold.ttf);
}
#font-face {
font-family:myRobotoLight;
src:url(fonts/Roboto-Light.ttf);
}
body {
background-color:black;
color:white;
}
h1 {
font-family:myRobotoBold;
text-align:center;
}
.right {
float:right;
width:49%;
}
.individual {
height:100%;
margin:0 auto;
overflow-y:scroll;
padding-right:10px;
text-align:left;
width:440px;
}
.bannerGreen {
background-color:#0D731D;
padding:10px;
}
.bannerTitle {
font-family:myRobotoBold;
}
.bannerRarity {
font-family:myRobotoLight;
}
.description {
background-color:black;
font-family:myRobotoRegular;
padding:20px 10px 10px 10px;
}
.quotes {
color:#C0B9A7;
}
.orangeStat {
color:#F26A1C;
display:inline-block;
font-family:myRobotoBold;
font-size:20px;
}
.yellowStat {
color:#FFD30B;
display:inline-block;
font-family:myRobotoBold;
font-size:20px;
}
.imgDiv {
float:right;
margin-top:-10px;
}
.img {
height:58px;
}
</style>
</head>
<body>
<div class="mainDiv">
<div class="right">
<div class="individual">
<h1>
CATEGORY
</h1>
<div class="bannerGreen">
<div class="imgDiv">
<img class="img" src="">
</div>
<span class="bannerTitle">
TITLE
</span>
<br>
<span class="bannerRarity">
SUBTITLE
</span>
</div>
<div class="description">
DESCRIPTION
<span class="yellowStat">
STATISTICS
</span>
DESCRIPTION
<span class="orangeStat">
A STATISTIC
</span>.
</div>
<br>
</div>
</div>
</div>
</body>
</html>
The "A" in "A STATISTIC" should well be able to be on the first line, but instead it follows the entire span to the second line.
(Bonus points if you recognize this. ;) )
EDIT: Inline instead of inline-block surely fixes the problem, but then the period after the .orangeStat span jumps away from the span. And i'd like it to not jump away but i do not want it to be included in the span either. Is there a way to get that?
Well, if you want the A and STATISTIC to be treated individually, then you should put them in individual (inline-)block elements:
<span class="orangeStat">
A
</span>
<span class="orangeStat">
STATISTIC
</span>
OR (edit):
Use inline instead of inline-block and to remove the space between the STATISTIC and the period, try something like this:
<span class="orangeStat">
A STATISTIC<!--
--></span>.
Increase the width of the outer container
.individual {
width: 490px;
}
The words are coming in second line because there is no enought space in the container.
Or
Decrease the font-size of yellowStat and orangeStat
I Jerry-rigged a line behind 3 elements by having bars on the right and left of the elements. However, this solution isn't consistent across browsers -- See images below.
Is there a better way to place a line centered behind several objects using HTML and CSS? I tried and failed using pseudo elements/selectors (i.e., :after or :before) before coming to my solution below, but I don't want to rule them out.
Chrome
IE
My solution is, in fact, so jerry-rigged that I can't reproduce it in JS fiddle, but I did something like this:
(My fiddle just for reference https://jsfiddle.net/8t6qtafy/1/)
HTML
<div class="tab-header">
<span>
<div class="header-bar bar-left bar-blank"></div>
<p>1</p>
<div class="header-bar bar-right"></div>
</span>
<span>
<div class="header-bar bar-left"></div>
<p>2</p>
<div class="header-bar bar-right"></div>
</span>
<span>
<div class="header-bar bar-left"></div>
<p>3</p>
<div class="header-bar bar-right bar-blank"></div>
</span>
</div>
CSS
html {
font-family: calibri;
}
.container {
width = 400px;
margin:auto;
}
.tab-header {
margin-top:10px;
position:relative;
padding:5px 10px;
//display:inline-block;
}
.tab-header span {
height:45px;
width:45px;
border-radius:50%;
margin:auto;
color:#4c4a47;
background-color:transparent;
border:2px solid #99958E;
display:block;
position:relative;
}
.tab-header span p {
font-size:30px;
font-weight:bold;
text-align:center;
position:relative;
top:-4px;
left:.5px;
margin:2px;
}
.tab-header .header-bar {
width:130px;
height:3px;
background-color:#99958E;
position:relative;
}
.tab-header .bar-right {
left:42px;
top:-36px;
}
.tab-header .bar-left {
right:130px;
top: 19px;
}
.tab-header .header-bar.bar-blank {
background-color:transparent;
}
A bit late to the party: what browsers needed to be compatible?
Something like that is a bit neater and could work on all modern browsers and IE10: https://jsfiddle.net/fparent/qhprm41a
<div class="tab-header">
<span class="step active">1</span>
<span class="step">2</span>
<span class="step">3</span>
</div>
I made a list with divs, that is displayed fine in Opera, but not in IE.
This is what is happening, in first scene, a line break for some rows, at last span from divs - that contains the class shortcut: http://i.imgur.com/D5wZEdb.png
These are the span and .shortcut styles:
.ui-context-menu .row span{
font-size:16px;
font-family:'Segoe Ui',Arial,sans-serif;
font-weight:400
}
.ui-context-menu .row .shortcut{
float:right;
margin-left:40px;
margin-right:15px
}
In the class row, I did:
.ui-context-menu .row{
display:table;
width:100%;
height:25px;
cursor:default;
padding-right:18px
}
And the class ui-context-menu is a bit normal, but I add a property on to make overflow hidden.
The HTML may turn something so:
<div class="ui-context-menu" data-which="none" oncontextmenu="..." id="context-menu" style="display:none;left:8px;top:50px">
<div class="row able" onmousedown="..." onclick="...">
<div class="base">
<div class="context">
<span>
Load
</span>
<span class="shortcut">
CTRL+O
</span>
</div>
</div>
</div>
</div>
This is an quick fiddle for tests: http://jsfiddle.net/erpngfwv/2/
How can I fix this?
Add this class ".ui-context-menu .row span" float
.ui-context-menu .row span{
float: left;
font-family: "Segoe Ui",Arial,sans-serif;
font-size: 16px;
font-weight: 400;
}
I have some span/div blocks with width and height defined and display set to inline-block but there is some gap between those blocks so i used margin:0px; but there is still gap i have to use negative margin value to remove that gap.
Here is the code i am using
//HTML SPAN BLOCKS//
<body>
<span class="pro" id="1"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
</body>
//CSS//
body{margin:0px;}
.pro{
width:300px;
height:300px;
display:inline-block;
border:1px solid #FF0004;
margin:0px;
padding:0px;
}
#1{
background:#FF0004;
}
and i am giving background with id but its not working. Margin between span blocks works is 0 (when set to 0) in internet explorer.
JSFIDDLE
When i add some content(text) in those tags whole layout is messed up . All blocks moves up and down from its position
this space between inline-block elements is caused by font-size of the parent, in your case the BODY element. To fix this issue set font-size of the parent element to 0 then define new font-size inside .pro elements.
Here is the solution without affecting font-size of body element by wrapping content with .clearGaps container.
https://jsfiddle.net/jrv4zp5d/1/
html:
<div class="clearGaps">
<span class="pro" id="1"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
<span class="pro"></span>
</div>
css:
body{
margin: 0px;
}
.clearGaps {
font-size: 0;
}
.pro{
width:300px;
height:300px;
display:inline-block;
border:1px solid #FF0004;
font-size: 12px; /* restore font size after clearing gaps */
}
#1{
background:#FF0004;
}
Good luck
id's that start with a number will not work in css, unless you escape them in your stylesheet (which I wouldn't advise). So I would suggest changing your id to something like #p1 and you should be fine.
inline(-block) elements take whitespace into account. If you remove the whitespace from your markup, or set the font-size to 0, the spacing between the blocks should disappear. Or you could turn them into block elements as well.
And your updated fiddle:https://jsfiddle.net/jrv4zp5d/2/
CSS:
span {
display: inline-block;
}
HTML:
<span>This will have</span>
<span>a gap between the elements</span>
<span>This won't have</span><span>a gap between the elements</span>
originally #Juan G. Hurtado
Alternatively, for a CSS only approach, you can try changing the display of .pro to block and specify a float.
.pro{
width:300px;
height:300px;
display:block;
float:left;
border:1px solid #FF0004;
margin:0;
padding:0;
}
I have now been looking for hours (obviously not in the right place!)
Please consider this sample: http://jsfiddle.net/DYLs4/9/
<div id="wrapper">
<span id="text24">Text 24</span>
<span id="text12">Text 12</span>
<span id="icon"></span>
</div>
css:
#text24{
font-size:24px; color:#999;
}
#text12{
font-size:12px; color:#000;
}
#icon{
height:36px; width:36px;
display:inline-block;
background:url(some-icon.png);
}
What I'm trying to achieve is this:
Center vertically the text24 (relative to the image)
Align the bottom of text12 with bottom of text24
Make sure the whole thing work in IE6 -> chrome
Many thanks for your help!
Add vertical-align: middle to your image.
EDIT
Per comments, this solution also requires display:inline-block;.
This is working
http://jsfiddle.net/rizwanabbasi/frsA5/1/
I know most of designers hate use table for layout, but let me try anyway.
You can use valign of table.
Final result
http://jsfiddle.net/rizwanabbasi/frsA5/
<div id="wrapper">
<span id="text24">Text 24</span>
<span id="text12">Text 12</span>
<img src="http://www.adlittle.com/fileadmin/templates/images/rss_feed_icon.png" id="icon"/>
</div>
#wrapper{
position:absolute; left:0;
}
#text24{
font-size:24px; color:#999; font-weight:bold;
}
#text12{
font-size:12px; color:#000; font-weight:bold; }
#icon{
height:36px; width:36px;
display:inline;
vertical-align:middle;
}