• We just launched and are currently in beta. Join us as we build and grow the community.

Creating a Diagonal Background Design using HTML and CSS Tutorial

The Father

SEO Auditor
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
99
Likes
93
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this tutorial, you can learn to create a Simple Diagonal Background Design for a website or web application web pages using HTML and CSS. The tutorial aims to provide students and beginners with a reference for learning some tricks and techniques for designing or developing a website interface. Here, I will be providing a simple web page script that demonstrates the creation of a simple diagonal background design.

What is Diagonal Design?

The Diagonal Design is a simple user interface layout or background design of a website or web application with a slanting direction design. Frontend developers implement this design to a creative website UI and to give the end users a better experience while using the site.

How to Create a Diagonal Design using CSS?

Using CSS, there are a lot of ways and techniques to create diagonal shapes or elements. The skew() function of the transform property of CSS is one of the useful properties that can achieve the diagonal design. The skew CSS function skews or slants an element on the 2D plane. There are 3 skewing functions in CSS which are the skew(), skewX(), and skewY. Check out the scripts that I provided below to understand more about how can CSS create Diagonal Shaped Elements.

Sample Web Page

Here are the scripts of a simple web application page that demonstrate the creation of a simple website with a Diagonal background Design. The sample web page has a simple parallax with a diagonal design on the page header.

HTML

Here's the HTML file script of the web page that contains the sample static contents.

  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    >
  5. <meta

    http-equiv

    =

    "X-UA-Compatible"

    content

    =

    "IE=edge"

    >
  6. <meta

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1.0"

    >
  7. <title

    >

    CSS - Diagonal Background</

    title

    >
  8. <link

    rel

    =

    "preconnect"

    href

    =

    "https://fonts.googleapis.com"

    >
  9. <link

    rel

    =

    "preconnect"

    href

    =

    "https://fonts.gstatic.com"

    crossorigin>
  10. <link

    rel

    =

    "stylesheet"

    href

    =

    "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"

    /

    >
  11. <link

    rel

    =

    "stylesheet"

    href

    =

    "style.css"

    >
  12. </

    head

    >
  13. <body

    >
  14. <div

    id

    =

    "wrapper"

    >
  15. <div

    id

    =

    "page-header-container"

    >
  16. <div

    class

    =

    "page-header-container-shadow"

    ></

    div

    >
  17. <div

    class

    =

    "header-content"

    >
  18. <div

    class

    =

    "page-title"

    >

    Welcome to Sample Website</

    div

    >
  19. <div

    class

    =

    "site-logo"

    >
  20. <img

    src

    =

    "./logo.jpg"

    alt

    =

    "Site Logo"

    >
  21. </

    div

    >
  22. </

    div

    >
  23. </

    div

    >
  24. <section

    >
  25. <h1

    align

    =

    "center"

    >

    About Us</

    h1

    >
  26. <p

    >

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus cursus vehicula mauris eget convallis. Phasellus eros neque, interdum eget mollis a, vulputate ut metus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas malesuada facilisis facilisis. Duis in metus vel orci tincidunt consequat in vel augue. Sed posuere sit amet lectus sit amet porta. Pellentesque ullamcorper ornare sem et facilisis. Sed lobortis semper augue, at commodo est posuere nec.</

    p

    >
  27. <p

    >

    Suspendisse at odio est. Aliquam vitae porta turpis. Maecenas sit amet metus rhoncus, posuere erat in, bibendum lacus. Suspendisse potenti. Duis auctor ligula nisl, nec venenatis purus sagittis mattis. Praesent feugiat ligula nunc, vel pulvinar ipsum elementum eu. Vivamus mollis sit amet orci id placerat. Donec ullamcorper elit in mattis condimentum.</

    p

    >
  28. </

    section

    >
  29. </

    div

    >
  30. </

    body

    >
  31. </

    html

    >

Default Stylesheet

