Alternative Image Classes in Markdown
How do I make an alternative image classes in markdown?
This is a kind-of "hack" to apply CSS to images in Markdown.. What is a alternative image classes in markdown? How do you make a alternative image classes in markdown? This script and codes were developed by Kevin Gimbel on 11 August 2022, Thursday.
Alternative Image Classes in Markdown - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Alternative Image Classes in Markdown</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ * { margin: 0; padding: 0; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; position: relative;
}
body { font: 1rem/1.6em sans; margin: 5em auto; width: 100%; max-width: 50em; padding: 1.5em; background: #ddd;
}
a { color: grey; text-decoration: none; border-bottom: 1px solid grey;
}
a:hover { color: black; border-bottom: none;
}
h1 { font: 2em/1.6em sans;
}
pre { background: #313131; padding: .5em; color: white; overflow-x: scroll;
}
h3 { padding: 1em 0 0 0;
}
p { padding: .5em 0 1em 0; line-height: 1.65em;
}
code { background: #313131; padding: .2em .4em; color: white;
}
img { width: 100%;
}
img:after { content: attr(alt); position: absolute; bottom: 0; left: 0; background: #313131; color: black;
}
/*IMG "Hack" */
img[title*="imgClass--small"] { width: 20em;
}
img[title*="imgClass--rounded"] { -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px;
}
img[title*="imgClass--shadow"] { -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.8); -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.8); box-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
}
img[title*="imgClass--gray"] { -webkit-filter: grayscale(1); filter: grayscale(1);
}
img[title*="imgClass--float-right"] { width: 50%; float: right; margin-left: .5em; margin-bottom: .5em;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <h1>Alternative image classes in Markdown</h1>
<h3>The Problem</h3>
<p>My main problem with Markdown is that I'm unable to give classes to images. I like to have classes for everything. The benefits I have from giving classes to nearly every element is that I'm in full control when I design a website. If I'm using a lossy mix of direct selectors and classes it becomes messy.</p>
<p>However, let's assume I'm writing an article with a lot of images. I don't want them all to just "be" there, I want to style them. I want them to float to the left and right, have borders or apply shadows or whatever else. I want to use the full potential of CSS. </p>
<h3>Markup</h3>
<p>The markup for images in Markdown is pretty simple as you can see below:</p>
<pre><code>![image alt text](http://url.to/img.jpg)
</code></pre>
<p>You can apply an alt Text by writing it between <code>[</code> and <code>]</code>, an title Attribute can also be set by writing it in quotes right after the URL or PATH of the image. The only way I found to apply a specific style to images in Markdown is "hacking" into the <code>title</code> or <code>alt</code> Attribute. I decided to do it with the <code>title</code>, it would work the same way with alt.</p>
<h4>Markdown</h4>
<p><img src="http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949" alt="Image of a Car.">
First we define an image in Markdown. It's the same you can see above. <em>Notice: It is already styled by CSS (see line 23)</em></p>
<pre><code>![Image of a Car.](http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949)
</code></pre>
<p>The next step is to apply a title Attribute to the image. </p>
<pre><code>![Image of a Car.](http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949 "Hi, I'm the title!")
</code></pre>
<p>We'll now use this title Attribute to style specific images.</p>
<h4>CSS</h4>
<p>To use our "hacked" class we now need to use a special CSS Selector Method: The Attribute Selector. With the Attribute Selector you can easily access an Attribute, similar to styling an <code>h2</code> an Attribute Selector Style applies to all matching elements. In our case we'll likely want to address images only.
The markup is pretty easy:</p>
<pre><code>img[title*="imgClass--rounded"] { -webkit-border-radius:3px; -moz-border-radius:3px; border-radius:3px;
}
</code></pre>
<p>This small snippet simply points to "an image with a title attribute that contains imgClass--rounded". There are other selectors like that, e.g. <code>a[href$="https"]</code>,<code>input[type="text"]</code>,<code>div[class^="whatever"]</code> - I'll maybe cover them in a blog post.</p>
<p>To prevent conflicts I decided to name all "classes" I apply to the image <code>imgClass--</code> followed by the name. Below you can see some examples, hover them to get the Title attribute, the last word always represents the "class".</p>
<p><img src="http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949" alt="Image of a Car." title="A beautiful car imgClass--rounded"></p>
<p><img src="http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949" alt="Image of a Car." title="A beautiful car imgClass--shadow"></p>
<p><img src="http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949" alt="Image of a Car." title="A beautiful car imgClass--gray"></p>
<p>Another use-case could be to float an image to the right or left as shown below. </p>
<p><img src="http://cdn.eyeem.com/thumb/h/800/605f2220bc97deaa5c22e9bf427893c2cfcc458c-1377867949" alt="Image of a Car." title="A beautiful car imgClass--float-right"></p>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>That's it. Suggestions can be sent directly via <a href="http://twitter.com/_kevinatari">twitter</a></p>
</body>
</html>
Alternative Image Classes in Markdown - Script Codes CSS Codes
* { margin: 0; padding: 0; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; position: relative;
}
body { font: 1rem/1.6em sans; margin: 5em auto; width: 100%; max-width: 50em; padding: 1.5em; background: #ddd;
}
a { color: grey; text-decoration: none; border-bottom: 1px solid grey;
}
a:hover { color: black; border-bottom: none;
}
h1 { font: 2em/1.6em sans;
}
pre { background: #313131; padding: .5em; color: white; overflow-x: scroll;
}
h3 { padding: 1em 0 0 0;
}
p { padding: .5em 0 1em 0; line-height: 1.65em;
}
code { background: #313131; padding: .2em .4em; color: white;
}
img { width: 100%;
}
img:after { content: attr(alt); position: absolute; bottom: 0; left: 0; background: #313131; color: black;
}
/*IMG "Hack" */
img[title*="imgClass--small"] { width: 20em;
}
img[title*="imgClass--rounded"] { -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px;
}
img[title*="imgClass--shadow"] { -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.8); -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.8); box-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
}
img[title*="imgClass--gray"] { -webkit-filter: grayscale(1); filter: grayscale(1);
}
img[title*="imgClass--float-right"] { width: 50%; float: right; margin-left: .5em; margin-bottom: .5em;
}
Developer | Kevin Gimbel |
Username | kevingimbel |
Uploaded | August 11, 2022 |
Rating | 3 |
Size | 6,385 Kb |
Views | 30,360 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Custom Rating buttons with Icon Fonts | 5,022 Kb |
ViewSwitcher | 4,203 Kb |
Pure JavaScript Slider | 3,122 Kb |
Pure CSS3 single element Link from TLOZ | 5,118 Kb |
Slide Menu | 3,725 Kb |
Register or Sponsor Prototype | 3,183 Kb |
CSS3 only Turret from Portal | 3,910 Kb |
.LANG | 3,709 Kb |
An Object-Oriented ToDo-List | 5,275 Kb |
CSS3 only classic Gameboy | 6,134 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
A Pen by tugce | Ecgutcnkr | 4,197 Kb |
A Pen by Shidhin | Shidhincr | 5,015 Kb |
Brent Burns Tribute Page | Nevada48 | 2,569 Kb |
Starfield old school style | Bolloxim | 5,214 Kb |
Welcome | Nakome | 6,076 Kb |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
React Markdown Previewer | C0d0er | 3,190 Kb |
Sticky notes with CSS3 | HaiNguyen007 | 2,146 Kb |
Social Profiles | Lachlanjc | 1,939 Kb |
Midterm dry run | Jds317 | 1,649 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!