<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Michael</title>
    <description>The latest articles on DEV Community by Michael (@micmcgrorty).</description>
    <link>https://dev.to/micmcgrorty</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F113086%2F63160ac3-93a2-44f2-886f-bed12e374376.png</url>
      <title>DEV Community: Michael</title>
      <link>https://dev.to/micmcgrorty</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/micmcgrorty"/>
    <language>en</language>
    <item>
      <title>Pure HTML Accordion</title>
      <dc:creator>Michael</dc:creator>
      <pubDate>Tue, 25 Aug 2020 10:32:25 +0000</pubDate>
      <link>https://dev.to/micmcgrorty/pure-html-accordion-3daa</link>
      <guid>https://dev.to/micmcgrorty/pure-html-accordion-3daa</guid>
      <description>&lt;h1&gt;
  
  
  Accordions
&lt;/h1&gt;

&lt;p&gt;In the past when building accordion components, I'll usually reach for Bootstrap's accordion implementation. Most of the projects I work on use Bootstrap so it's always seemed like the obvious choice. It's a wee bit complicated though.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;p&amp;gt;
  &amp;lt;a data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample"&amp;gt;
    Click me please!
  &amp;lt;/a&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="collapse" id="collapseExample"&amp;gt;
  &amp;lt;div&amp;gt;
    Ooh, you clicked!
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You need a lot of attributes to make it work, and it's easy to forget them or mismatch the &lt;code&gt;id&lt;/code&gt; and the &lt;code&gt;href&lt;/code&gt;. The type of problem that's sitting right in front of you but for some reason takes you absolutely ages to see.&lt;/p&gt;

&lt;h1&gt;
  
  
  Details Element
&lt;/h1&gt;

&lt;p&gt;We've now been saved from having to use tons of attributes and ids/hrefs to make our accordions work, thanks to the &lt;code&gt;&amp;lt;detail&amp;gt;&lt;/code&gt; element!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2F3gM1liq7Eetk4%2F200.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2F3gM1liq7Eetk4%2F200.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm not sure how long it's been around, but a colleague has just shown it to me and it's magical. It works like this.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;details&amp;gt;
    &amp;lt;summary&amp;gt;Accordion title&amp;lt;/summary&amp;gt;
    Content you want to show/hide.
&amp;lt;/details&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It starts with a &lt;code&gt;&amp;lt;detail&amp;gt;&lt;/code&gt; element, which has a &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt; element nested within it, as well as whatever content you want to show/hide. Whatever is inside the &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt; element shows as the accordion title, and anything else is shown/hidden when the title is clicked. You'll probably want to do some styling, but the opening/closing is all handled for you. &lt;/p&gt;

&lt;h4&gt;
  
  
  Events
&lt;/h4&gt;

&lt;p&gt;Another cool feature of this element is that is supports the &lt;code&gt;toggle&lt;/code&gt; event whenever the element is opened or closed. Perhaps you'd like to show a cool animation? The world is your oyster!&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;

&lt;p&gt;I've put together a very basic example &lt;a href="https://codepen.io/mmcgrorty1/pen/QWNpEYx" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F6FKazYA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F6FKazYA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Support
&lt;/h1&gt;

&lt;p&gt;The Detail element currently has around 95% browser support, with only IE11 being the only major browser not supporting it. More detailed information on the level of support can be found &lt;a href="https://caniuse.com/#feat=details" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Further Reading
&lt;/h1&gt;

&lt;p&gt;You can read about the Detail element further at MDN.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
    </item>
    <item>
      <title>The Basics of HTML</title>
      <dc:creator>Michael</dc:creator>
      <pubDate>Sat, 22 Aug 2020 20:33:41 +0000</pubDate>
      <link>https://dev.to/micmcgrorty/the-basics-of-html-4a58</link>
      <guid>https://dev.to/micmcgrorty/the-basics-of-html-4a58</guid>
      <description>&lt;h1&gt;
  
  
  What is HTML
&lt;/h1&gt;

&lt;p&gt;HTML is the very first building block of developing websites. It describes to a browser what content to display on a web page, and in a basic way, how that content should be displayed.&lt;/p&gt;

&lt;p&gt;HTML is made up of &lt;em&gt;elements&lt;/em&gt;. An element consists of an opening tag and a closing tag. A tag consists of the name of the element between two angle brackets, with a backslash to indicate if it is a closing tag. Any text between the tags is what is displayed on the page, with the tag indicating what element it is and how it should be displayed.&lt;/p&gt;

&lt;h1&gt;
  
  
  HTML Elements
&lt;/h1&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The above example shows a typical HTML element. It starts with an opening tag, the text we want to display, and then a closing tag. We can see that the closing tag is identical to the opening tag, but the name of the element is preceded by a backslash. MDN has a very good image depicting the anatomy of a HTML element &lt;a href="https://mdn.mozillademos.org/files/9347/grumpy-cat-small.png"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The content between the tags can also encompass other HTML elements. This is called nesting and is generally how HTML pages are built. Elements can be &lt;em&gt;nested&lt;/em&gt; inside other elements to create the page layout that you desire.&lt;/p&gt;

