• Complain

Ahmed Bouchefra - Modern CSS

Here you can read online Ahmed Bouchefra - Modern CSS full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: SitePoint, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Ahmed Bouchefra Modern CSS

Modern CSS: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Modern CSS" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

CSS has grown from a language for formatting documents into a robust language for designing web applications. Its syntax is easy to learn, making CSS a great entry point for those new to programming. Indeed, its often the second language that developers learn, right behind HTML.

As CSSs feature set and abilities have grown, so has its depth. This book is a collection of articles that explore some of the amazing thngs that developers can do with CSS today; things that in the past might only have been achievable with some pretty complex JavaScript previously, if at all. It contains:

  • Using CSS Transforms in the Real World by Craig Buckler
  • Variable Fonts: What They Are, and How to Use Them by Claudio Ribeiro
  • Scroll Snap in CSS: Controlling Scroll Action by Tiffany B. Brown
  • Real World Use of CSS with SVG by Craig Buckler
  • CSS and PWAs: Some Tips for Building Progressive Web Apps by David Attard
  • 20 Tips for Optimizing CSS Performance by Craig Buckler
  • Advanced CSS Theming with Custom Properties and JavaScript by Ahmed Bouchefra

This book is for developers with some experience of CSS.

Ahmed Bouchefra: author's other books


Who wrote Modern CSS? Find out the surname, the name of the author of the book and a list of all author's works by series.

Modern CSS — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Modern CSS" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Chapter 1: Using CSS Transforms in the Real World
by Ilya Bodrov-Krukowski

In this article, well learn how CSS transforms can be used in the real world to solve various tasks and achieve interesting results. Specifically, youll learn how to adjust elements vertically, create nice-looking arrows, build loading animations and create flip animations.

Transformations of HTML elements became a CSS3 standard in 2012 and were available in some browsers before then. Transformations allow you to transform elements on a web page as explained in our 101 article on CSS transforms. You can rotate, scale, or skew your elements easily with just one line of code, which was difficult before. Both 2D and 3D transformations are available.

As for browser support, 2D transforms are supported by all major browsers including Internet Explorer, which has had support since version 9. As for 3D transformations, IE has only partial support since version 10.

Ahem, Excuse Me ...

This article wont focus on the basics of transformations. If you dont feel very confident with transformations, I recommend reading about 2D and 3D transforms first.

Vertically Aligning Children

Any web designer knows how tedious it can be to vertically align elements. This task may sound very simple to a person whos not familiar with CSS, but in reality theres a jumble of techniques that are carefully preserved between generations of developers. Some suggest using display: inline with vertical-align: middle, some vote for display: table and accompanying styles, whereas true old school coders are still designing their sites with tables (just joking, dont do that!). Also, its possible to solve this task with Flexbox or Grids, but for smaller components, transforms may be a simpler option.

Vertical alignment can be more complex when element heights are variable. However, CSS transformations provide one way to solve the problem. Lets see a very simple example with two nested divs:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam

Nothing complex: just two nested blocks with a Lorem Ipsum text of different length.

Lets set width, height, and border for the parent, as well as some spacing to make it look nicer:

.parent { height: 300px; width: 600px; padding: 0 1em; margin: 1em; border: 1px solid red;}

Also, enlarge the children font size a bit:

.child { font-size: 1.2rem;}

As a result, youll see something like this:

And now your customer says Please align the text vertically so that it appears - photo 1

And now your customer says: Please align the text vertically so that it appears in the middle of these red boxes. Nooo! But fear not: were armed with transformations! The first step is to position our children relatively and move them 50% to the bottom:

.child { font-size: 1.2rem; position: relative; top: 50%;}

After that, apply a secret ingredient the translateY function which will reposition the elements vertically:

.child { font-size: 1.2rem; position: relative; top: 50%; transform: translateY(-50%);}

So, whats happening here? top: 50% moves the top of the child element to the center of the parent:

But this is not enough because we want the childs center to be aligned with - photo 2

But this is not enough, because we want the childs center to be aligned with the parents center. Therefore, by applying the translateY we move the child up 50% of its height:

Some developers have reported that this approach can cause the children to - photo 3

Some developers have reported that this approach can cause the children to become blurry due to the element being placed on a half pixel. A solution for this is to set the perspective of the element:

.child { // ... transform: perspective(1px) translateY(-50%);}

This is it! Your children are now aligned properly even with variable text, which is really nice. Of course, this solution is a little hacky, but it works in older browsers in contrast to CSS Grid. The final result can be seen on CodePen:

Live Code

The final result can be seen on CodePen: see the Pen CSS Transforms: Vertical-Align.

Creating Arrows

Another very interesting use case for transformations is creating speech bubble arrows that scale properly. I mean, you can definitely create arrows with a graphical editor, but thats a bit tedious, and also they may not scale well if you use a bitmap image.

Instead, lets try to stick with a pure CSS solution. Suppose we have a box of text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam

It has some generic styling to make it look like a speech bubble:

html { font-size: 16px;}.box { width: 10rem; background-color: #e0e0e0; padding: 1rem; margin: 1rem; border-radius: 1rem;}

Im using rem units here so that if the roots font size is changed the box is - photo 4

Im using rem units here so that if the roots font size is changed, the box is scaled accordingly.

Next, Id like to make this bubble become more bubble-ish by displaying an arrow to the right. Well achieve that by using a ::before pseudo-selector:

.box::before { content: ''; width: 1rem; height: 1rem; background-color: #e0e0e0; overflow: hidden;}

The larger the width and height you assign, the larger the arrow will be.

Now move the arrow to the right:

.box { // ... position: relative;}.box::before { // ... position: absolute; right: -0.5rem;}

Currently, however, this element doesnt look like an arrow at all:

Lets align this small box vertically As long as its dimensions are static - photo 5

Lets align this small box vertically. As long as its dimensions are static, this is a simple task:

.box::before { // ... top: 50%;}

It is not precisely aligned, but well fix that later.

Now its time for transformation to step in. All we need to do is rotate this small box to turn it to a triangle, which will look just like an arrow:

.box::before { // ... transform: rotate(45deg);}

Heres a screenshot from the developer console (the box is highlighted with blue so you can see how its actually positioned):

Then just move the arrow a bit to the top using negative margin so that its - photo 6

Then, just move the arrow a bit to the top using negative margin so that its positioned precisely at the middle of the box:

.box::before { // ... margin-top: -0.5rem;}
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Modern CSS»

Look at similar books to Modern CSS. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Modern CSS»

Discussion, reviews of the book Modern CSS and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.