<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CSS]]></title><description><![CDATA[Styles of the Web]]></description><link>https://css.co.in</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 05:09:38 GMT</lastBuildDate><atom:link href="https://css.co.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[@supports API]]></title><description><![CDATA[In order to check if some CSS property is supported in a browser or not we can make use of the @supports API which itself is supported by all browsers except IE and Opera Mini (https://caniuse.com/css-supports-api) - so we’re good here.
So let take o...]]></description><link>https://css.co.in/supports-api</link><guid isPermaLink="true">https://css.co.in/supports-api</guid><category><![CDATA[masonry]]></category><category><![CDATA[CSS]]></category><category><![CDATA[grid]]></category><category><![CDATA[grid layout]]></category><category><![CDATA[@supports]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Fri, 23 Jan 2026 07:55:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769154680991/ffbafcd5-4b68-4f2d-8244-309e9b948fcd.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In order to check if some CSS property is supported in a browser or not we can make use of the @supports API which itself is supported by all browsers except IE and Opera Mini (<a target="_blank" href="https://caniuse.com/css-supports-api">https://caniuse.com/css-supports-api</a>) - so we’re good here.</p>
<p>So let take one good example of a CSS feature that many front-end developers have been waiting for.</p>
<p>It looks like <code>grid-template-rows: masonry;</code> may come to browsers this year. The latest Safari Technical Preview seems to have support for this though I couldn’t get it to work on my Safari Tech Preview on my macOS Sequoia 15.7.3 - not sure if masonry support is only for Tahoe’s version of Safari Tech Preview.</p>
<p>To check if your browser supports <code>grid-template-rows: masonry</code> we can use it in CSS like this :</p>
<pre><code class="lang-css"><span class="hljs-keyword">@supports</span> (<span class="hljs-attribute">grid-template-rows:</span> masonry)
{

}
</code></pre>
<p>We can place any CSS within the block and the good part is we can also apply CSS to browsers that don’t support <code>grid-template-rows: masonry</code> - by using the <code>not</code> keyword.</p>
<pre><code class="lang-css"><span class="hljs-keyword">@supports</span> <span class="hljs-keyword">not</span> (<span class="hljs-attribute">grid-template-rows:</span> masonry)
{

}
</code></pre>
<p>You can get Firefox to support <code>grid-template-rows: masonry</code> by enabling <strong>layout.css.grid-template-masonry-value.enabled</strong> to <em>true</em> in <strong>about:config</strong>.</p>
<p>Here’s the sample CSS code :</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>
{
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>fr);
    <span class="hljs-attribute">gap</span>: <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">grid-template-rows</span>: masonry;
}

<span class="hljs-selector-class">.container</span> &gt; <span class="hljs-selector-tag">div</span>
{      
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">1em</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f0f0f0</span>;
}

<span class="hljs-keyword">@supports</span> (<span class="hljs-attribute">grid-template-rows:</span> masonry)
{
    <span class="hljs-selector-class">.container</span> &gt; <span class="hljs-selector-tag">div</span>
    {
        <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid red;
    }
}

<span class="hljs-keyword">@supports</span> <span class="hljs-keyword">not</span> (<span class="hljs-attribute">grid-template-rows:</span> masonry)
{
    <span class="hljs-selector-class">.container</span> &gt; <span class="hljs-selector-tag">div</span>
    {
        <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid green;
    }  
}
</code></pre>
<p>And here’s the corresponding HTML:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Item 2.1<span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>Item 2.2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Item 3.1<span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>Item 3.2<span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>Item 3.3<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Item 4<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>This will show like this for no masonry support :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769154115109/ba5aa1cb-5ee1-4d85-8071-d1851ed3ac69.png" alt class="image--center mx-auto" /></p>
<p>And like this for browsers that do support masonry :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769154169613/224a2907-c599-4d50-b8ae-7b1695eac77b.png" alt class="image--center mx-auto" /></p>
<p>Notice the difference - for one: the colours are different - and most importantly, the layout is as per the height of the content of each item cell and not uniform.</p>
<p>Demo : <a target="_blank" href="https://anjanesh.s3.us-east-1.amazonaws.com/demo/supports.html">https://anjanesh.s3.us-east-1.amazonaws.com/demo/supports.html</a></p>
<p>Reference : <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Masonry_layout">https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Masonry_layout</a></p>
]]></content:encoded></item><item><title><![CDATA[Using the :has selector to display full with of a container]]></title><description><![CDATA[Finally, today I had a use-case for the :has selector which was first supported by Safari as reported by Jen Simmons.
I have this in my base.html :
<div id="main" class="grow mx-auto px-4">
    {% block content %}{% endblock %}
</div>

which has the ...]]></description><link>https://css.co.in/using-the-has-selector-to-display-full-with-of-a-container</link><guid isPermaLink="true">https://css.co.in/using-the-has-selector-to-display-full-with-of-a-container</guid><category><![CDATA[selectors]]></category><category><![CDATA[container]]></category><category><![CDATA[has ]]></category><category><![CDATA[CSS]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Sun, 26 Feb 2023 17:03:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1677430956465/7544d1eb-0c11-4ff4-be5c-4d3888bf4f06.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Finally, today I had a use-case for the <code>:has</code> selector which was first supported by Safari as <a target="_blank" href="https://twitter.com/jensimmons/status/1473051429115940868">reported by Jen Simmons</a>.</p>
<p>I have this in my base.html :</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"main"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grow mx-auto px-4"</span>&gt;</span>
    {% block content %}{% endblock %}
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>which has the container to the block content as <code>mx-auto</code> which translates to <code>margin-left: auto; margin-right: auto;</code> for all pages including the events page.</p>
<p>And this in events.html</p>
<pre><code class="lang-xml">{% extends 'base.html' %}
{% load static %}

{% block content %}

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"events-page"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"p-7 mt-5 w-full"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>            
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-4xl pb-4 mb-4 border-b border-gray-200"</span>&gt;</span>Events<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"px-4- sm:px-6- lg:px-8-"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sm:flex sm:items-center"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sm:flex-auto"</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-xl font-semibold text-gray-900"</span>&gt;</span>Events<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mt-2 text-sm text-gray-700"</span>&gt;</span>Event Calendar<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"-mx-4 overflow-hidden shadow ring-1 ring-black ring-opacity-5 p-5 sm:-mx-6 md:mx-0 md:rounded-lg w-full"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">iframe</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://calendar.google.com/calendar/embed?src=newsletter%40allcareerguru.com&amp;ctz=Asia%2FKolkata"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"border: 0"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"100%"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"800"</span> <span class="hljs-attr">frameborder</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">scrolling</span>=<span class="hljs-string">"no"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">iframe</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>    

