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

<channel>
	<title>CSS3 Archives : vedmant.com : coding blog</title>
	<atom:link href="https://vedmant.com/tag/css3/feed/" rel="self" type="application/rss+xml" />
	<link>https://vedmant.com/tag/css3/</link>
	<description>Sharing my personal experience in web development</description>
	<lastBuildDate>Sun, 05 Jul 2015 12:15:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>
	<item>
		<title>CSS vertical centering techniques</title>
		<link>https://vedmant.com/css-vertical-centering-techniques/</link>
					<comments>https://vedmant.com/css-vertical-centering-techniques/#respond</comments>
		
		<dc:creator><![CDATA[vedmant]]></dc:creator>
		<pubDate>Mon, 29 Jun 2015 18:57:36 +0000</pubDate>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<guid isPermaLink="false">https://vedmant.com/?p=49</guid>

					<description><![CDATA[<p>So what is the best way to center blocks vertically using CSS? There are bunch of techniques, lets try each of them! 1. &#8220;line-height&#8221; property HTML code: CSS code: Here is the result: &#160; So it works just good, quite simple, but it doesn&#8217;t support variable height. 2. &#8220;position: absolute&#8221; and negative margins HTML code: CSS code: Here &#8230; <a href="https://vedmant.com/css-vertical-centering-techniques/" class="more-link">Continue reading <span class="screen-reader-text">CSS vertical centering techniques</span></a></p>
<p>The post <a href="https://vedmant.com/css-vertical-centering-techniques/">CSS vertical centering techniques</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<style>
.outer-block { background-color: gray; }
.inner-block p {margin-bottom: 0; }
.inner-text { display: inline-block; text-align: left; }
</style>

<h3>So what is the best way to center blocks vertically using CSS?</h3>
<p>There are bunch of techniques, lets try each of them!</p>
<h3>1. &#8220;line-height&#8221; property</h3>
<p>HTML code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;outer-block&quot;&gt;
   &lt;div class=&quot;inner-block&quot;&gt;
      &lt;p&gt;Some text&lt;/p&gt;
      &lt;p&gt;Some more text&lt;/p&gt;
   &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>CSS code:</p>
<pre class="brush: css; title: ; notranslate">
.outer-block { 
   height: 200px; 
   line-height: 200px; 
   text-align: center; 
}
.inner-block { 
   display: inline-block; 
   line-height: 1.5;
   text-align: left; 
   vertical-align: middle; 
}
</pre>
<p>Here is the result: </p>
 
<style>
.centering-inline-block .outer-block { 
   height: 200px; 
   line-height: 200px; 
   text-align: center; 
}
.centering-inline-block .inner-block { 
   display: inline-block; 
   line-height: 1.5;
   text-align: left; 
   vertical-align: middle;
}
</style>

<div class="centering-inline-block">

<div class="outer-block">
   <div class="inner-block">
      <p>Some text</p>
      <p>Some more text</p>
   </div>
</div>

</div>

<p>&nbsp;<br />
So it works just good, quite simple, but it doesn&#8217;t support variable height.</p>
<h3>2. &#8220;position: absolute&#8221; and negative margins</h3>
<p>HTML code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;outer-block&quot;&gt;
   &lt;div class=&quot;inner-block&quot;&gt;
      &lt;div class=&quot;inner-text&quot;&gt;
         &lt;p&gt;Some text&lt;/p&gt;
         &lt;p&gt;Some more text&lt;/p&gt;
      &lt;/div&gt;
   &lt;/div&gt;
&lt;/div&gt;

</pre>
<p>CSS code:</p>
<pre class="brush: css; title: ; notranslate">
.outer-block {
   position: relative;
   height: 200px; 
   text-align: center; 
}
.inner-block { 
   position: absolute;
   top: 50%;
   left: 0;
   margin-top: -30px;
   width: 100%;
   height: 60px;
   text-align: center; 
}
</pre>
<p>Here is the result: </p>
 
<style>
.centering-absolute .outer-block {
   position: relative;
   height: 200px; 
   text-align: center; 
}
.centering-absolute .inner-block { 
   position: absolute;
   top: 50%;
   left: 0;
   margin-top: -30px;
   width: 100%;
   height: 60px;
   text-align: center; 
}
</style>

<div class="centering-absolute">

<div class="outer-block">
   <div class="inner-block">
      <div class="inner-text">
         <p>Some text</p>
         <p>Some more text</p>
      </div>
   </div>
</div>

</div>

<p>&nbsp;<br />
Another good approach, not so simple as line-height though. However it needs inner block to by fixed height so negative margin-top can be set. And it needs additional block to center text block horizontally.</p>
<h3>3. Table cell method</h3>
<p>HTML code:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;div class=&quot;some-container&quot;&gt;
   &lt;div class=&quot;outer-block&quot;&gt;
      &lt;div class=&quot;inner-block&quot;&gt;
         &lt;div class=&quot;inner-text&quot;&gt;
            &lt;p&gt;Some text&lt;/p&gt;
            &lt;p&gt;Some more text&lt;/p&gt;
         &lt;/div&gt;
      &lt;/div&gt;
   &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>CSS code:</p>
<pre class="brush: css; title: ; notranslate">
.some-container {
   height: 200px;
}
.outer-block { 
   width: 100%; 
   height: 100%;
   display: table;
}
.inner-block { 
   width: 100%; 
   height: 100%;
   display: table-cell;
   vertical-align: middle;
   text-align: center;
}
</pre>
<p>Here is the result: </p>
 
<style>
.centering-table-cell .some-container {
   height: 200px;
}
.centering-table-cell .outer-block { 
   width: 100%; 
   height: 100%;
   display: table; 
}
.centering-table-cell .inner-block { 
   width: 100%; 
   height: 100%;
   display: table-cell;
   vertical-align: middle;
   text-align: center;
}
</style>

<div class="centering-table-cell">

<div class="some-container">
   <div class="outer-block">
      <div class="inner-block">
         <div class="inner-text">
            <p>Some text</p>
            <p>Some more text</p>
         </div>
      </div>
   </div>
</div>

</div>

<p>&nbsp;<br />
This is a great approach if you have container with variable height, this method will certainly work in this case! Downside of this method is that it will not work in older versions of IE. Also it needs additional block to center text block horizontally. Another pros is that it will expand if inner-block content height will became bigger than outer block.</p>
<p>If you need it to work in older IE versions you can use explicit table tags instead of div blocks:</p>
<p>HTML code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;some-container&quot;&gt;
   &lt;table class=&quot;outer-block&quot;&gt;
      &lt;tr&gt;
         &lt;td class=&quot;inner-block&quot;&gt;
            &lt;div class=&quot;inner-text&quot;&gt;
               &lt;p&gt;Some text&lt;/p&gt;
               &lt;p&gt;Some more text&lt;/p&gt;
            &lt;/div&gt;
         &lt;/td&gt;
      &lt;/tr&gt;
   &lt;/table&gt;
&lt;/div&gt;
</pre>
<p>CSS code:</p>
<pre class="brush: css; title: ; notranslate">
.some-container {
   height: 200px;
}
.outer-block { 
   width: 100%; 
   height: 100%; 
}
.inner-block {
   vertical-align: middle;
   text-align: center;
}
</pre>
<p>Here is the result: </p>
 
<style>
.centering-table .some-container {
   height: 200px;
}
.centering-table .outer-block { 
   width: 100%; 
   height: 100%; 
}
.centering-table .inner-block {
   vertical-align: middle;
   text-align: center;
}
</style>

<div class="centering-table">

<div class="some-container">
   <table class="outer-block">
      <tr>
         <td class="inner-block">
            <div class="inner-text">
               <p>Some text</p>
               <p>Some more text</p>
            </div>
         </td>
      </tr>
   </table>
</div>
</div>

<h3>Summary</h3>
<p>To summary this methods, I would say the best way for responsive designs is table cell method. Despite it doesn&#8217;t support old versions of IE this is virtually the only method to fully center block vertically for responsive design without JavaScript snippets. Two other ways always require outer or inner block to have fixes height value.</p>
<p>The post <a href="https://vedmant.com/css-vertical-centering-techniques/">CSS vertical centering techniques</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vedmant.com/css-vertical-centering-techniques/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Image slider on pure CSS3</title>
		<link>https://vedmant.com/image-slider-on-pure-css3/</link>
					<comments>https://vedmant.com/image-slider-on-pure-css3/#comments</comments>
		
		<dc:creator><![CDATA[vedmant]]></dc:creator>
		<pubDate>Thu, 05 Mar 2015 19:02:16 +0000</pubDate>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Slider]]></category>
		<guid isPermaLink="false">https://vedmant.com/?p=19</guid>

					<description><![CDATA[<p>Recently I&#8217;ve read one article about slider without any JS code and I decided to extend this idea and here is what i&#8217;ve got. First, we will need basic HTML layout for slider: &#60;ul class=&#34;css-slider&#34;&#62; &#60;li&#62;&#60;img src=&#34;slides/1.jpg&#34; alt=&#34;&#34;&#62;&#60;/li&#62; &#60;li&#62;&#60;img src=&#34;slides/2.jpg&#34; alt=&#34;&#34;&#62;&#60;/li&#62; &#60;li&#62;&#60;img src=&#34;slides/3.jpg&#34; alt=&#34;&#34;&#62;&#60;/li&#62; &#60;li&#62;&#60;img src=&#34;slides/4.jpg&#34; alt=&#34;&#34;&#62;&#60;/li&#62; &#60;li&#62;&#60;img src=&#34;slides/5.jpg&#34; alt=&#34;&#34;&#62;&#60;/li&#62; &#60;/ul&#62; Quite simple and straightforward. &#8230; <a href="https://vedmant.com/image-slider-on-pure-css3/" class="more-link">Continue reading <span class="screen-reader-text">Image slider on pure CSS3</span></a></p>
<p>The post <a href="https://vedmant.com/image-slider-on-pure-css3/">Image slider on pure CSS3</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Recently I&#8217;ve read one article about slider without any JS code and I decided to extend this idea and here is what i&#8217;ve got.</p>
<p>First, we will need basic HTML layout for slider:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul class=&quot;css-slider&quot;&gt;
    &lt;li&gt;&lt;img src=&quot;slides/1.jpg&quot; alt=&quot;&quot;&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;slides/2.jpg&quot; alt=&quot;&quot;&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;slides/3.jpg&quot; alt=&quot;&quot;&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;slides/4.jpg&quot; alt=&quot;&quot;&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;slides/5.jpg&quot; alt=&quot;&quot;&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Quite simple and straightforward.</p>
<p>Next step, lets style our sliders container, and add some other styles:</p>
<pre class="brush: css; title: ; notranslate">
.css-slider{
   position: relative; /* All slides will have absolute position */
   width: 100%; /* Make it responsive */
   padding: 0; margin: 0; 
   padding-bottom: 75%; /* Height will be 75% from width */
   list-style-type: none; 
   overflow: hidden; /* In case images will have wrong aspect ratio */
}

.css-slider li img{width: 100%;} /* And make images responsive as well */
</pre>
<p>The whole idea of this slider is to use keyframe animation for changing slides. </p>
<p>To make this work we will create keyframes that have to do following: show slide, keep it some time, hide slide, wait while all other slides will show.</p>
<p>This is how it looks:</p>
<pre class="brush: css; title: ; notranslate">
@-webkit-keyframes css-slider {
  10%{opacity: 1;} /* This is where slide becomes visible, duration 10 % of 20 sec */
  20%{opacity: 1;} /* Still visible, little more then middle point (100 % / 5 slides) */
  40%{opacity: 0;} /* Now its hidden, when next slide is fully visible */
}
</pre>
<p>Some explanations about percents and durations. </p>
<p>Our slide has 5 slides, delay between slides is 4s, this means that whole animation have to take 5 slides * 4s = 20s.</p>
<p>Then we can calculate how long will take 1%, 20s / 100% = 0.2s, or 10% will take 2s and this is our transition duration from opacity: 0 to opacity: 1. </p>
<p>Next step to get middle point: 4s / 0.2s = 20 % or just 100% / 5 slides = 20%, this is when next slide will start it&#8217;s transition, and current slide have to stay visible until that.</p>
<p>At last we have to hide our slide when next slide is fully shown, it&#8217;s the middle of next slide, 20% + 20% = 40%.</p>
<p>Then we add styles and keyframes to slides:</p>
<pre class="brush: css; title: ; notranslate">
.css-slider li{
   position: absolute; top:0; right: 0; bottom: 0; left: 0; /* Make it fill whole slider container */
   opacity: 0; /* Hide it */
   -webkit-animation: css-slider 20s infinite; /* Use keyframe animation from above */
}
</pre>
<p>And at last we set different delays for each slide to make it work. Each slide must have slides delay durations multiplied by slide position &#8211; 1, or just each next slide&#8217;s delay equals previous plus delay duration.</p>
<pre class="brush: css; title: ; notranslate">
.css-slider li:nth-child(1){-webkit-animation-delay: 0s;}
.css-slider li:nth-child(2){-webkit-animation-delay: 4s;}
.css-slider li:nth-child(3){-webkit-animation-delay: 8s;}
.css-slider li:nth-child(4){-webkit-animation-delay: 12s;}
.css-slider li:nth-child(5){-webkit-animation-delay: 16s;}
</pre>
<p>And here is result:</p>

<style>
.css-slider{
   position: relative; /* All slides will have absolute position */
   width: 100%; /* Make it responsive */
   padding: 0; margin: 0; 
   padding-bottom: 75%; /* Height will be 75% from width */
   list-style-type: none; 
   overflow: hidden; /* In case images will have wrong aspect ratio */
}

.css-slider li img{width: 100%;} /* And make images responsive as well */

@-webkit-keyframes css-slider {
  10%{opacity: 1;} /* This is where slide becomes visible, duration 10 % of 20 sec */
  20%{opacity: 1;} /* Still visible, little more then middle point (100 % / 5 slides) */
  40%{opacity: 0;} /* Now its hidden, when next slide is fully visible */
}

.css-slider li{
   position: absolute; top:0; right: 0; bottom: 0; left: 0; /* Make it fill whole slider container */
   opacity: 0; /* Hide it */
   -webkit-animation: css-slider 20s infinite; /* Use keyframe animation from above */
}

.css-slider li:nth-child(1){-webkit-animation-delay: 0s;}
.css-slider li:nth-child(2){-webkit-animation-delay: 4s;}
.css-slider li:nth-child(3){-webkit-animation-delay: 8s;}
.css-slider li:nth-child(4){-webkit-animation-delay: 12s;}
.css-slider li:nth-child(5){-webkit-animation-delay: 16s;}
</style>

<ul class="css-slider">
    <li><img src="https://vedmant.com/wp-content/uploads/2015/03/slide1.jpg" alt=""></li>
    <li><img src="https://vedmant.com/wp-content/uploads/2015/03/slide2.jpg" alt=""></li>
    <li><img src="https://vedmant.com/wp-content/uploads/2015/03/slide3.jpg" alt=""></li>
    <li><img src="https://vedmant.com/wp-content/uploads/2015/03/slide4.jpg" alt=""></li>
    <li><img src="https://vedmant.com/wp-content/uploads/2015/03/slide5.jpg" alt=""></li>
</ul>

<p>&nbsp;</p>
<p>Ok it looks good, but it has a big con, if you want to change slides count, delays or transitions duration you have to recalculate keyframes positions change duration and add or remove delays for each slide. That&#8217;s why it&#8217;s not very usable in real production projects. </p>
<p>Until some generator will be used, I will add SASS generator here next time.</p>
<p>And here is promised SASS mixin, I&#8217;ve improved it a little by adding z-indexes:</p>
<pre class="brush: css; title: ; notranslate">

@mixin css-slider($count, $duration, $delay) {

	$delay: $duration + $delay;
	$total_duration: $delay * $count;
	$start_visible: $duration / $total_duration * 100;
	$mid_visible: 100 / $count;
	$end_visible: $mid_visible * 2;

	@-webkit-keyframes css-slider {
		#{$start_visible + '%'}{opacity: 1; z-index: 100;}
		#{$mid_visible + '%'}{opacity: 1; z-index: 2}
		#{$end_visible + '%'}{opacity: 0; z-index: 1;}
	}

	@keyframes css-slider {
		#{$start_visible + '%'}{opacity: 1; z-index: 100;}
		#{$mid_visible + '%'}{opacity: 1; z-index: 2}
		#{$end_visible + '%'}{opacity: 0; z-index: 1;}
	}


	position: relative;
	width: 100%; padding: 0 0 75% 0; margin: 0;
	list-style-type: none; overflow: hidden;

	li{
		position: absolute; top:0; right: 0; bottom: 0; left: 0; z-index: 1;
		opacity: 0;
		-webkit-animation: css-slider #{$delay * $count}s infinite;
		animation: css-slider #{$delay * $count}s infinite;
	}

	li img{width: 100%;}

	@for $i from 0 through $count - 1 {
		li:nth-child(#{$i+1}){-webkit-animation-delay: #{$i * $delay}s; animation-delay: #{$i * $delay}s;}
	}

}

/* Apply our minix for .css-slider */
.css-slider{
	@include css-slider(5, 2, 2);
}

</pre>
<p>The post <a href="https://vedmant.com/image-slider-on-pure-css3/">Image slider on pure CSS3</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vedmant.com/image-slider-on-pure-css3/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