Here's the default CSS for the design and layout of the web page. The script does not contain the script for displaying a diagonal design.

  1. @import

    url

    (

    'https://fonts.googleapis.com/css2?family=Rubik&display=swap'

    )

    ;
  2. @import

    url

    (

    'https://fonts.googleapis.com/css2?family=Courgette&family=Secular+One&display=swap" rel="stylesheet'

    )

    ;
  3. :

    root

    {
  4. --secular-font

    :

    'Secular One'

    ,

    sans-serif

    ;
  5. }
  6. body *

    {
  7. font-family

    :

    'Rubik'

    ,

    sans-serif

    ;
  8. }
  9. /**
  10. Page Design
  11. */
  12. body,
  13. html{
  14. height

    :

    100%

    ;
  15. width

    :

    100%

    ;
  16. margin

    :

    0

    ;
  17. padding

    :

    0

    ;
  18. }
  19. body{
  20. background-color

    :

    #fff

    ;
  21. }
  22. /* Page Header Design*/
  23. #page-header-container

    {
  24. position

    :

    relative

    ;
  25. height

    :

    300px

    ;
  26. width

    :

    100%

    ;
  27. overflow

    :

    unset;
  28. }
  29. #page-header-container

    :

    before

    {
  30. content

    :

    ""

    ;
  31. position

    :

    absolute

    ;
  32. width

    :

    100%

    ;
  33. height

    :

    100%

    ;
  34. background-image

    :

    url

    (

    ./bg-1

    .jpg)

    ;
  35. background-repeat

    :

    no-repeat

    ;
  36. background-attachment

    :

    fixed

    ;
  37. background-size

    :

    cover;
  38. background-position

    :

    bottom

    center

    ;
  39. top

    :

    0

    ;
  40. left

    :

    0

    ;
  41. filter

    :

    brightness(

    .8)
  42. }
  43. /** Header Content */
  44. #page-header-container

    .header-content

    {
  45. position

    :

    relative

    ;
  46. height

    :

    85%

    ;
  47. padding

    :

    3em

    6em

    ;
  48. z-index

    :

    3

    ;
  49. }
  50. .header-content

    .page-title{
  51. font-size

    :

    3rem

    ;
  52. letter-spacing

    :

    3px

    ;
  53. font-weight

    :

    500

    ;
  54. text-align

    :

    center

    ;
  55. color

    :

    #fff

    ;
  56. font-family

    :

    var

    (

    --secular-font

    )

    ;
  57. }
  58. /* Site Logo */
  59. .site-logo

    {
  60. position

    :

    absolute

    ;
  61. width

    :

    150px

    ;
  62. height

    :

    170px

    ;
  63. right

    :

    10%

    ;
  64. top

    :

    36%

    ;
  65. transform

    :

    skew

    (

    -16deg

    ,

    11deg

    )

    ;
  66. }
  67. .site-logo

    >

    img {
  68. width

    :

    100%

    ;
  69. height

    :

    100%

    ;
  70. object-fit

    :

    cover;
  71. object-position

    :

    center

    center

    ;
  72. }
  73. section{
  74. padding

    :

    1em

    5em

    ;
  75. }

The following Image is the result of the provided script above which has no diagonal design yet.

Creating a Diagonal Design

Here's the additional CSS design that creates the diagonal design.

  1. /* Creating the Diagonal area*/
  2. #page-header-container

    :

    after

    {
  3. content

    :

    ""

    ;
  4. position

    :

    absolute

    ;
  5. width

    :

    100%

    ;
  6. height

    :

    50px

    ;
  7. background-color

    :

    #fff

    ;
  8. bottom

    :

    -25px

    ;
  9. left

    :

    0

    ;
  10. transform

    :

    skewY(

    -2deg

    )

    ;
  11. }
  12. /* Creating the Diagonal shadow*/
  13. #page-header-container

    .page-header-container-shadow

    {
  14. position

    :

    absolute

    ;
  15. bottom

    :

    -26px

    ;
  16. height

    :

    44px

    ;
  17. width

    :

    100%

    ;
  18. background

    :

    #f5f5f5

    ;
  19. transform

    :

    skewY(

    -2deg

    )

    ;
  20. z-index

    :

    2

    ;
  21. }

There you go! I have also provided the complete source code file that I created for this tutorial on this website and it is free to download. The download button is located below this tutorial's content.

That's it! I hope this Creating a Diagonal Background Design using HTML and CSS Tutorial will help you with what you are looking for and will be useful for your current and future projects.

Explore more on this website for more Tutorials and Free Source Codes.

Happy Coding =)


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,526

323,535

Top