&lt;h4&gt;
  
  
  Element Examples
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; - used to group elements together&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; - used to display a paragraph&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; - used to display an image&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; - used to link to another website or to a particular part of the page&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; through &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt; - used to display a header element, with h1 being the biggest through to h6 being the smallest&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Attributes
&lt;/h1&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;h1 class="header-text"&amp;gt;Hello World&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;HTML elements can have extra pieces of information added into them in the form of an &lt;em&gt;attribute&lt;/em&gt;. They are inserted into the opening tag and follow the format &lt;code&gt;attribute="value"&lt;/code&gt; which can be seen above inside a full element. There are many different types of attributes, some of which are used behind the scenes in CSS or Javascript and some of which are used to tell the element something that it should be doing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Attribute Examples
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;class&lt;/code&gt; - used to target the element through CSS or Javascript along with all other elements that have the same class value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;id&lt;/code&gt; - used to target the element through CSS or Javascript or used to link to this part of the page with an anchor &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;href&lt;/code&gt; - used to provide an anchor element with the link that it should go to&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src&lt;/code&gt; - used to provide a link to the image that an &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; element should display&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Nesting
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
   &amp;lt;body&amp;gt;
      &amp;lt;div&amp;gt;
         &amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;
         &amp;lt;a href="https://www.google.com&amp;gt;Click me!&amp;lt;/a&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
         &amp;lt;h4&amp;gt;Dinosaurs&amp;lt;/h4&amp;gt;
         &amp;lt;p&amp;gt;Dinosaurs are great.&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
   &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above is a typical example of nesting elements within other elements. The top level is an &lt;code&gt;html&lt;/code&gt; element which tells the browser that everything between those tags is going to be HTML. Next is a &lt;code&gt;body&lt;/code&gt; element which tells the browser to display everything between its tags. (There is also a &lt;code&gt;head&lt;/code&gt; element which is where stylesheets and scripts are loaded.) The next level contains two &lt;code&gt;div&lt;/code&gt; elements which are being used to group some elements together. &lt;/p&gt;

&lt;h1&gt;
  
  
  Further Reading
&lt;/h1&gt;

&lt;p&gt;If you're interested in reading more about HTML, MDN has a wealth of information about all topics relating to HTML.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
    </item>
    <item>
      <title>How to stack HTML elements</title>
      <dc:creator>Michael</dc:creator>
      <pubDate>Tue, 19 May 2020 15:25:58 +0000</pubDate>
      <link>https://dev.to/micmcgrorty/how-to-stack-html-elements-40kd</link>
      <guid>https://dev.to/micmcgrorty/how-to-stack-html-elements-40kd</guid>
      <description>&lt;p&gt;I recently had to build this. It's a button with a separate image behind it, providing a cool background effect to the container the button is in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6egrk8qk2vxfmxp10kww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6egrk8qk2vxfmxp10kww.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, I didn't have a clue what to do. I'm familiar with &lt;code&gt;z-index&lt;/code&gt; but I'd never used it to stack elements directly on top of each other like that.&lt;/p&gt;

&lt;p&gt;After a bit of Googling and speaking to a colleague, here's what I ended up doing.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;div class="container"&amp;gt;
   &amp;lt;img class="image" src=""&amp;gt;
   &amp;lt;a href="" target="_blank" class="btn"&amp;gt;Button&amp;lt;/a&amp;gt;
&amp;lt;/div&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  The container
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.container {
  display: flex;
  align-items: center;
  justify-content: center;
  float: left
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I'm using flexbox here along with &lt;code&gt;align-items: center&lt;/code&gt; and &lt;code&gt;justify-content: center&lt;/code&gt; so that my image and button are both centred inside the parent container. Depending on your needs this may not be the right solution for you. You can read more on flexbox by following the link at the bottom of the page.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;float: left&lt;/code&gt; here isn't needed for the actual stacking of elements, but in my case it was needed to ensure that the component is left-aligned relative to some text above it, but also that the image stays centred behind the button.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.image {
    z-index: 1;
    position: absolute;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I've given the image &lt;code&gt;z-index: 1&lt;/code&gt; and &lt;code&gt;position: absolute&lt;/code&gt;. Absolute positioning essentially pulls the element out of the normal document flow meaning that surrounding elements won't be affected by this element. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Button
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.btn {
    z-index: 2;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With &lt;code&gt;z-index: 2&lt;/code&gt;, and absolute positioning on the image this means the button is nicely stacked on top of the image.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;These basic properties should give you a button stacked nicely on top of an image. This is because the button is now acting as if the image wasn't even there. So rather than getting positioned next to it, it is now on top of it.&lt;/p&gt;

&lt;p&gt;If you'd like to learn more about flexbox, absolute position or relative position then check out these great MDN links.&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Flexbox" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Glossary/Flexbox&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm keen to hear if there are any other ways this could be tackled, or any ways my implementation could be improved. So please leave a comment!&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
