A hero section is the area that is immediately shown when the user visits a website. This section of the website should be able to introduce the overall aspects of the website.
Key Factors:
Today, I attempted to create an example hero section that was provided in my udemy course. As always, I began by creating all the content elements that will be displayed on the web page using html. I divided all the contents into either header or section in order to differentiate the texts that are used in different components.
Inside the header, I created a nav component where the logo and the navigation tool for the website will be created. Additionally, I created another text component that briefly explains and advertises what the website is for. I also added a button element for some user interaction.
Inside the section, I created another text component that will futher explain features of the website in greater detail. For now, I only added some random text which I will change later after giving some structure to the overall layout.
// html <header> <nav> <div>LOGO</div> <div>NAVIGATION</div> </nav> <div> <h1>A healthy meal delivered to your door, every single day</h1> <p> The smart 365-days-per-year food subscription that will make you eat healthy again. Tailored to your personal tastes and nutritional needs </p> <a href="#" class="btn">Start eating well</a> </div> </header> <section> <div> <h2>Some random heading</h2> <p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia vel nam totam, provident eligendi facilis saepe eum veniam laborum id magnam nobis dicta rerum ullam quibusdam officiis autem nesciunt dolore? </p> </div> </section>
// css html { font-family: "Rubik", sans-serif; color: #444; }
Although there are some contents displayed on the website, it looks very boring without any colors or layout. Now would be a very good time to add some css effects to the website. For css, I always set all my margin and padding size to 0. I also set box-sizing to border-box. Setting these as default will clear any restrictions when I want to freely size elements.
For the entire header section, I gave a random background-color of orange-red to see how much space is occupied. Later, this will be replaced with an image.
I started with the nav element and went all the way down in order. For the navigation bar, I set the display property to flex and gave space between the logo and navigation by setting the justify-content property to space-between. For now, I gave a random background-color of green to the bar to see how much space is occupied.
For the text elements, I quickly adjusted their font-size and line-height while placing them in the appropriate location with margin and padding.
There was no need to give any background-color for the section component.
// css nav { font-size: 20px; font-weight: 700; display: flex; justify-content: space-between; background-color: green; } h1 { font-size: 52px; margin-bottom: 32px; } p { font-size: 20px; line-height: 1.6; margin-bottom: 48px; } .btn:link, .btn:visited { font-size: 20px; font-weight: 600; background-color: #e67e22; color: #fff; text-decoration: none; display: inline-block; padding: 10px 32px; border-radius: 9px; } h2 { font-size: 44px; margin-bottom: 48px; } section { padding: 96px 0; background: #f7f7f7; }
Before moving on, I added an extra div element within the header container and in order to adjust the width of the header text to lean towards the left.
Using absolute positioning, I moved the header text on the center without affecting any other components.
Now its time to get add an image background to the header section and make some final adjustments for sizes. By using a property known as background-image, I was able to instantly apply an image file onto the website. Because the text needed to be readable, I made the image to look darker by adjusting the gradient. Additionally, I used the background-size property and set it to cover. This automatically sets the image to fit the size according to the screen.
With this, the hero section was finally complete! 😀!
// css header { height: 100vh; position: relative; background-image: linear-gradient( rgba(34, 34, 34, 0.6), rgba(34, 34, 34, 0.6) ), url(hero.jpg); background-size: cover; color: #fff; } .header-container { width: 1200px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); } .header-container-inner { width: 50%; }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Omnifood Hero Section</title> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;700&display=swap" rel="stylesheet" /> <style> * { margin: 0; padding: 0; box-sizing: border-box; } html { font-family: "Rubik", sans-serif; color: #444; } .container { margin: 0 auto; width: 1200px; } header { height: 100vh; position: relative; background-image: linear-gradient( rgba(34, 34, 34, 0.6), rgba(34, 34, 34, 0.6) ), url(hero.jpg); background-size: cover; color: #fff; } nav { font-size: 20px; font-weight: 700; display: flex; justify-content: space-between; padding: 32px; } .header-container { width: 1200px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); } .header-container-inner { width: 50%; } h1 { font-size: 52px; margin-bottom: 32px; line-height: 1.05; } p { font-size: 20px; line-height: 1.6; margin-bottom: 48px; } .btn:link, .btn:visited { font-size: 20px; font-weight: 600; background-color: #e67e22; color: #fff; text-decoration: none; display: inline-block; padding: 10px 32px; border-radius: 9px; } h2 { font-size: 44px; margin-bottom: 48px; } section { padding: 96px 0; background: #f7f7f7; } </style> </head> <body> <header> <nav class="container"> <div>LOGO</div> <div>NAVIGATION</div> </nav> <div class="header-container"> <div class="header-container-inner"> <h1>A healthy meal delivered to your door, every single day</h1> <p> The smart 365-days-per-year food subscription that will make you eat healthy again. Tailored to your personal tastes and nutritional needs </p> <a href="#" class="btn">Start eating well</a> </div> </div> </header> <section> <div class="container"> <h2>Some random heading</h2> <p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia vel nam totam, provident eligendi facilis saepe eum veniam laborum id magnam nobis dicta rerum ullam quibusdam officiis autem nesciunt dolore? </p> </div> </section> </body> </html>
Thanks a ton to get writing this sort of superb posting! I uncovered your web blog ideal for this demands. Contained in the grapefruit excellent plus handy discussions. Keep up to date favorable deliver the results! biurko młodzieżowe
Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it. fototapety 3d
What a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much. افضل موقع زيادة متابعين
Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it. hagia sophia visiting hours
도프티켓은 신용카드 현금화 전문 업체입니다. 신용카드 현금화 90% 최저 수수료로 신속하고 편리하게 이용하세요. 현금이 필요할 때 본인 명의의 신용카드만 있다면 OK, 신용점수에 영향 없이 안전한 현금 마련은 온라인 카드깡 전문 도프티켓에 문의하세요. 신용카드 현금화, 법인카드 현금화 등 자세한 상담은 도프티켓 고객센터에 문의하여 주세요. 본 서비스는 신용카드의 한도를 활용하여 현금을 마련하는 서비스로 반드시 본인 명의의 신용카드와 계좌로만 진행이 가능합니다. 상담 전 사용중이신 카드 정보, 필요 금액, 본인 확인 정보, 카드의 잔여 한도 등을 미리 확인하여 주시면 보다 빠른 상담을 받으실 수 있습니다. 도프티켓은 카드현금화 전문 상담센터를 365일 24시간 운영하고 있으니 언제든 편하게 문의하여 주세요. 신용카드 현금화
This is definitely the knowledge We are acquiring all over the place. Cheers for ones web site, I merely join your blog. This is the wonderful web site. . Comment fidéliser ses clients B2B ?
I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it.. https://www.ini188pp.com/
I did experience checking articles or reviews shared here. They are simply exceptional there are a large amount of advantageous knowledge. https://eventsguys.co.za/
Enter 1X200BOX while registering on 1xBet to claim a 130% welcome bonus. Get up to €130 in extra funds and enjoy top-tier sports betting! code promo 1xbet anniversaire
Continue the nice function, We study couple of articles about this web site as well as I believe that the internet weblog is actually actual fascinating and it has obtained arenas associated with wonderful info. https://thebeerstore.co.za/
I did experience checking articles or reviews shared here. They are simply exceptional there are a large amount of advantageous knowledge. https://waxedbranding.co.za/
Compete the great get the job done, As i browse small amount of content articles in this particular websites and even It looks like that your choice of word wide web web log is without a doubt realistic important and allows gotten forums in fabulous tips. https://www.corporateeventplanning.co.za/
I did experience checking articles or reviews shared here. They are simply exceptional there are a large amount of advantageous knowledge.https://www.videoproductioncompany.co.za/
The audio will be awesome. You might have several extremely skilled performers. My partner and i want an individual the most effective regarding accomplishment. łóżeczka dla niemowląt
her in fact awesome blog page. her realy content rich and then a this fantastic profession. i prefer this unique. i love my boyfriend