{% endblock %}
</code></pre>
<p>Thing is, with the iframe <strong>not</strong> being 100% of the page is not exactly aesthetically pleasing. The iframe needs to be 100% of the container, and the container is not the full-width of the page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1677430609903/0bf15bf6-a1c7-4108-a51f-613d766a22bc.png" alt class="image--center mx-auto" /></p>
<p>So, I want the <code>main</code> DIV not to be <code>margin-left: auto; margin-right: auto;</code> and instead be <code>margin-left: 0; margin-right: 0;</code></p>
<p>So after <code>{% block content %}</code> all I added was :</p>
<pre><code class="lang-css">&lt;<span class="hljs-selector-tag">style</span> <span class="hljs-selector-tag">type</span>="<span class="hljs-selector-tag">text</span>/<span class="hljs-selector-tag">css</span>"&gt;
<span class="hljs-selector-id">#main</span><span class="hljs-selector-pseudo">:has(</span><span class="hljs-selector-id">#events-page</span>)
{
    <span class="hljs-attribute">margin-left</span>:<span class="hljs-number">0</span>;
    <span class="hljs-attribute">margin-right</span>:<span class="hljs-number">0</span>;
}
&lt;/<span class="hljs-selector-tag">style</span>&gt;
</code></pre>
<p>Now this makes only the event page's container (<strong>#main</strong>) to not have <code>margin-left: 0; margin-right: 0;</code> which overrides <code>mx-auto</code></p>
<p>FireFox is yet to support <code>:has</code> (<a target="_blank" href="https://caniuse.com/css-has">https://caniuse.com/css-has</a>) ! The browser I work on exclusively!</p>
]]></content:encoded></item><item><title><![CDATA[first-of-type]]></title><description><![CDATA[Let's say we wanted to target DOM Elements of a particular type inside a parent DOM container say a section.
<section class="plan">

    <div>
        Inner Content not in an inner enclosed DIV or DOM Element.
        <div>Inner Content 1 in 1st plan...]]></description><link>https://css.co.in/first-of-type</link><guid isPermaLink="true">https://css.co.in/first-of-type</guid><category><![CDATA[first-of-type]]></category><category><![CDATA[CSS]]></category><category><![CDATA[DOM]]></category><category><![CDATA[Element ]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Fri, 25 Nov 2022 08:40:25 GMT</pubDate><content:encoded><![CDATA[<p>Let's say we wanted to target DOM Elements of a particular type inside a parent DOM container say a <code>section</code>.</p>
<pre><code>&lt;section <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"plan"</span>&gt;

    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        Inner Content not in an inner enclosed DIV or DOM Element.
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Inner Content 1 in 1st plan DIV<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Inner Content 2 in 1st plan DIV<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>

    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 2 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 3 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 4 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 5 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>

&lt;/section&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 1 in Green<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 2 in Green<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre><p>If we do <code>section.plan div</code> it'll target all DIVs inside <code>section.plan</code>. So a <code>section.plan div { color: blue; }</code> will make text content in all DIVs in color blue.</p>
<p>But if we do <code>section.plan &gt; div</code> it'll target all only DIVs that are <strong>direct </strong> decendants of <code>section.plan</code> - all first level DIVs under <code>section.plan</code>. So <code>section.plan &gt; div { border: 1px solid red; }</code> will not have red borders for the DIVs with <strong>Inner Content 1/2 in 1st plan DIV</strong>.</p>
<p>But what about <code>section.plan &gt; div:first-child</code> ? This would select the DIV that's the first child of the parent <code>section.plan</code>. Here's the catch - if the first child of <code>section.plan</code> is a P like <code>&lt;p&gt;First child is not a DIV&lt;/p&gt;</code> then <code>section.plan &gt; div:first-child</code> will fail to do anything - since the first child of <code>section.plan</code> is not a DIV but a P tag. <code>section.plan &gt; div:first-child</code> does not mean select the first DIV that's the child of <code>section.plan</code> - it means that <em>if</em> the  first child is a DIV then apply the CSS. To catch the <strong>first</strong> DIV that's a child of <code>section.plan</code> we use <code>section.plan &gt; div:first-of-type</code></p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">HTML</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1, user-scalable=no"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>fist-of-type<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
<span class="hljs-selector-tag">section</span><span class="hljs-selector-class">.plan</span> <span class="hljs-selector-tag">div</span>
{
    <span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-selector-tag">section</span><span class="hljs-selector-class">.plan</span> &gt; <span class="hljs-selector-tag">div</span>
{
    <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid red;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
}

<span class="hljs-comment">/* Not used any where since first child of section class="plan" isn't a DIV but a P */</span>
<span class="hljs-selector-tag">section</span><span class="hljs-selector-class">.plan</span> &gt; <span class="hljs-selector-tag">div</span><span class="hljs-selector-pseudo">:first-child</span>
{
    <span class="hljs-attribute">background-color</span>: yellow;
}

<span class="hljs-selector-tag">section</span><span class="hljs-selector-class">.plan</span> &gt; <span class="hljs-selector-tag">div</span><span class="hljs-selector-pseudo">:last-child</span>
{
    <span class="hljs-attribute">background-color</span>: lightcyan;
}
<span class="hljs-selector-tag">section</span><span class="hljs-selector-class">.plan</span> &gt; <span class="hljs-selector-tag">div</span><span class="hljs-selector-pseudo">:first-of-type</span>
{
    <span class="hljs-attribute">border</span>:<span class="hljs-number">1px</span> dashed black;
}
<span class="hljs-selector-tag">section</span><span class="hljs-selector-class">.plan</span> ~ <span class="hljs-selector-tag">div</span>
{
    <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid green;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"plan"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>First child is not a DIV<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        Inner Content not in an inner enclosed DIV or DOM Element.
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Inner Content 1 in 1st plan DIV<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Inner Content 2 in 1st plan DIV<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 2 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 3 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 4 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 5 in Red<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 1 in Green<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content 2 in Green<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><a target="_blank" href="https://caniuse.com/?search=first-of-type">first-of-type is supported on all recent browsers, old and new ones</a>.</p>
<p>Demo : https://s3.amazonaws.com/s3.css.co.in/demo/first-of-type.html</p>
]]></content:encoded></item><item><title><![CDATA[Text Input Validation & Error without JavaScript]]></title><description><![CDATA[Vanilla CSS:
input.nameValidation + label::after
{
    content:  "Only alphabets and quotes allowed";
    color: orange;
}
input.nameValidation:focus:required:invalid:not(:placeholder-shown)
{
    border: 1px solid red;
    animation: shake 300ms;
}
...]]></description><link>https://css.co.in/text-input-validation-and-error-without-javascript</link><guid isPermaLink="true">https://css.co.in/text-input-validation-and-error-without-javascript</guid><category><![CDATA[Validation]]></category><category><![CDATA[pseudo elements]]></category><category><![CDATA[CSS]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Mon, 11 Jul 2022 18:40:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1657612346187/s80s-hpMD.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Vanilla CSS:</p>
<pre><code><span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span> + <span class="hljs-selector-tag">label</span><span class="hljs-selector-pseudo">::after</span>
{
    <span class="hljs-attribute">content</span>:  <span class="hljs-string">"Only alphabets and quotes allowed"</span>;
    <span class="hljs-attribute">color</span>: orange;
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:focus</span><span class="hljs-selector-pseudo">:required</span><span class="hljs-selector-pseudo">:invalid</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:placeholder-shown)</span>
{
    <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid red;
    <span class="hljs-attribute">animation</span>: shake <span class="hljs-number">300ms</span>;
}

