85209

CSS Vertical Align Baseline HTML Headings

Question:

I have two columns of headings that I want to align to the baseline which are both different font-sizes. In addition to this I want one on the left side and one on the right side.

If you use display: inline-block they are aligned to the baseline, regardless of the max-width.

HTML:

<div class="headings interior"> <div class="headings-position"> <h2 class="left heading">Heading</h2> <h3 class="right sub-heading">Heading with long text & Stuff</h3> </div> </div>

CSS:

h2,h3 { margin: 0; display: inline-block; position: relative; } h2 { left: 0; bottom: 0 } h3 { max-width: 100px; right: 0; bottom: 0; text-align:right; } .headings { position: relative; height: 200px; width: 500px; margin: 0 auto; border: 1px solid #000; }

Fiddle: <a href="http://jsfiddle.net/qgjttauq/" rel="nofollow">http://jsfiddle.net/qgjttauq/</a>

Answer1:

You need to use float: left for h2 instead of left: 0, and float: right for h3 instead of right: 0.

<a href="http://jsfiddle.net/emturano/qgjttauq/1/" rel="nofollow" title="Fiddle">Fiddle</a>

Answer2:

h3 { float: right; //additional styles }

Recommend

  • Trouble running a parser created using scrapy with selenium
  • Toggle DIV state localstorage
  • How to resolve designated initialization error for UITableViewController?
  • Could be Text orientation of JTextArea changed by keyboard shortcut?
  • Zooming an element and its contents— an alternative to CSS3's zoom property?
  • Python PIL remove sections of an image based on its colour
  • How can I have equal heights for inner elements of flexbox grid/boxes/cards without using jQuery?
  • Contact form problem - I do receive messages, but no contents (blank page)
  • How can I make this modal persistent?
  • Put value at centre of bins for histogram
  • CSS - Cannot get one spanned style to override another inherited style and align left
  • RxJava debounce by arbitrary value
  • D3 get axis values on zoom event
  • C: Incompatible pointer type initializing
  • GridView breaks while scrolling
  • Blackberry - Custom EditField Cursor
  • FileReader+canvas image loading problem
  • Body moving without any force applied? (Box2d)
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Insert into database using onclick function
  • Deselecting radio buttons while keeping the View Model in synch
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • How to show dropdown in excel using jrxml (jasper api)?
  • How to get next/previous record number?
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to get icons for entities from eclipse?
  • Proper way to use connect-multiparty with express.js?
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Load html files in TinyMce
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • python draw pie shapes with colour filled
  • unknown Exception android
  • JaxB to read class hierarchy
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal