<?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 Insiders]]></title><description><![CDATA[CSS Insiders]]></description><link>https://cssinsiders.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 16:17:06 GMT</lastBuildDate><atom:link href="https://cssinsiders.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[CSS Position Property]]></title><description><![CDATA[Normally all the HTML elements follow a default order. To manipulate the position of HTML elements inside the view-port, we can use the CSS position property.
CSS Position property defines how an HTML element is positioned inside the browser's view-p...]]></description><link>https://cssinsiders.hashnode.dev/css-position-property</link><guid isPermaLink="true">https://cssinsiders.hashnode.dev/css-position-property</guid><category><![CDATA[CSS]]></category><category><![CDATA[CSS3]]></category><category><![CDATA[position]]></category><category><![CDATA[css position ]]></category><category><![CDATA[position absolute]]></category><dc:creator><![CDATA[Dhananjay Kumar]]></dc:creator><pubDate>Tue, 14 Jun 2022 17:09:13 GMT</pubDate><content:encoded><![CDATA[<p>Normally all the HTML elements follow a default order. To manipulate the position of HTML elements inside the view-port, we can use the <strong>CSS position property</strong>.</p>
<p>CSS <code>Position</code> property defines how an HTML element is positioned inside the browser's view-port. We use <code>top</code>, <code>right</code>, <code>bottom</code> and <code>left</code> properties to determine the final position of the element.</p>
<p>This can be used to place an element behind another with <code>z-index</code> property and also useful for <em>scripted animation</em> effect.</p>
<h4 id="heading-position-property-can-take-five-values-are-listed-below">Position property can take five values are listed below :</h4>
<ol>
<li>static</li>
<li>relative</li>
<li>absolute</li>
<li>fixed</li>
<li>sticky</li>
</ol>
<h3 id="heading-1-static">1. static</h3>
<p><code>position: static</code> is the default property for any element. Left, right, top, bottom and z-index properties <em>do not affect</em> a <code>static</code> positioned element. Element remained positioned according to the normal flow of the document.</p>
<h4 id="heading-html">HTML</h4>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent-element"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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">"positioned-element"</span>&gt;</span>
      I am the main <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>positioned static<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> element.
    <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">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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>
<h4 id="heading-css">CSS</h4>
<pre><code class="lang-css"><span class="hljs-selector-class">.positioned-element</span> {
    <span class="hljs-attribute">position</span>: static;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">16px</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">16px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#104a65</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffffff</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-class">.simple-element</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ddd</span>;
}
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/erdhananjay7/pen/GRQPbXR">https://codepen.io/erdhananjay7/pen/GRQPbXR</a></div>
<p>Here notice the <code>left</code> and <code>top</code> values have no effect on positioned sticky element</p>
<h3 id="heading-2-relative">2. relative</h3>
<p>Elements having <code>position: relative</code> will remain in it's normal flow of the web page. But, here the left, right, top, bottom and z-index properties affect the position of the element.</p>
<p>Let's replace <code>position: static</code> with <code>position: relative</code> in above example.</p>
<h4 id="heading-html">HTML</h4>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent-element"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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">"positioned-element"</span>&gt;</span>
      I am the main <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>positioned relative<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> element.
    <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">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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>
<h4 id="heading-css">CSS</h4>
<pre><code class="lang-css"><span class="hljs-selector-class">.positioned-element</span> {
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">16px</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">16px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#104a65</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffffff</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-class">.simple-element</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ddd</span>;
}
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/erdhananjay7/pen/GRQzKew">https://codepen.io/erdhananjay7/pen/GRQzKew</a></div>
<p>Here notice that the <code>left</code> and <code>top</code> properties now affect the position of the element. Also the element remains in the normal flow of the document and the offset is applied relative to itself.</p>
<h3 id="heading-3-absolute">3. absolute</h3>
<p>Element having <code>position: absolute</code> is positioned relative to its closest positioned parent if any. Otherwise it will be placed relative to the next parent positioned element and it's final position is defined by the <code>top</code>, <code>right</code>, <code>bottom</code>, and <code>left</code> value provided to it.</p>
<blockquote>
<p>If there's no positioned parent element, it is positioned relative to the <code>&lt;html&gt;</code> (e.g. root) element.</p>
</blockquote>
<p>The element is removed from the normal document flow in this case. The other elements will behave as if that element is not in the document. No space is there for the positioned absolute element in the page layout.</p>
<p>Let's check our example, we change the value of position to <code>absolute</code> from <code>relative</code>. Also we will give relative position to it's parent element so that it's position not get relative to the <code>&lt;html&gt;</code> element.</p>
<h4 id="heading-html">HTML</h4>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent-element"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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">"positioned-element"</span>&gt;</span>
      I am the main <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>positioned absolute<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> element.
    <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">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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>
<h4 id="heading-css">CSS</h4>
<pre><code class="lang-css"><span class="hljs-selector-class">.parent-element</span> {
    <span class="hljs-attribute">position</span>: relative;
}
<span class="hljs-selector-class">.positioned-element</span> {
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#104a65</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffffff</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-class">.simple-element</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ddd</span>;
}
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/erdhananjay7/pen/zYReYEp">https://codepen.io/erdhananjay7/pen/zYReYEp</a></div>
<p>Here notice that no space was created in the document for the positioned absolute element. Element is now positioned relative to the parent element.</p>
<h3 id="heading-4-fixed">4. fixed</h3>
<p>Elements having <code>position: fixed</code> are somewhat similar to positioned absolute elements. They also don't take space in the document and removed from the page layout. But they always get positioned with relative to the <code>&lt;html&gt;</code> element (i.e.) the root of the document.</p>
<blockquote>
<p>They always stay in same position on the screen while scrolling.</p>
</blockquote>
<p>Final position of the element is determined by the values of <code>top</code>, <code>right</code>, <code>bottom</code>, and <code>left</code>.</p>
<p>In our example let's change the value of position to fixed from absolute.</p>
<h4 id="heading-html">HTML</h4>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent-element"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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">"positioned-element"</span>&gt;</span>
      I am the main <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>positioned fixed<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> element.
    <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">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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>
<h4 id="heading-css">CSS</h4>
<pre><code class="lang-css"><span class="hljs-selector-class">.parent-element</span> {
    <span class="hljs-attribute">position</span>: relative;
}
<span class="hljs-selector-class">.positioned-element</span> {
    <span class="hljs-attribute">position</span>: fixed;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#104a65</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffffff</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-class">.simple-element</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ddd</span>;
}
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/erdhananjay7/pen/yLvZNVd">https://codepen.io/erdhananjay7/pen/yLvZNVd</a></div>
<h3 id="heading-4-sticky">4. sticky</h3>
<p><code>sticky</code> positioned elements are positioned according to the normal flow of the document, and then offset (based on the values of <code>top</code>, <code>right</code>, <code>bottom</code>, and <code>left</code>) relative to its nearest scrolling container/parent and containing block (block-level container). </p>
<blockquote>
<p>Until a certain scroll point it acts like a relatively positioned element and then it acts like a fixed element.</p>
</blockquote>
<h4 id="heading-html">HTML</h4>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent-element"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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">"positioned-element"</span>&gt;</span>
      I am the main <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>positioned sticky<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> element.
    <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">"simple-element"</span>&gt;</span>
      Lorem Ipsum is simply dummy text
    <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>
<h4 id="heading-css">CSS</h4>
<pre><code class="lang-css"><span class="hljs-selector-class">.parent-element</span> {
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">850px</span>;
}
<span class="hljs-selector-class">.positioned-element</span> {
    <span class="hljs-attribute">position</span>: sticky;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">30px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#104a65</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffffff</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
}
<span class="hljs-selector-class">.simple-element</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ddd</span>;
}
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/erdhananjay7/pen/ZErwbXy">https://codepen.io/erdhananjay7/pen/ZErwbXy</a></div>
<h3 id="heading-use-of-z-index-property">Use of z-index property</h3>
<p>HTML elements having higher value of <code>z-index</code> will overlap the element with a lower <code>z-index</code> value. This property only works on the positioned elements (relative, absolute, fixed and static). It doesn't affect the elements with <code>position: static</code>.</p>
<blockquote>
<p>The value of <code>z-index</code> can be set with an integer value. </p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Truncating text vertically at specific line number]]></title><description><![CDATA[While creating a card with small info which redirects to the detail somewhere else, we sometimes need to limit our information text to specific line let's say 3 or 4 and truncate the rest content vertically.
Here -webkit-line-clamp comes into the rol...]]></description><link>https://cssinsiders.hashnode.dev/truncating-text-vertically</link><guid isPermaLink="true">https://cssinsiders.hashnode.dev/truncating-text-vertically</guid><dc:creator><![CDATA[Dhananjay Kumar]]></dc:creator><pubDate>Sun, 22 May 2022 16:29:45 GMT</pubDate><content:encoded><![CDATA[<p>While creating a card with small info which redirects to the detail somewhere else, we sometimes need to limit our information text to specific line let's say 3 or 4 and truncate the rest content vertically.</p>
<p>Here <code>-webkit-line-clamp</code> comes into the role.</p>
<p>The CSS property- <code>-webkit-line-clamp</code> allows limiting of the contents of a <em>block container </em>  to the specified number of lines.</p>
<p>Combination of <code>display</code> property set to <code>-webkit-box</code> or <code>-webkit-inline-box</code> and 
<code>-webkit-box-orient</code> property set to <code>vertical</code> is needed to work <strong>line-clamp</strong> properly.</p>
<blockquote>
<p>Also in most of the cases contents won't be clipped but an ellipsis will still be shown after the specified number of lines, for this we need to set <code>overflow</code> to <code>hidden</code>.</p>
</blockquote>
<h4 id="heading-html">HTML</h4>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
       Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
       Lorem Ipsum has been the industry standard dummy text ever since the
       1500s, when an unknown printer took a galley of type and scrambled it to
       make a type specimen book. It has survived not only five centuries, but also
       the leap into electronic typesetting.
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h4 id="heading-css">CSS</h4>
<pre><code class="lang-CSS"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">display</span>: -webkit-box;
  <span class="hljs-attribute">-webkit-box-orient</span>: vertical;
  <span class="hljs-attribute">-webkit-line-clamp</span>: <span class="hljs-number">3</span>;
  <span class="hljs-attribute">overflow</span>: hidden;
}
</code></pre>
<h3 id="heading-codepen">Codepen</h3>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/erdhananjay7/pen/WNMEOYK">https://codepen.io/erdhananjay7/pen/WNMEOYK</a></div>
]]></content:encoded></item></channel></rss>