<span class="hljs-comment">/* animation inspired by https://www.instagram.com/tv/CfvWUG3jgY */</span>
<span class="hljs-keyword">@keyframes</span> shake
{
    25% { <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(<span class="hljs-number">4px</span>); }
    50% { <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(-<span class="hljs-number">4px</span>); }
    75% { <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(<span class="hljs-number">4px</span>); }
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:invalid</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:placeholder-shown)</span> + <span class="hljs-selector-tag">label</span>
{
    <span class="hljs-attribute">display</span>: inline-block;    
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:invalid</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:placeholder-shown)</span> + <span class="hljs-selector-tag">label</span><span class="hljs-selector-pseudo">::after</span>
{
    <span class="hljs-attribute">content</span>: <span class="hljs-string">"Invalid Entry for a Full Name"</span>;
    <span class="hljs-attribute">color</span>: red;
}
</code></pre><p>HTML :</p>
<pre><code><span class="hljs-operator">&lt;</span>form<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span>div<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>input <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"text"</span> class<span class="hljs-operator">=</span><span class="hljs-string">"nameValidation"</span> required pattern<span class="hljs-operator">=</span><span class="hljs-string">"[a-zA-Z &amp;quot;&amp;apos;]*"</span> placeholder<span class="hljs-operator">=</span><span class="hljs-string">"Enter your Full Name"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>label<span class="hljs-operator">&gt;</span><span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>label<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span>button <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"submit"</span><span class="hljs-operator">&gt;</span>Submit<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>button<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>form<span class="hljs-operator">&gt;</span>
</code></pre><p>There's a pseudo CSS property called <code>:placeholder-shown</code> which can be used in CSS to fill in styles if the placeholder still there in the text input. If the placeholder still exists then it means that the value is empty.</p>
<p><code>not(:placeholder-shown)</code> states that the placeholder is not shown in the text input and a result means that it's not empty. The user has entered atleast one character in the text input.</p>
<p><code>input:invalid</code> gets invoked when the input text is <strong>invalid</strong> when on the <code>pattern</code> attribute fails to return the input validation as true.</p>
<p>So put together, <code>input.nameValidation:invalid:not(:placeholder-shown) + label::after</code> will show the label content with the style which is just after input text field when the input <em>pattern</em> triggers the user input as a invalid .</p>
<p>Using Bootstrap 5 for some nice looking default styles :</p>
<pre><code><span class="hljs-selector-class">.form-control</span><span class="hljs-selector-pseudo">:focus</span>
{
    <span class="hljs-attribute">box-shadow</span>: none;
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:focus</span>
{
    <span class="hljs-attribute">outline</span>:none;
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span> + <span class="hljs-selector-tag">label</span><span class="hljs-selector-pseudo">::after</span>
{
    <span class="hljs-attribute">content</span>:  <span class="hljs-string">"Only alphabets and quotes allowed"</span>;
    <span class="hljs-attribute">color</span>: orange;
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:focus</span><span class="hljs-selector-pseudo">:required</span><span class="hljs-selector-pseudo">:invalid</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:placeholder-shown)</span>
{
    <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid red;
    <span class="hljs-attribute">animation</span>: shake <span class="hljs-number">300ms</span>;
}

<span class="hljs-comment">/* animation inspired by https://www.instagram.com/tv/CfvWUG3jgY */</span>
<span class="hljs-keyword">@keyframes</span> shake
{
    25% { <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(<span class="hljs-number">4px</span>); }
    50% { <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(-<span class="hljs-number">4px</span>); }
    75% { <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(<span class="hljs-number">4px</span>); }
}
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:invalid</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:placeholder-shown)</span> + <span class="hljs-selector-tag">label</span>
{
    <span class="hljs-attribute">display</span>: inline-block;
    <span class="hljs-attribute">color</span>: red;
}
<span class="hljs-selector-tag">input</span><span class="hljs-selector-class">.nameValidation</span><span class="hljs-selector-pseudo">:invalid</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:placeholder-shown)</span> + <span class="hljs-selector-tag">label</span><span class="hljs-selector-pseudo">::after</span>
{
    <span class="hljs-attribute">content</span>: <span class="hljs-string">"Invalid Entry for a Full Name"</span>;
    <span class="hljs-attribute">color</span>: red;
}
</code></pre><p>HTML :</p>
<pre><code><span class="hljs-operator">&lt;</span>form<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span>div<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>input <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"text"</span> class<span class="hljs-operator">=</span><span class="hljs-string">"form-control nameValidation"</span> required pattern<span class="hljs-operator">=</span><span class="hljs-string">"[a-zA-Z &amp;quot;&amp;apos;]*"</span> placeholder<span class="hljs-operator">=</span><span class="hljs-string">"Enter your Full Name"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>label class<span class="hljs-operator">=</span><span class="hljs-string">"mt-1"</span><span class="hljs-operator">&gt;</span><span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>label<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span>button <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"submit"</span> class<span class="hljs-operator">=</span><span class="hljs-string">"btn btn-primary mt-2"</span><span class="hljs-operator">&gt;</span>Submit<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>button<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>form<span class="hljs-operator">&gt;</span>
</code></pre><p><strong>Demos :</strong><br />
Vanilla CSS - https://anjanesh.s3.amazonaws.com/demo/input-validation.html<br />
Bootstrap - https://anjanesh.s3.amazonaws.com/demo/input-validation-bs5.html</p>
]]></content:encoded></item><item><title><![CDATA[Mega Menu using CSS only]]></title><description><![CDATA[Demo : http://s3.css.co.in/demo/mega-menu.html
Code : https://gist.github.com/anjanesh/876b781b69fff9598fd73ffeda4b9318
Sorry for no explanation here.
#top-menu-1 > div > a + div:hover has to be displayed as block too.
For people who know CSS, I thin...]]></description><link>https://css.co.in/mega-menu-using-css-only</link><guid isPermaLink="true">https://css.co.in/mega-menu-using-css-only</guid><category><![CDATA[general]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Sat, 09 Jan 2021 12:51:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020058287/UbtEMZJII.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020056655/FkPjO7owj.png" alt /></p>
<p>Demo : <a target="_blank" href="http://s3.css.co.in/demo/mega-menu.html">http://s3.css.co.in/demo/mega-menu.html</a></p>
<p>Code : <a target="_blank" href="https://gist.github.com/anjanesh/876b781b69fff9598fd73ffeda4b9318">https://gist.github.com/anjanesh/876b781b69fff9598fd73ffeda4b9318</a></p>
<p>Sorry for no explanation here.</p>
<p><code>#top-menu-1 &gt; div &gt; a + div:hover</code> has to be displayed as block too.</p>
<p>For people who know CSS, I think most people just want to copy-paste code and edit for customization. And people who don’t know CSS will just edit the content.</p>
]]></content:encoded></item><item><title><![CDATA[Using ::marker to display content before content]]></title><description><![CDATA[Ever wanted a piece of content before the content ?
Well …. there is ::before which is what it is used for.
But there is another selector called ::marker which is used for displaying content before a list item.
It is possible to display a non-list it...]]></description><link>https://css.co.in/using-marker-to-display-content-before-content</link><guid isPermaLink="true">https://css.co.in/using-marker-to-display-content-before-content</guid><category><![CDATA[content]]></category><category><![CDATA[general]]></category><category><![CDATA[marker]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Sun, 01 Nov 2020 06:39:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020069582/YyUl0lnV2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ever wanted a piece of content before the content ?</p>
<p>Well …. there is <code>::before</code> which is what it is used for.</p>
<p>But there is another selector called <code>::marker</code> which is used for displaying content before a <em>list item</em>.</p>
<p>It <em>is</em> possible to display a non-list item as an item via <code>display: list-item;</code> to a div or p, so you don’t necessarily have to create a list like ul or ol.</p>
<p>According to <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/::marker">Mozilla</a>, <em>Only certain CSS properties can be used in a rule with ::marker as a selector</em> and one of them is <code>content</code> which can be used to insert custom content.</p>
<p>What is not possible is, to absolute position the content in the marker as it’s not supported till now. So for now, we have to do with the left alignment with the text.</p>
<p>&lt;!DOCTYPE html&gt;</p>




