<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CSS &#8211; The Web Developer Guide</title>
	<atom:link href="https://thewebdeveloperguide.com/category/frontend/css/feed/" rel="self" type="application/rss+xml" />
	<link>https://thewebdeveloperguide.com</link>
	<description>A Developers Guide to Web Develoment</description>
	<lastBuildDate>Wed, 08 Feb 2023 10:30:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>
	<item>
		<title>CSS Z-Index Not Working! Send Help!</title>
		<link>https://thewebdeveloperguide.com/css-z-index-not-working-send-help/</link>
		
		<dc:creator><![CDATA[Kris Barton]]></dc:creator>
		<pubDate>Thu, 28 Mar 2019 15:26:25 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[css positioning]]></category>
		<category><![CDATA[css z-index not working]]></category>
		<category><![CDATA[positioning]]></category>
		<category><![CDATA[z-index]]></category>
		<guid isPermaLink="false">https://www.thewebdeveloperguide.com/?p=106</guid>

					<description><![CDATA[You're CSS z-index isn't working? Here's why:]]></description>
										<content:encoded><![CDATA[
<p>“Help!! CSS z-index not working!!! WTF!!!!”<br></p>



<p>Is this you (but without the cursing)? Don’t worry &#8211; I feel your pain. No matter how many pop-ups or fixed navigation systems I make, I always seem to forget the golden rule with the CSS z-index selector: <em>they only work on specifically positioned elements</em>.</p>



<p>Gets me <em>every single time.</em></p>



<p><strong>TL;DR:</strong> the most common cause for z-index not working is not explicitly declaring a CSS position value (i.e. position: relative, absolute, fixed or stick) on the element.<br></p>



<p>But if this hasn’t solved your z-index issue or just want to get a little more information about the CSS property, then let’s go a little deeper.</p>



<h2 class="wp-block-heading">What&#8217;s a CSS z-i<g class="gr_ gr_7 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="7" data-gr-id="7">ndex</g>?</h2>



<p>I think the W3Schools definition of the z-index property sums it up the best:<br></p>



<blockquote class="wp-block-quote">
<p><em>“The z-index property specifies the stack order of an element.”</em><br></p>
<cite>W3Schools &#8211; <br><a href="https://www.w3schools.com/cssref/pr_pos_z-index.asp" target="_blank" rel="noopener">https://www.w3schools.com/cssref/pr_pos_z-index.asp</a> </cite></blockquote>



<p>This basically means you can use this CSS property to stack items on top of each other. <br></p>



<p>Another good way I like to look at it is: it&#8217;s basically the concept of layers for websites. </p>



<p>If you’ve ever used any kind of decent image editing/creation software like Photoshop, GIMP or maybe even Canva, then will no doubt have come across the concept of layers: the ability place images, shapes, text and anything else you might use on top of each other to create a stunning effect or display.<br></p>



<p>That’s what the CSS z-index property can do for your website design.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" width="400" height="400" src="https://www.thewebdeveloperguide.com/wp-content/uploads/2019/03/tried-z-index-1-liked-it.jpg" alt="Tried z-index: 1; Liked it sudden realisation meme. CSS z-index is not working article." class="wp-image-108" srcset="https://thewebdeveloperguide.com/wp-content/uploads/2019/03/tried-z-index-1-liked-it.jpg 400w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/tried-z-index-1-liked-it-150x150.jpg 150w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/tried-z-index-1-liked-it-300x300.jpg 300w" sizes="(max-width: 400px) 100vw, 400px" /></figure></div>


<h2 class="wp-block-heading">I&#8217;ve set the positioning, but my CSS z-index is not working!</h2>



<p>Okay, you&#8217;ve read the section above and have a pretty good grip on the concept of the z-index property. You&#8217;ve also set a CSS position value on the element, but your CSS z-index is still not working. </p>



<p>What now?</p>



<p>Well, the next thing to investigate is the order of your HTML elements and how you&#8217;ve applied your z-index property to them.</p>



<p>Here&#8217;s a pretty good example how the CSS z-index works in a real-world scenario that might just fix your problem.</p>



<h2 class="wp-block-heading">How does the CSS z-index Property Work?</h2>



<p>The CSS z-index property works by assigning the property with a numeric value to any element. <br></p>



<p>The property can take large numeric values, as well as minus values should you want to position elements further back in the stack.<br></p>



<p>An element without a z-index specifically assigned to it, automatically inherits in the z-index of its parent and if the parent element doesn’t have a value set, then the default z-index is 0.<br></p>



<p>Here’s a visual demonstration of how it works:<br></p>



<pre class="wp-block-preformatted"><p class="codepen" data-height="265" data-theme-id="0" data-default-tab="css,result" data-user="TheWebDeveloperGuide" data-slug-hash="YgbKdR" style="height: 265px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="Help! My z-index isn't working! The Web Developer Guide">
  <span>See the Pen <a href="https://codepen.io/TheWebDeveloperGuide/pen/YgbKdR/" target="_blank" rel="noopener">
  Help! My z-index isn't working! The Web Developer Guide</a> by Kris Barton (<a href="https://codepen.io/TheWebDeveloperGuide" target="_blank" rel="noopener">@TheWebDeveloperGuide</a>)
  on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</span>
</p>
<script async="" src="https://static.codepen.io/assets/embed/ei.js"></script>
</pre>



<p>As you can see from the example above, we’re trying to position both layer 1 and layer 2 to the top left of the base layer. To do this we’re using the absolute positioning CSS property along with the z-index property.<br></p>



<p>As you can see, the orange layer (layer 2) is the layer on top. This is because we’ve set the z-index for the layer to 2. The blue layer (layer 1) is set to a z-index of 1, so layer 2 will be displayed on top.<br></p>



<p>But what if we set layer 2 to have a z-index of 1? You might think that layer 1 would take precedence and layer 2 would be hidden behind it, but that’s not what happens.<br></p>



<p>Because layer 2 uses absolute positioning and its HTML element is underneath layer 1, it takes precedence. This can be tested by moving layer 1’s element underneath layer 2.<br></p>



<p>Now, if we alter the layer 2 z-index to have a value of 2 rather than 1, layer 2 takes precedence again because we’ve explicitly stated it should be place higher than layer 1 in the CSS.<br></p>



<p>Very interesting stuff (at least, it is for geek like me).</p>



<h2 class="wp-block-heading">What can you do with a z-index?</h2>



<p>Okay, so there’s the basic functionality of the z-index CSS property so let’s take a look at some real world examples.<br></p>



<p>Let’s say we want to create a fixed navigation menu that hovers over the main page content. Then, whenever an option is clicked a sub menu is displayed over the top of the floating navigation menu and the main content. This is a scenario where the z-index CSS property becomes essential.<br></p>



<p>To do this, we’ll be using HTML5, CSS and Javascript &#8211; <a href="https://codepen.io/TheWebDeveloperGuide/pen/xBNaBZ" target="_blank" rel="noopener">click here to jump to the codepen</a> (a codepen embed can’t do this bad boy justice).<br></p>



<h3 class="wp-block-heading">Z-Index: Get Your Layers Right!</h3>



<p>As you can see from the code demo, I’m setting the z-index in 2 places:<br></p>



<ol>
<li>I’m setting the main navigation panel to have a z-index of 1.</li>



<li>I’m setting the sub navigation panels to have a z-index of 2.</li>
</ol>



<p>I want the layering of my elements to be the sub navigation links on the top, then the navigation and finally the content behind them. This could’ve been achieved a little easier than I’ve done it in this example, but I wanted to demonstrate the z-index element hierarchy in action.<br></p>



<p>I’ve included the HTML elements in this order:<br></p>



<ol>
<li>Sub navigation links.</li>



<li>Navigation panel.</li>



<li>Content.</li>
</ol>



<p>Because I’ve added the sub navigation links first, I have to specifically assign them a higher z-index than the navigation panel. This is because if the second element has<strong> the same z-index</strong>, it will take precedence over the first and <strong>will overlap it</strong>. <br></p>



<p>In our example, it would mean the sub navigation links would be hidden behind the navigation panel.<br></p>



<p>Conversely, if I move the sub navigation below the navigation panel and changed its z-index to 1, <strong>then the sub navigation items would still overlap the navigation panel</strong>. <br></p>



<p>Pretty interesting stuff once you break it down and examine it. Feel free to fork my codepen and have a play around with the elements yourself.</p>



<h2 class="wp-block-heading">Top Tip: Think About Your z-index Elements In Advance When Planning Your Website</h2>



<p>When creating a website, you might find yourself with a number of different elements that will need to be layered and overlap on the same page, sometimes at the same time.</p>



<h3 class="wp-block-heading">Start Planning</h3>



<p>It’s worth planning in advance the order in which your z-index elements should take precedence. For example, should your popup box be able to overlap your navigation element? Or should it be the other way around.<br></p>



<p>I say this because a lot of developers will automatically set the z-index of an element to a high number (something like 999) and this okay because it’s definitely going to overlap the page with such a high value, but doesn’t take into account scenarios where you have two or more overlapping elements action and open at the same time.</p>



<p>Let me hammer home that point in meme form:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" loading="lazy" width="498" height="457" src="https://www.thewebdeveloperguide.com/wp-content/uploads/2019/03/css-z-index-not-working.jpg" alt="Too Damn High Meme about the CSS Z-Index in CSS z-index not working article" class="wp-image-107" srcset="https://thewebdeveloperguide.com/wp-content/uploads/2019/03/css-z-index-not-working.jpg 498w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/css-z-index-not-working-300x275.jpg 300w" sizes="(max-width: 498px) 100vw, 498px" /></figure></div>


<p>This might not ever be a scenario you need to worry about, but if you think it might be then it’s a good idea to come up with a more sensible z-index valuation system.<br></p>



<p>For example, you can always image the base layer of your website to have a z-index value of 0. Set the next value you’d like to overlap to have a z-index value of 1. If then you decide you need another element to overlap and it’s more important to the user to display it over the top of the previous overlapping element, then set it to 2 and so on.<br></p>



<p>This way, you can always guaranteed the right overlay will be displayed to the user. </p>



<h2 class="wp-block-heading">Further Reading:</h2>



<ul>
<li><a href="https://www.w3schools.com/cssref/pr_pos_z-index.asp" target="_blank" rel="noopener">https://www.w3schools.com/cssref/pr_pos_z-index.asp</a></li>



<li><a href="https://css-tricks.com/almanac/properties/z/z-index/" target="_blank" rel="noopener">https://css-tricks.com/almanac/properties/z/z-index/</a></li>



<li><a href="https://philipwalton.com/articles/what-no-one-told-you-about-z-index/" target="_blank" rel="noopener">https://philipwalton.com/articles/what-no-one-told-you-about-z-index/</a></li>



<li><a href="https://webdesign.tutsplus.com/articles/what-you-may-not-know-about-the-z-index-property--webdesign-16892" target="_blank" rel="noopener">https://webdesign.tutsplus.com/articles/what-you-may-not-know-about-the-z-index-property&#8211;webdesign-16892</a></li>
</ul>



<p><br></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Vertically Align Text Using CSS</title>
		<link>https://thewebdeveloperguide.com/css-vertical-align-text/</link>
		
		<dc:creator><![CDATA[Kris Barton]]></dc:creator>
		<pubDate>Mon, 04 Mar 2019 13:01:17 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<guid isPermaLink="false">https://www.thewebdeveloperguide.com/?p=6</guid>

					<description><![CDATA[Want to know how to vertically align text in CSS? Here's how:]]></description>
										<content:encoded><![CDATA[
<p>You have a large HTML Div with some text inside. You’ve got text centered horizontally with CSS no problem, but vertically? Hmm. That’s a little trickier and you’re stumped.<a href="https://shareasale.com/r.cfm?b=1291521&amp;u=508016&amp;m=41388&amp;urllink=&amp;afftrack=" target="_blank" rel="noreferrer noopener"></a></p>



<p>Or maybe you want a completely different kind of CSS vertical align text altogether. Maybe you have a line of text with two different font sizes and you want the smaller font to be vertically aligned to the middle of the larger font size &#8211; like a quote or citation or something like that. <a rel="noreferrer noopener" target="_blank" href="https://shareasale.com/r.cfm?b=1291521&amp;u=508016&amp;m=41388&amp;urllink=&amp;afftrack="></a></p>



<p>Both are completely different scenarios, with different solutions but both of them make you want to scream the same thing: CSS <g class="gr_ gr_3 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="3" data-gr-id="3">vertical align</g> text how I do dis???</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" loading="lazy" width="500" height="500" src="https://www.thewebdeveloperguide.com/wp-content/uploads/2019/03/how_i_do_dis.jpg" alt="CSS Vertical Align Text - How I Do Did - The Web Developer Guide" class="wp-image-21" srcset="https://thewebdeveloperguide.com/wp-content/uploads/2019/03/how_i_do_dis.jpg 500w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/how_i_do_dis-150x150.jpg 150w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/how_i_do_dis-300x300.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></figure></div>


<p>It can be frustrating, but we have options &#8211; let’s take a look. <br></p>



<h2 class="wp-block-heading">Defining our Scenarios</h2>



<p>I know we kinda defined the scenarios already in the introduction to this post, but let’s make sure we’re absolutely clear on what we’re trying to accomplish here.</p>



<h3 class="wp-block-heading">Scenario 1</h3>



<p>We have an HTML div where we want the text inside the div to be vertically aligned at the center. Like this:<br></p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" loading="lazy" width="576" height="305" src="https://www.thewebdeveloperguide.com/wp-content/uploads/2019/03/scenario_1.png" alt="CSS Vertical Guide - Scenario 2 - The Web Developer Guide" class="wp-image-15" srcset="https://thewebdeveloperguide.com/wp-content/uploads/2019/03/scenario_1.png 576w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/scenario_1-300x159.png 300w" sizes="(max-width: 576px) 100vw, 576px" /></figure></div>


<h3 class="wp-block-heading">Scenario 2</h3>



<p>We have a line code that has two different font sizes. We want the smaller font size to be vertically aligned to the middle of the larger font size. Like this:<br></p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" loading="lazy" width="481" height="63" src="https://www.thewebdeveloperguide.com/wp-content/uploads/2019/03/scenario_2.png" alt="CSS Vertical Align Text - Scenario 1 - The web Developer Guide" class="wp-image-16" srcset="https://thewebdeveloperguide.com/wp-content/uploads/2019/03/scenario_2.png 481w, https://thewebdeveloperguide.com/wp-content/uploads/2019/03/scenario_2-300x39.png 300w" sizes="(max-width: 481px) 100vw, 481px" /></figure></div>


<p>Let’s start off with the first scenario.</p>



<h2 class="wp-block-heading">CSS Vertical Align Text with CSS Flexbox</h2>



<p>So we want to vertically align text in a div or some other container. <br></p>



<p>One way to do this, is to use CSS Flexbox. If you’re unfamiliar with Flexbox, it’s a CSS layout module that makes it easier to make your layout design more flexible and responsive.<br></p>



<p>Flexbox allows you to have a little more control over your layout and makes vertically aligning text a breeze using the align-items selector. <br></p>



<p>Let’s take a look at the code:<br></p>



<p><p class="codepen" data-height="500" data-theme-id="dark" data-default-tab="css,result" data-user="TheWebDeveloperGuide" data-slug-hash="XGmYab" style="height: 500px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="CSS Vertical Align Text Scenario 1 - Flex">
  <span>See the Pen <a href="https://codepen.io/TheWebDeveloperGuide/pen/XGmYab/" target="_blank" rel="noopener">
  CSS Vertical Align Text Scenario 1 &#8211; Flex</a> by Kris Barton (<a href="https://codepen.io/TheWebDeveloperGuide" target="_blank" rel="noopener">@TheWebDeveloperGuide</a>)
  on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</span>
</p>
<script async src="https://static.codepen.io/assets/embed/ei.js"></script></p>



<p>Here, I’m using 3 CSS Flexbox selectors:<br></p>



<ol>
<li>I’m declaring it a Flexbox item using <em>display: flex; </em>This means that I’m making it possible for anything inside that div (child elements) to be controlled by CSS Flexbox.</li>



<li>I’m using <em>justify-content: center</em> to center the text horizontally.</li>



<li>I’m using <em>align-items: center</em> to align the text vertically.</li>
</ol>



<h3 class="wp-block-heading">Can I Use Flexbox Align-Items?</h3>



<p>Before you take this as your final solution, you should probably first work out whether you’re able to actually use CSS Flex and the align-items selector.<br></p>



<p><em>Why can’t I use it?</em> You might be asking yourself. The answer is simple: browser support. CSS Flex doesn’t work all that great in older browser &#8211; particularly IE (surprise, surprise).<br></p>



<p>In fact, even IE11 is listed as having only partial support (IE Edge supports it completely).<br></p>



<p>So if you need to support older browsers for any reason, just be aware of this. You can find out more about the browser support for the align-items CSS selector <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">at CanIUse.com</a>.</p>



<h2 class="wp-block-heading">CSS Vertical Align Text with CSS Grid</h2>



<p>We can accomplish CSS vertical align text with a newer CSS layout module know as Grid. CSS Grid is a bit of an update on CSS Flexbox and is <em>really </em>useful for making great layouts.<br></p>



<p>Here’s a Codepen showing how we vertically aligned our text using CSS Grid:<br><br><p class="codepen" data-height="500" data-theme-id="dark" data-default-tab="css,result" data-user="TheWebDeveloperGuide" data-slug-hash="MxaZLz" style="height: 500px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="CSS Vertical Align Text Scenario 1 - Grid">
  <span>See the Pen <a href="https://codepen.io/TheWebDeveloperGuide/pen/MxaZLz/" target="_blank" rel="noopener">
  CSS Vertical Align Text Scenario 1 &#8211; Grid</a> by Kris Barton (<a href="https://codepen.io/TheWebDeveloperGuide" target="_blank" rel="noopener">@TheWebDeveloperGuide</a>)
  on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</span>
</p>
</p>



<p>For a simple example such as this, it might seem there’s no difference between the CSS Flexbox and CSS Grid layout modules, but once your layout become a little more complicated the power of the Grid layout style will become more and more apparent.</p>



<h3 class="wp-block-heading">Can I Use CSS Grid Align-Items?</h3>



<p>Again, a word of warning before you implement this solution: make sure you’re able to use it on whichever web browsers you support.<br></p>



<p>Despite CSS Grid is a newer technology than CSS Flexbox, there’s still pretty much the same support there. There’s minor support on IE10 and IE11 (limited functionality and what you can do must be limited to IE specific CSS selectors), but every other modern browser is basically fine. <br></p>



<p>Again, you can check out <a href="https://caniuse.com/#search=grid" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">browser support for CSS Grid yourself at CanIUse.com</a>.</p>



<h2 class="wp-block-heading">CSS Vertical Align Text with CSS Absolute Positioning</h2>



<p>With all the wonderful layout functionality that’s built into CSS, using Absolute Positioning in CSS to accomplish our goal of vertically aligning text, in my opinion, is a little bit overkill. <br></p>



<p>BUT for thoroughness, it’s worth mentioning this way of aligning text vertically just in case it’s the only option available to you (for whatever reason).<br></p>



<p>Take a look at our Pen:<br></p>



<p><p class="codepen" data-height="500" data-theme-id="dark" data-default-tab="css,result" data-user="TheWebDeveloperGuide" data-slug-hash="eXJMdz" style="height: 500px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="CSS Vertical Align Text Scenario 1 - Absolute Positioning">
  <span>See the Pen <a href="https://codepen.io/TheWebDeveloperGuide/pen/eXJMdz/" target="_blank" rel="noopener">
  CSS Vertical Align Text Scenario 1 &#8211; Absolute Positioning</a> by Kris Barton (<a href="https://codepen.io/TheWebDeveloperGuide" target="_blank" rel="noopener">@TheWebDeveloperGuide</a>)
  on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</span>
</p><br></p>



<p>As you may notice, there’s a little more going on in here. <br></p>



<p>Firstly, if you’ve used absolute positioning in CSS before then you’ll know that if I want my item to be positioned absolutely within the containing div, then that divs positioning must be set explicitly to relative. Otherwise, the div assigned absolute positioning will not be contained to the container &#8211; just the webpage itself. <br></p>



<p>Secondly, you may be wondering about the use of the CSS Calc function. For those of you who haven’t used the Calc function before, your missing out on a really powerful CSS feature. I’m not going to go into too much detail about the function here, but <a href="https://www.w3schools.com/cssref/func_calc.asp" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">go read more about it at W3Schools for more information</a> &#8211; it’ll be SO worth your time. Essentially, what I’m doing here is calculating the true middle of the container div, based on the height of the inner div.<br></p>



<p>Let me explain: when you use top &nbsp;50%, the web browser will calculate 50% from the top of the container div (in this case .box) to the <strong>top</strong> of our inner div (.box__content). This means the content inside the inner div will fall below the middle of the contain div and just look <em>off</em>. <br></p>



<p>There are a number of ways to combat this, but assigning the inner div a set height and using the CSS Calc function to work out absolute center is the sleekest option for me.<br></p>



<p>You could just tweak the top value until it looks right, but then you’ll end up with a value of 47% or some other random number (or magic number if you like) which isn’t as web developer friendly for my liking. <br></p>



<p>Let’s take a look how we can vertically align our text for the second scenario.</p>



<h2 class="wp-block-heading">CSS Vertical Align Text with Vertical Align CSS Selector</h2>



<p>Let’s start off by defining a real-world example of why you might need to vertically align different sized font on the same line.<br></p>



<p>We want to create a standard quote styling in which the actual quote text is larger than the citation. <br></p>



<p>In this situation you’d use the vertical-align selector tag and set it’s value to <em>middle</em>.<br></p>



<p>As the name of the CSS selector suggests, the vertical-align property sets the vertical alignment of an inline or table property. It has a number of cool options:<br></p>



<ol>
<li>Baseline</li>



<li>Top</li>



<li>Middle</li>



<li>Bottom</li>



<li>Sub</li>



<li>Text-Top</li>



<li>Length (in which you can specify a value for the vertical alignment)</li>



<li>Percentage (in which you can specify the percentage of the vertical alignment)</li>
</ol>



<p>For the task we’re trying to accomplish here, we’re going to use the <em>middle </em>option. See our demo Codepen below:<br></p>



<p><p class="codepen" data-height="500" data-theme-id="dark" data-default-tab="html,result" data-user="TheWebDeveloperGuide" data-slug-hash="NJGwKQ" style="height: 500px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="CSS Vertical Align Text Scenario 2">
  <span>See the Pen <a href="https://codepen.io/TheWebDeveloperGuide/pen/NJGwKQ/" target="_blank" rel="noopener">
  CSS Vertical Align Text Scenario 2</a> by Kris Barton (<a href="https://codepen.io/TheWebDeveloperGuide" target="_blank" rel="noopener">@TheWebDeveloperGuide</a>)
  on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</span>
</p></p>



<p>This way of vertical alignment in CSS is actually really quite useful, especially of you have a combination of text and images you want to line up just right on the same line. </p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>CSS Vertical Align Text can mean 2 different things.<br></p>



<ol>
<li>You want to align text vertically within a container.</li>



<li>You want larger and smaller text or text and images to align vertically inline.</li>
</ol>



<p>For the first scenario there are 3 different ways to do it:<br></p>



<ol>
<li>Using CSS Flexbox.</li>



<li>Using CSS Grid.</li>



<li>Using CSS Absolute position.</li>
</ol>



<p>Option 1 or 2 are the best ways to vertically align text within a container, but don’t have full support in some of the older web browsers.<br></p>



<p>For the second scenario, there’s only really one option that makes any kind of sense: the vertical-align: middle tag. </p>



<h2 class="wp-block-heading">Further Reading</h2>



<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align" target="_blank" rel="noopener">Vertical Align CSS Property &#8211; MDN Web Docs</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.w3schools.com/cssref/pr_pos_vertical-align.asp" target="_blank">W3Schools Vertical Align Property</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/" target="_blank">Flexbox Cheat Sheet &#8211; CSS Tricks</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.w3schools.com/css/css3_flexbox.asp" target="_blank">W3Schools CSS Flexbox</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox" target="_blank">Basic Concepts of Flexbox &#8211; MDN Web Docs</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.w3schools.com/cssref/css3_pr_align-items.asp" target="_blank">Align-Items Property &#8211; W3Schools</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.w3schools.com/css/css_positioning.asp" target="_blank">CSS Positioning &#8211; W3Schools</a></li>



<li><a href="https://www.w3schools.com/cssref/func_calc.asp" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">CSS Calc Function &#8211; W3Schools</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