Marker





    <div id="div-marker"><br />        <p id="p-marker-1">Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsa, reprehenderit. Tenetur delectus repellendus eligendi fugit neque nulla adipisci tempora quam, error tempore repellat quibusdam esse officiis consequuntur vel nobis optio?</p>
        <p id="p-marker-2">Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsa, reprehenderit. Tenetur delectus repellendus eligendi fugit neque nulla adipisci tempora quam, error tempore repellat quibusdam esse officiis consequuntur vel nobis optio?</p>
    </div><br />



<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020067034/ECWckA9M3.png" alt /></p>
]]></content:encoded></item><item><title><![CDATA[Using the data URI scheme to reduce an HTTP request]]></title><description><![CDATA[Ever wanted to include a 1px wide/high background image that repeats (one way), to your existing sprite image just to reduce that one HTTP request, even though it may not have that great an impact on speed ?
Since the image repeats itself (repeat-x o...]]></description><link>https://css.co.in/using-the-data-uri-scheme-to-reduce-an-http-request</link><guid isPermaLink="true">https://css.co.in/using-the-data-uri-scheme-to-reduce-an-http-request</guid><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Sat, 01 Jan 2011 04:08:50 GMT</pubDate><content:encoded><![CDATA[<p>Ever wanted to include a 1px wide/high background image that repeats (one way), to your existing sprite image just to reduce that one HTTP request, even though it may not have that great an impact on speed ?</p>
<p>Since the image repeats itself (repeat-x <em>or</em> repeat-y, <em>not</em> both-ways), embedding it to a sprite is only useful if image’s width/height spans across the sprite image.<br />Using the <a target="_blank" href="http://en.wikipedia.org/wiki/Data_URI_scheme">data URI scheme</a>, its possible to embed an image into a <code>background-image</code> property directly. This is supported by almost all browsers except IE7 and below. (Use <a target="_blank" href="http://www.greywyvern.com/code/php/binary2base64">this</a> to convert an image to base64 format)</p>
<p>This is normally not a good solution because the base64 encoded string of the image is more (1/3 more) in bytes than the image file itself. But for small images that, say, act as a backrgound image for a navigation container, its a good trade-off for that additional HTTP request.<br />And for IE6 &amp; IE7, use the image itself.</p>
<p><strong>style.css</strong></p>
<pre><code><span class="hljs-selector-class">.nav</span>
{
    <span class="hljs-attribute">background-image</span>:<span class="hljs-built_in">url</span>(<span class="hljs-string">'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAiCAYAAACeLbMRAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oMHw4JJ8ytHAkAAAAhSURBVAjXY2DABYyMjP4zMTAwMFCJ+Pr1K4k6GBkZkbgApdoEsBPcDsAAAAAASUVORK5CYII%3D'</span>);
}
</code></pre><p><strong>HTML page</strong></p>
<pre><code><span class="hljs-operator">&lt;</span><span class="hljs-operator">!</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>[<span class="hljs-keyword">if</span> lt IE <span class="hljs-number">8</span>]<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>link rel<span class="hljs-operator">=</span><span class="hljs-string">"stylesheet"</span> <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"text/css"</span> href<span class="hljs-operator">=</span><span class="hljs-string">"ie67.css"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">!</span>[endif]<span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">&gt;</span>
</code></pre><p><strong>ie67.css</strong></p>
<pre><code><span class="hljs-selector-class">.nav</span>
{
    <span class="hljs-attribute">background-image</span>:<span class="hljs-built_in">url</span>(images/nav-bg.png);
}
</code></pre>]]></content:encoded></item><item><title><![CDATA[FireFox Specific CSS]]></title><description><![CDATA[Though the chances of wanting this is pretty slim, but if you want to target a set of CSS attributes just for FireFox instead of using JavaScript to alter the styles, its possible.Though most -moz- properties get deprecated & later removed, when the ...]]></description><link>https://css.co.in/firefox-specific-css</link><guid isPermaLink="true">https://css.co.in/firefox-specific-css</guid><category><![CDATA[Firefox]]></category><category><![CDATA[general]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Sat, 04 Dec 2010 08:08:17 GMT</pubDate><content:encoded><![CDATA[<p>Though the chances of wanting this is pretty slim, but if you want to target a set of CSS attributes just for FireFox instead of using JavaScript to alter the styles, its possible.<br />Though most <em>-moz-</em> properties get deprecated &amp; later removed, when the official CSS3 one is implemented, the <a target="_blank" href="https://developer.mozilla.org/en/CSS/@-moz-document">@-moz-document</a> is Mozilla/Gecko-only specific which is used to contain different styles rules based on filtering document URLs.</p>
<pre><code><span class="hljs-operator">&lt;</span><span class="hljs-operator">!</span>DOCTYPE html<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>html lang<span class="hljs-operator">=</span><span class="hljs-string">"en"</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>head<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>meta charset<span class="hljs-operator">=</span><span class="hljs-string">"utf-8"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>meta http<span class="hljs-operator">-</span>equiv<span class="hljs-operator">=</span><span class="hljs-string">"Content-Type"</span> content<span class="hljs-operator">=</span><span class="hljs-string">"text/html;charset=utf-8"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>title<span class="hljs-operator">&gt;</span>FireFox Specific CSS<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>title<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>style <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"text/css"</span><span class="hljs-operator">&gt;</span>
h1
{
    color:red;
}
h2
{
    color:green;
}
@<span class="hljs-operator">-</span>moz<span class="hljs-operator">-</span>document url<span class="hljs-operator">-</span>prefix()
{
    h1
    {
        color:blue;
    }
    h2
    {
        color:black;
    }
}
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>style<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>head<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>body<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>h1<span class="hljs-operator">&gt;</span>Hello<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h1<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>h2<span class="hljs-operator">&gt;</span>World<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h2<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>body<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>html<span class="hljs-operator">&gt;</span>
</code></pre><p>Example : <a target="_blank" href="http://css.co.in/examples/firefox-specific-css.html">Mozilla Extensions</a></p>
<h4 id="heading-related-links">Related Links :</h4>
<ul>
<li><a target="_blank" href="https://developer.mozilla.org/en/CSS_Reference/Mozilla_Extensions">Mozilla Extensions</a></li>
<li><a target="_blank" href="http://stackoverflow.com/questions/952861/targeting-only-firefox-with-css">Targeting only FireFox with CSS</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Adjusting styles based on a language]]></title><description><![CDATA[Traditionally, language HTML files would be stored separately and load language specific CSS files.But now we just store the language strings separately and programmatically print the language strings within the same HTML file.Very often I find mysel...]]></description><link>https://css.co.in/adjusting-styles-based-on-a-language</link><guid isPermaLink="true">https://css.co.in/adjusting-styles-based-on-a-language</guid><category><![CDATA[HTML]]></category><category><![CDATA[language]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Fri, 26 Nov 2010 16:40:14 GMT</pubDate><content:encoded><![CDATA[<p>Traditionally, language HTML files would be stored separately and load language specific CSS files.<br />But now we just store the language <em>strings</em> separately and programmatically print the language strings within the same HTML file.<br />Very often I find myself adjusting the style attributes a little here and there for different languages just so that it fits nicely inside a container or a navigation bar and looks the same across all languages.<br />Its actually easy to set style attributes based on the language attribute, <strong>lang</strong> in the HTML element.</p>
<pre><code><span class="hljs-operator">&lt;</span><span class="hljs-operator">!</span>DOCTYPE html<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>html lang<span class="hljs-operator">=</span><span class="hljs-string">"fr"</span> dir<span class="hljs-operator">=</span><span class="hljs-string">"ltr"</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>head<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>meta charset<span class="hljs-operator">=</span><span class="hljs-string">"utf-8"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>meta http<span class="hljs-operator">-</span>equiv<span class="hljs-operator">=</span><span class="hljs-string">"Content-Type"</span> content<span class="hljs-operator">=</span><span class="hljs-string">"text/html;charset=utf-8"</span> <span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>style <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"text/css"</span><span class="hljs-operator">&gt;</span>
html[lang<span class="hljs-operator">=</span><span class="hljs-string">"en"</span>] h2
{
    color:black;
}

html[lang<span class="hljs-operator">=</span><span class="hljs-string">"hi"</span>] h2
{
    color:red;
}
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>style<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>head<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>body<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>h2<span class="hljs-operator">&gt;</span>The quick brown fox jumps over the lazy dog<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h2<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>body<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>html<span class="hljs-operator">&gt;</span>
</code></pre><p><a target="_blank" href="http://css.co.in/examples/language-fonts.html">This Example</a> doesn’t change the text colour using JavaScript. JavaScript was used to change the <strong>lang</strong> attribute value in the <strong>html</strong> element.</p>
]]></content:encoded></item><item><title><![CDATA[CSS only Tabs using :target]]></title><description><![CDATA[Its highly unlikely that tabs using only CSS would replace JavaScript based ones.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>CSS Tabs</title>
<style type...]]></description><link>https://css.co.in/css-only-tabs-using-target</link><guid isPermaLink="true">https://css.co.in/css-only-tabs-using-target</guid><category><![CDATA[CSS3]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Fri, 15 Oct 2010 12:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020100652/qxZoy0axb.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Its highly unlikely that tabs using <em>only</em> CSS would replace JavaScript based ones.<br /><a target="_blank" href="http://css.co.in/examples/css-tabs.html#item-1"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020098942/iS2Xhc8d-.png" alt="tabs" /></a></p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=utf-8"</span> &gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>CSS Tabs<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
<span class="hljs-selector-class">.css-tabs</span>
{
    <span class="hljs-attribute">position</span>:relative;
    <span class="hljs-attribute">text-align</span>:center; <span class="hljs-comment">/* This is only if you want the tab items at the center */</span>
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span>
{
    <span class="hljs-attribute">list-style-type</span>:none;
    <span class="hljs-attribute">display</span>:inline-block; <span class="hljs-comment">/* Change this to block or inline for non-center alignment */</span>
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> &gt; <span class="hljs-selector-tag">li</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">float</span>:left;
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> <span class="hljs-selector-tag">li</span> &gt; <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">color</span>:<span class="hljs-number">#000</span>;
    <span class="hljs-attribute">text-decoration</span>:none;
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">text-align</span>:center;
    <span class="hljs-attribute">border</span>:<span class="hljs-number">1px</span> solid <span class="hljs-number">#808080</span>;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span> <span class="hljs-number">10px</span> <span class="hljs-number">5px</span> <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">margin-right</span>:<span class="hljs-number">5px</span>;
    <span class="hljs-attribute">border-top-left-radius</span>:<span class="hljs-number">5px</span>; <span class="hljs-attribute">-moz-border-radius-topleft</span>:<span class="hljs-number">4px</span>; <span class="hljs-attribute">-webkit-border-top-left-radius</span>:<span class="hljs-number">5px</span>;
    <span class="hljs-attribute">border-top-right-radius</span>:<span class="hljs-number">5px</span>; <span class="hljs-attribute">-moz-border-radius-topright</span>:<span class="hljs-number">4px</span>; <span class="hljs-attribute">-webkit-border-top-right-radius</span>:<span class="hljs-number">5px</span>;
    <span class="hljs-attribute">-moz-user-select</span>:none;
    <span class="hljs-attribute">cursor</span>:pointer;
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> <span class="hljs-selector-tag">li</span> &gt; <span class="hljs-selector-tag">div</span>
{
    <span class="hljs-attribute">display</span>:none;
    <span class="hljs-attribute">position</span>:absolute;
    <span class="hljs-attribute">width</span>:<span class="hljs-number">100%</span>;
    <span class="hljs-attribute">left</span>:<span class="hljs-number">0</span>;
    <span class="hljs-attribute">margin</span>:-<span class="hljs-number">1px</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">z-index</span>:-<span class="hljs-number">1</span>;
    <span class="hljs-attribute">text-align</span>:left;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>;
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> <span class="hljs-selector-tag">li</span> &gt; <span class="hljs-selector-tag">div</span> &gt; <span class="hljs-selector-tag">p</span>
{
    <span class="hljs-attribute">border</span>:<span class="hljs-number">1px</span> solid <span class="hljs-number">#808080</span>;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span>;
    <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>;
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> <span class="hljs-selector-tag">li</span> &gt; <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:focus</span>
{
    <span class="hljs-attribute">border-bottom</span>:<span class="hljs-number">1px</span> solid <span class="hljs-number">#fff</span>;
}
<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:target</span> &gt; <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">cursor</span>:default;
    <span class="hljs-attribute">border-bottom</span>:<span class="hljs-number">1px</span> solid <span class="hljs-number">#fff</span>;
}

<span class="hljs-selector-class">.css-tabs</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-class">.menu</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:target</span> &gt; <span class="hljs-selector-tag">div</span>
{
    <span class="hljs-attribute">display</span>:block;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tab2"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"css-tabs"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"item-1"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#item-1"</span>&gt;</span>Tab 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Tab Content 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"item-2"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#item-2"</span>&gt;</span>Tab 2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Tab Content 2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"item-3"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#item-3"</span>&gt;</span>Tab 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Tab Content 3<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"item-4"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"click for Tab 4"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#item-4"</span>&gt;</span>Tab 4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Tab Content 4<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>I think its safe to say that its a real annoyance when the browser re-positions the page when a fragment (named anchor) link is clicked. We don’t want the page moving up on clicking on a tab button. <a target="_blank" href="http://css.co.in/examples/css-tabs.html#item-1">Example</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Preventing Images From Being Saved on Right-Click]]></title><description><![CDATA[More often than not, people have asked that if they uploaded their profile picture online, would it be possible to disable downloading of their profile photo by others.
There is no full-proof method of preventing images from being saved by the end us...]]></description><link>https://css.co.in/preventing-images-from-being-saved-on-right-click</link><guid isPermaLink="true">https://css.co.in/preventing-images-from-being-saved-on-right-click</guid><category><![CDATA[images]]></category><category><![CDATA[general]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Fri, 08 Oct 2010 01:09:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020109956/meIEwSWeG.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>More often than not, people have asked that if they uploaded their profile picture online, would it be possible to disable downloading of their profile photo by others.</p>
<p>There is no full-proof method of preventing images from being saved by the end user.<br />The user can hit print-screen and crop the image out of the screenshot, or can directly download the image by knowing the exact image URL from the page’s source code (HTML, CSS JavaScript) or using tools like FireBug, AdBlockPlus to extract the image URL.</p>
<p>Whats mentioned here is a simple common technique to prevent someone from saving the actual image by right-clicking on it &amp; <em>Save As</em> or <em>Get Image Location</em>.</p>
<ul>
<li>Set the image’s <strong>src</strong> attribute to a 1 pixel transparent gif</li>
<li><p>Set the image’s backgound-image property to the actual image you want it to show</p>
<p><img src="1x1.gif" alt="cat" /></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020108490/LxR5doOgr.jpeg" alt="no save" /></p>
]]></content:encoded></item><item><title><![CDATA[All Star Attributes for HTML5 elements in IE]]></title><description><![CDATA[It is very common to set margin:0 and padding:0 as default to all HTML elements via the star hack.
* { margin:0; padding:0; }
And we get so used to explicitly setting margins and paddings to elements that require them, that we assume no padding & mar...]]></description><link>https://css.co.in/all-star-attributes-for-html5-elements-in-ie</link><guid isPermaLink="true">https://css.co.in/all-star-attributes-for-html5-elements-in-ie</guid><category><![CDATA[general]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Tue, 28 Sep 2010 13:07:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020122864/-tJn8GPeC.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>It is very common to set <code>margin:0</code> and <code>padding:0</code> as default to all HTML elements via the <a target="_blank" href="http://css-tricks.com/margin-0-padding-0-no-longer-cool/">star hack</a>.</p>
<pre><code>* { <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
</code></pre><p>And we get so used to explicitly setting margins and paddings to elements that require them, that we assume no padding &amp; margins at all as default for all elements.</p>
<p>With <a target="_blank" href="http://html5shiv.googlecode.com">html5shiv</a> javascript, we can get most HTML5 functionality working in Internet Explorer (6,7,8). And with <a target="_blank" href="http://ie7-js.googlecode.com">ie7-js</a>, we can get IE (6,7,8) to behave more-or-less like IE9.<br />When using HTML5 elements such as <code>header</code>, <code>section</code>, <code>footer</code>, <code>aside</code>, <code>nav</code>, <code>article</code> &amp; <code>figure</code>, the all star hack doesn’t work and hence we need to set them explicitly. (Looks like ie7-js is resetting the margins)</p>
<p><strong>IE6 / IE7</strong> :<br /><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020118428/lc0L3Thws.jpeg" alt="Screenshot in IE6 / IE7" /></p>
<p><strong>IE8</strong> :<br /><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020120444/AYWaY15Ie.jpeg" alt="Screenshot in IE8" /></p>
<p><code>margin:0</code> isn’t applied in IE 6/7/8. So don’t forget to set it explicitly for HTML5 elements.</p>
<pre><code><span class="hljs-selector-tag">header</span>, <span class="hljs-selector-tag">section</span>, <span class="hljs-selector-tag">footer</span>, <span class="hljs-selector-tag">aside</span>, <span class="hljs-selector-tag">nav</span>, <span class="hljs-selector-tag">article</span>, <span class="hljs-selector-tag">figure</span> { <span class="hljs-attribute">display</span>:block; <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
</code></pre>]]></content:encoded></item><item><title><![CDATA[Centering Lists]]></title><description><![CDATA[One of the most common techniques for creating a menu or some sort of a navigational bar is by using a list. A list is well-structured, uses fewer elements to parse than a table (buzzword tableless) and can always fall back to normal HTML when CSS or...]]></description><link>https://css.co.in/centering-lists</link><guid isPermaLink="true">https://css.co.in/centering-lists</guid><category><![CDATA[general]]></category><category><![CDATA[list]]></category><category><![CDATA[inline]]></category><category><![CDATA[nav]]></category><dc:creator><![CDATA[Anjanesh Lekshminarayanan]]></dc:creator><pubDate>Tue, 18 May 2010 10:19:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020138201/5aP8wCHM4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>One of the most common techniques for creating a menu or some sort of a navigational bar is by using a <a target="_blank" href="http://www.w3.org/TR/html401/struct/lists.html"><code>list</code></a>. A <code>list</code> is well-structured, uses fewer elements to parse than a table (buzzword <em>tableless</em>) and can always fall back to normal HTML when CSS or JavaScript is used to manipulate it for effects. (i.e, degrade gracefully)</p>
<p>This is probably the easiest way to center.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020132692/PlSS22VVi.png" alt /></p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=utf-8"</span> &gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Centering Lists<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
* { <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
<span class="hljs-selector-id">#nav</span>
{
    <span class="hljs-attribute">text-align</span>:center; <span class="hljs-comment">/* Not meant for centering a block element */</span>
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">background-color</span>:lightblue;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span>
{
    <span class="hljs-attribute">display</span>:inline;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span> <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:green;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span>
{
    <span class="hljs-attribute">display</span>:inline;
    <span class="hljs-attribute">background-color</span>:yellow;
    <span class="hljs-attribute">margin-right</span>:<span class="hljs-number">5px</span>;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">display</span>:inline;
    <span class="hljs-attribute">text-decoration</span>:none;
    <span class="hljs-attribute">color</span>:black;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span> <span class="hljs-number">5px</span>;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>
{
    <span class="hljs-attribute">background-color</span>:red;
    <span class="hljs-attribute">color</span>:white;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nav"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"first"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"last"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 5<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>But this has some drawbacks.</p>
<ul>
<li><h3 id="heading-text-align">text-align</h3>
<p>is meant for aligning text, not block elements, but this works for centering <em>inline</em> blocks on all browsers. But now, all text nodes within all child blocks inherits this text-align alignment property.</p>
</li>
<li><h3 id="heading-height">height</h3>
<p>Because the list and list items are inline, there is no room for adusting or specifying the height of the menu items. height, padding-top, padding-bottom won’t have any effect.</p>
</li>
</ul>
<p>A workaround for <em>inline</em> is by treating the list as a table and the list items as <code>table-cells</code>. But Internet Explorer supports <code>display:table</code> and <code>display:table-cell</code> only from version 8 onwards. So this is a no no solution for IE 6 &amp; IE 7. See <a target="_blank" href="http://www.quirksmode.org/css/display.html">the display declaration</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020134328/KHH6a9-yq3.png" alt /></p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=utf-8"</span> &gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Centering Lists<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
* { <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
<span class="hljs-selector-id">#nav</span>
{
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">background-color</span>:lightblue;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span>
{
    <span class="hljs-attribute">display</span>:table;
    <span class="hljs-attribute">margin-left</span>:auto;
    <span class="hljs-attribute">margin-right</span>:auto;
    <span class="hljs-attribute">background-color</span>:green;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span>
{
    <span class="hljs-attribute">display</span>:table-cell;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:green;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-class">.last</span>
{
    <span class="hljs-attribute">padding-right</span>:<span class="hljs-number">5px</span>;
}

<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">text-decoration</span>:none;
    <span class="hljs-attribute">color</span>:black;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:yellow;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>
{
    <span class="hljs-attribute">background-color</span>:red;
    <span class="hljs-attribute">color</span>:white;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nav"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"first"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"last"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu 5<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>A better option would be float the elements and specify exact widths. This works nicely when you know the exact content and can specify the width of each element.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020135555/VEKxYY3jK.png" alt /></p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=utf-8"</span> &gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Centering Lists<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
* { <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
<span class="hljs-selector-id">#nav</span>
{
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">background-color</span>:lightblue;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span> <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">width</span>:<span class="hljs-number">370px</span>; <span class="hljs-comment">/* 30x4 (width of a) + 125 (width of Menu Item 3) + 5x5 (margin right) + 5x10x2 (padding left &amp; right for a) */</span>
    <span class="hljs-attribute">height</span>:<span class="hljs-number">30px</span>;
    <span class="hljs-attribute">margin-left</span>:auto;
    <span class="hljs-attribute">margin-right</span>:auto;
    <span class="hljs-attribute">background-color</span>:green;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">float</span>:left;
    <span class="hljs-attribute">margin-right</span>:<span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:yellow;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">min-width</span>:<span class="hljs-number">30px</span>;
    <span class="hljs-attribute">width</span>:<span class="hljs-number">30px</span>;
    <span class="hljs-attribute">line-height</span>:<span class="hljs-number">30px</span>; <span class="hljs-comment">/* Align vertically in the middle */</span>
    <span class="hljs-attribute">text-align</span>:center;
    <span class="hljs-attribute">text-decoration</span>:none;
    <span class="hljs-attribute">color</span>:black;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>
{
    <span class="hljs-attribute">background-color</span>:red;
    <span class="hljs-attribute">color</span>:white;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-comment">&lt;!--[if lte IE 7]&gt;
&lt;style type="text/css"&gt;
#nav ul li.last
{
    margin-right:0;
}
&lt;/style&gt;
&lt;![endif]--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nav"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"first"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"width:125px;"</span>&gt;</span>Menu Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"last"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>5<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>For a fully floating list with centering, applying <code>display:inline-block</code> to the list is enough to achieve the desired result. But according to Quirksmode, <code>inline-block</code> is incomplete in IE6 and IE7. I don’t know how incomplete works, but it wierdly seems to work in IE6 when added in <a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx">IE conditional statements</a>.</p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
<span class="hljs-selector-id">#nav-container</span> <span class="hljs-selector-tag">ul</span>
{
    <span class="hljs-attribute">display</span>:inline-block;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-comment">&lt;!--[if lte IE 7]&gt;
&lt;style type="text/css"&gt;
#nav-container ul
{
    display:inline; /* For some reason now this works as inline-block in IE6 ?!? */
}
&lt;/style&gt;
&lt;![endif]--&gt;</span>
</code></pre><p>Full HTML :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1653020136855/i8eOj0dpa.png" alt /></p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=utf-8"</span> &gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Centering Lists<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
* { <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
<span class="hljs-selector-id">#nav</span>
{
    <span class="hljs-attribute">text-align</span>:center;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">background-color</span>:lightblue;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span>
{
    <span class="hljs-attribute">display</span>:inline-block;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span> <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:green;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">float</span>:left;
    <span class="hljs-attribute">background-color</span>:yellow;
    <span class="hljs-attribute">margin-right</span>:<span class="hljs-number">5px</span>;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">min-width</span>:<span class="hljs-number">30px</span>; <span class="hljs-comment">/* Wont work in IE6 */</span>
    <span class="hljs-attribute">line-height</span>:<span class="hljs-number">30px</span>; <span class="hljs-comment">/* Align vertically in the middle */</span>
    <span class="hljs-attribute">text-decoration</span>:none;
    <span class="hljs-attribute">text-align</span>:center;
    <span class="hljs-attribute">color</span>:black;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>
{
    <span class="hljs-attribute">background-color</span>:red;
    <span class="hljs-attribute">color</span>:white;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-comment">&lt;!--[if lte IE 7]&gt;
&lt;style type="text/css"&gt;
#nav ul
{
    display:inline; /* For some reason now this works as inline-block in IE6 ?!? */
}
#nav ul li.last
{
    margin-right:3px;
}
&lt;/style&gt;
&lt;![endif]--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nav"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"first"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"last"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>5<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>And using HTML5’s <code>nav</code> element :</p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=utf-8"</span> &gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Centering Lists<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-comment">&lt;!--[if lt IE 9]&gt;
&lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
&lt;script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"&gt;&lt;/script&gt;
&lt;![endif]--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>&gt;</span><span class="css">
* { <span class="hljs-attribute">margin</span>:<span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span>; }
<span class="hljs-selector-tag">header</span>, <span class="hljs-selector-tag">section</span>, <span class="hljs-selector-tag">footer</span>, <span class="hljs-selector-tag">aside</span>, <span class="hljs-selector-tag">nav</span>, <span class="hljs-selector-tag">article</span>, <span class="hljs-selector-tag">figure</span> { <span class="hljs-attribute">display</span>:block; }
<span class="hljs-selector-id">#nav</span>
{
    <span class="hljs-attribute">margin-top</span>:<span class="hljs-number">0</span>; <span class="hljs-comment">/* ie7-js's IE9.js seems to add a margin-top */</span>
    <span class="hljs-attribute">text-align</span>:center;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
    <span class="hljs-attribute">background-color</span>:lightblue;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span>
{
    <span class="hljs-attribute">display</span>:inline-block;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span> <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:green;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span>
{
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">float</span>:left;
    <span class="hljs-attribute">margin-right</span>:<span class="hljs-number">5px</span>;
    <span class="hljs-attribute">background-color</span>:yellow;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span>
{
    <span class="hljs-attribute">float</span>:left; <span class="hljs-comment">/* Required for IE6 */</span>
    <span class="hljs-attribute">display</span>:block;
    <span class="hljs-attribute">min-width</span>:<span class="hljs-number">30px</span>;
    <span class="hljs-attribute">line-height</span>:<span class="hljs-number">30px</span>; <span class="hljs-comment">/* Align vertically in the middle */</span>
    <span class="hljs-attribute">text-decoration</span>:none;
    <span class="hljs-attribute">text-align</span>:center;
    <span class="hljs-attribute">color</span>:black;
    <span class="hljs-attribute">padding</span>:<span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-id">#nav</span> <span class="hljs-selector-tag">ul</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>
{
    <span class="hljs-attribute">background-color</span>:red;
    <span class="hljs-attribute">color</span>:white;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-comment">&lt;!--[if lte IE 7]&gt;
&lt;style type="text/css"&gt;
#nav ul
{
    display:inline; /* For some reason this works in IE6 ?!? */
}
#nav ul li.last
{
    margin-right:3px;
}
&lt;/style&gt;
&lt;![endif]--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nav"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"first"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Menu Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"last"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>5<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>]]></content:encoded></item></channel></rss>