-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_13.txt
1514 lines (1279 loc) · 68.9 KB
/
script_13.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
____________________________________________________________________________
13_museum_of_candy_project________________________________________________13
____________________________________________________________________________
Now we get to this code along section where we build this website called the Museum of Candy. It's responsive, it uses Bootstrap. We want to make something here that does not look very bootstrapy. This is for a fictional candy museum where we put on some gallery images of candy. It has a minimal design with light passed out colors, some nice free photos. The site does not really say much with the content which is lorem ipsum. The navbar is transparent but when we scroll down it fills in and is also fixed to the top. We also have the heading section with a photo on the right. The main layout of the page are some big square fotos that we force to be square and then on the other side some text, an icon and some more text, centered vertically. The website is responsive and scales relatively nicely. On small screen sizes the items stack and the text goes above the images. This requires a little bit of work because the image comes on the left and then the text and after that the image comes on the right and the text goes first and so on. They are alternating. When we collapse it, the text always goes on top of the corresponding image and the icon also dissappears. Boostrap makes it easy to do that but Bootstrap makes it easy to do that but we have to add some classes to help us change the order when things collapse. The navbar also shrinks down and collapses. It's not incredibly difficult but it's not that obvious that it was made with Bootstrap. There's none of the default components, none of the fonts, the colors, the buttons. Maybe the only thing is the toggle hamburger icon for the navbar. Otherwise everything is pretty customized. Even though it is simple, it kind of looks nice these days. So that's our goal here to create this layout. If we think about this grid involved here, it is not that challenging.
So let's get started and have a look at our starter code inside museum_starter/. It contains index.html, app.css and an imgs folder. index.html has already boostrap included and also the used font which is called Nunito. The app.css is also added in the index.html but it's currently empty, but we'll work inside it. In the imgs folder are images which will be used on the website, including the icon.
We will begin with the navbar, get it to become transparent, change the font so that it looks nice. So let's start with giving our body a background color of #f5d9d5. For that we'll open app.css and write
body {
background: #f5d9d5;
}
Now we've got the pink background going so let's get to work on the navbar in index.html. Let's go inside body and make a nav of class="navbar navbar-dark bg-dark navbar-expand-md" and give it the id="mainNavbar"
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
</nav>
The first class is just a navbar and because the text is light on this navbar, we need to give it "navbar-dark" and we're also going to give it a "bg-dark" so that we can see what we're doing and we will remove it later on when we're finished. Lastly we have to decide where it should expand. In our finished example it shrinks on extra small and small and when we hit medium it expands. So that's "navbar-expand-md". We also gave it an id because sometimes we might have more than one navbar. This is not that often but it's good practice.
Inside the navbar we have the navbar brand which says CANDY then we have our HOME ABOUT and TICKETS links. So let's start with the navbar brand by making an anchor tag with class="navbar-brand" that has the text "CANDY" inside it.
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
</nav>
Let's now make a button from the docs that has the class "navbar-toggler" and attribute data-toggle="collapse" and a data-target="" which will stay empty because we don't have that set up yet:
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="">
</button>
</nav>
The next thing we'll do is add a span inside the button which has class="navbar-toggler-icon".
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
Now we should have abutton showing up at the right size. It's currenlty not working because it has nothing to collapse yet. So after that button we'll make a div with class="collapse navbar-collapse" and an id="navLinks" which we will reference as the data target in our button. We put navLinks because that's what it's collapsing. Let's also write "#navLinks" in our id from the button:
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
</div>
</nav>
We write it with #navLinks in data-target because we have to specify that it is an id with the # symbol. Okay, then we'll going to add in our actual nav inside our navbar. So there are three links for this and the markup is up to us what we want to use. This time we'll use an ul but we could also use a nav. So let's make a ul with the class of "navbar-nav" and then inside of it we'll add an li with the class="nav-item" and inside of each of those we'll put an anchor tag with the class="nav-link" and inside each anchor we'll put the text HOME, ABOUT and TICKETS.
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
<ul class="navbar-nav">
<li class="nav-item">
<a href="" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">ABOUT</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">TICKETS</a>
</li>
</ul>
</div>
</nav>
Now we should have some content collapsing. When the window expands, we should also get our content. We'll worry about the CSS as far as the font, color, size and hover color soon. What we need to do now is go to the button and make it more accessible. The navbar button does not actually have a label to explain what it is. It's three lines and to human eyes we understand what that means but when we are using a screen reader for example, this is not very meaningful at all, it will not know what clicking that button does. So what we can do is go into the button and add in an attribute aria-label="Toggle navigation" and we just say what it does inside there:
<nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
<ul class="navbar-nav">
<li class="nav-item">
<a href="" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">ABOUT</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">TICKETS</a>
</li>
</ul>
</div>
</nav>
Now we could do is remove the bg-dark from the navbar with id "mainNavbar".
<nav id="mainNavbar" class="navbar navbar-dark navbar-expand-md">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
<ul class="navbar-nav">
<li class="nav-item">
<a href="" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">ABOUT</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">TICKETS</a>
</li>
</ul>
</div>
</nav>
So that's it for the markup portion. We now have to go in and deal with all the CSS. The navbar text unfortunately is now a little hard to read but we'll deal with that as well. So in our app.css we already changed the background color. We now can declare the main font family for the body and set it to Nunito with a backup font of sans-serif:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
Now we need to make the navbar brand larger and red. So instead of altering all navbar brands using that class, we can say inside the navbar #mainNavbar .navbar-brand {} and we'll set color to #ea1c2c. Let's also set the font-size: 1.5rem. The last change we need to make is to the font-weight, it is currently a heavier font-weight and we need to make it lighter and set it to 100.
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
font-weight: 100;
font-size: 1.5rem;
}
Now we'd also like for the rest of the links to change font-weight and font-size. So instead of doing navbar-brand separately for the nav links to do the same thing, what we can do is say: everything in the main navbar should have font-size of 2.5rem and font-weight 100; and we can remove them from the mainNavbar .navbar-brand and just leave in the color:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
Now it's looking a little better. We notice that the default color for navbar-dark is not white, it's like a transparent white over which we hover and it turns white. So to make them true white we need to manually select them. So we'll select #mainNavbar .nav-link and set the color to white. And while we're at it let's change the order of the styles a bit:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
#mainNavbar .nav-link {
color: white;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
Now they are truly solid white, but we cannot tell when we're hovering. So we'll make them turn into that red color from the brand when we hover over them. So let's doplicate the nav-link selection and add in the pseudoselector :hover
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
#mainNavbar .nav-link {
color: white;
}
#mainNavbar .nav-link:hover {
color: #EA1C2C;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
So this applies the style only when we hover over that element. One more thing to take care of is the padding. The finished project has less padding. This is a little hard to see but if we inspect the nav element with dev tools f12 we can see it has green sides top and bottom which is paddin. So we're going to remove that padding top and bottom so that we get a narrower navbar. That's easy because we now have that padding utility from Bootstrap. So we can go to our navbar and write in the extra class "py-0"
<nav id="mainNavbar" class="navbar navbar-dark navbar-expand-md py-0">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
<ul class="navbar-nav">
<li class="nav-item">
<a href="" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">ABOUT</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">TICKETS</a>
</li>
</ul>
</div>
</nav>
this py-0 removes the padding from top and bottom completely. So it shrinks down a bit, it's closer to the top now. It is a very slight change. There is also something else that we cannot see right now, this navbar is not fixed to the top. The finished one is, as we scroll, it stays up there. So we have right now no content to scroll through so it is going to stay there at the top no matter what. Let's add some content in just to show this: let's add a div class="container" and another div with class="row" and another div class="col-4" with lorem100 inside it.
<div class="container">
<div class="row">
<div class="col-4">Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium, enim necessitatibus unde maxime sit reprehenderit illo sequi asperiores aut expedita eius ex perspiciatis quaerat obcaecati sunt mollitia cumque, laborum debitis tempora tenetur et aperiam voluptatem? Expedita facere pariatur magni? Placeat suscipit itaque neque, omnis cum harum, sequi quibusdam tenetur, reprehenderit magni repellendus accusantium. Sapiente delectus dolores consectetur unde fugiat, vero explicabo atque incidunt beatae numquam omnis itaque sit quos facere rem vitae nemo nisi corrupti maiores? Repellendus, dignissimos cumque quas aperiam fugiat voluptates reprehenderit doloremque. Asperiores illo ex porro voluptatibus quaerat temporibus perspiciatis quis minima. Rerum beatae distinctio placeat quia!</div>
</div>
</div>
So as we scroll, the navbar is not fixed. So in Boostrap we know there is an easy way to make it stick to the top by adding to the class "fixed-top":
<nav id="mainNavbar" class="navbar navbar-dark navbar-expand-md py-0 fixed-top">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
<ul class="navbar-nav">
<li class="nav-item">
<a href="" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">ABOUT</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">TICKETS</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-4">Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium, enim necessitatibus unde maxime sit reprehenderit illo sequi asperiores aut expedita eius ex perspiciatis quaerat obcaecati sunt mollitia cumque, laborum debitis tempora tenetur et aperiam voluptatem? Expedita facere pariatur magni? Placeat suscipit itaque neque, omnis cum harum, sequi quibusdam tenetur, reprehenderit magni repellendus accusantium. Sapiente delectus dolores consectetur unde fugiat, vero explicabo atque incidunt beatae numquam omnis itaque sit quos facere rem vitae nemo nisi corrupti maiores? Repellendus, dignissimos cumque quas aperiam fugiat voluptates reprehenderit doloremque. Asperiores illo ex porro voluptatibus quaerat temporibus perspiciatis quis minima. Rerum beatae distinctio placeat quia!</div>
</div>
</div>
So if we refresh the page the navbar is fixed up there but we have another problem: the content goes on top. We'll deal with that later. Let's now delete the text we added in.
<nav id="mainNavbar" class="navbar navbar-dark navbar-expand-md py-0 fixed-top">
<a href="#" class="navbar-brand">CANDY</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navLinks">
<ul class="navbar-nav">
<li class="nav-item">
<a href="" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">ABOUT</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">TICKETS</a>
</li>
</ul>
</div>
</nav>
So that's in for the navbar so far. It collapses correctly, it has the icon, it has the hover effect, the font is light, the color is changed so it's good enough to start
So now that the navbar is mostly done, let's tackle the next bit of content which is this top section where we have the image on the right holding a donut and on the left the series of headings which scale. The font-size changes, so that involves some non-bootstrap CSS to do that with media querries. The also the text just dissappears entirely and the image takes up the entire space at one point. The text is also centered vertically. So we'll start by adding a section under our <nav></nav> in index.html. If you remember, a regular container just goes just one part of the screen across and our content needs to go all the way across the screen.So we need to use a fluid container, it works the same way, we can use the grid system inside of it with rows and columns but it goes all the way across. Let's give it a class of "container-fluid":
</div>
</nav>
<section class="container-fluid>
</section>
Inside of it let's make a div with class of "row" and inside of that let's make two divs with "col-6", one after the other:
<section class="container-fluid">
<div class="row">
<div class="col-6"></div>
<div class="col-6"></div>
</div>
</section>
In the first one let's put some placeholder text like <h2></h2> that says "MUSEUM OF CANDY" to start with:
<section class="container-fluid">
<div class="row">
<div class="col-6">
<h2>MUSEUM OF CANDY</h2>
</div>
<div class="col-6"></div>
</div>
</section>
We can see straight away we have a small issue. Let's get the image in first before we worry about it. So inside the second div with class="col-6" we're going to put an image and the image we want is included in the images folder. It's called hand2.png and is inside imgs so we'll add an <img src="imgs/hand2.png">
<section class="container-fluid">
<div class="row">
<div class="col-6">
<h2>MUSEUM OF CANDY</h2>
</div>
<div class="col-6">
<img src="imgs/hand2.png" alt="">
</div>
</div>
</section>
We have a small problem now, first of all the image is huge but it is 50% across the screen. We can give it a class="img-fluid". This is a Bootstrap class that makes images responsive.
<section class="container-fluid">
<div class="row">
<div class="col-6">
<h2>MUSEUM OF CANDY</h2>
</div>
<div class="col-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
It changes the height property to be auto and max-width to be 100%. It makes it easier to work with images in the grid system and make them scale so that it shrinks down at different sizes. We also have an issue on the side, which is hard to see: the container-fluid has paddin on the left and right. Just a small amount. So let's remove it on the container by adding to the class px-0 to remove it on left and right:
<section class="container-fluid px-0">
<div class="row">
<div class="col-6">
<h2>MUSEUM OF CANDY</h2>
</div>
<div class="col-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now let's see how we can align that text on the left side of the container vertically. So the property we want is align-items. So let's add "align-items-center" to the div class="row":
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-6">
<h2>MUSEUM OF CANDY</h2>
</div>
<div class="col-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now our content is centered. Next we want that our text is centered. This is easier and we can give it on the actual h2 class="text-center".
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-6">
<h2 class="text-center">MUSEUM OF CANDY</h2>
</div>
<div class="col-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
We're going to rebuild this anyway but right now we're just approixmating how the content should look. We also need to add the rest of the text but in a while. Now we need get it to collapse, we want the MUSEUM OF CANDY text to go away and have the image take up all the space once we get to smaller than medium. There there is no header anymore. So we need to change our classes. We only want our two col-6 divs to be col-6 at size large so let's edit our two divs to col-lg-6.
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<h2 class="text-center">MUSEUM OF CANDY</h2>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Alright now we also want to make the MUSEUM OF CANDY text to go away. We can do that by using the display utility. To make this easier we're gonna make three of them and wrap them all together into a separate div:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div>
<h2 class="text-center">MUSEUM OF CANDY</h2>
<h2 class="text-center">MUSEUM OF CANDY</h2>
<h2 class="text-center">MUSEUM OF CANDY</h2>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
now let's add a class="text-white text-center" to the wrapper div to make the text white and remove "text-center" from the h2's class. This remove duplications.
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="text-white text-center">
<h2>MUSEUM OF CANDY</h2>
<h2>MUSEUM OF CANDY</h2>
<h2>MUSEUM OF CANDY</h2>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now to make the text hide itself and show itself when we get to screen size large, so let's add "d-none" and "d-lg-block" classes to our wrapper div:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="text-white text-center d-none d-lg-block">
<h2>MUSEUM OF CANDY</h2>
<h2>MUSEUM OF CANDY</h2>
<h2>MUSEUM OF CANDY</h2>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now we have most of this working. Now we have to make the text larger. We have seven museum of candy texts. We have a couple of things to tackle: font-size and font-weight. So let's make the slashes for now. Let's do some / inside spans:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="text-white text-center d-none d-lg-block">
<h2>MUSEUM<span>/</span>OF<span>/</span>CANDY</h2>
<h2>MUSEUM OF CANDY</h2>
<h2>MUSEUM OF CANDY</h2>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now we could go in CSS and style them red after giving them a class. Or we can give the wrapper div an id="headingGroup" and then we can go in our app.css that we want every span in headingGroup color red, rather than making every span on the entire page because we might have more spans later on:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
#mainNavbar .nav-link {
color: white;
}
#mainNavbar .nav-link:hover {
color: #EA1C2C;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
#headingGroup span {
color: #EA1C2C;
}
Now we're getting the red slashes. Now let's work on the font-weight. Let's make them h1's instead of h2's because they are actually the biggest text we have on our page and let's select all h1 inside id "headingGroup" and give them font-weight: 100 and font-size: 4rem in our app.css
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
#mainNavbar .nav-link {
color: white;
}
#mainNavbar .nav-link:hover {
color: #EA1C2C;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
#headingGroup span {
color: #EA1C2C;
}
#headingGroup h1 {
font-weight: 100;
font-size: 4rem;
}
How did we get to 4rem? I tried with trial and error to see what looked nice. And now let's duplicate them and make seven of them
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="text-white text-center d-none d-lg-block">
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now we see that it's a little cramped up top. So for that we need to add some margin top to the headingGroup div by adding "mt-5"
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="text-white text-center d-none d-lg-block mt-5">
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
Now we have a little more breathing room up there. So this looks good except we run into a big problem. Our text is not scaling, so we need it to shrink down at smaller screen sizes. We now need to take advantage of a media query. Media queries allow us to slectively apply styles based off of different screen sizes and the screen size that we're going to use is right about where it starts to get ugly at about 1200px. So let's write in our app.css @media(max-width:1200px) and let's select the h1's in the headingGroup and change their font-size to be 3rem:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
#mainNavbar .nav-link {
color: white;
}
#mainNavbar .nav-link:hover {
color: #EA1C2C;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
#headingGroup span {
color: #EA1C2C;
}
#headingGroup h1 {
font-weight: 100;
font-size: 4rem;
}
@media(max-width:1200px) {
#headingGroup h1 {
font-weight: 100;
font-size: 3rem;
}
}
Here it looks pretty good on all sizes. Now our heading is complete. We have the image, it's responsive. Next we'll do the next sections at the bottom where we have some text, an icon and a large photo and then they alternate sides. This would be content that can vary depending on we're actually making. So let's open up our index.html and after our heading section we'll make a new section with a class of "container-fluid px-0":
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="text-white text-center d-none d-lg-block mt-5">
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
<h1>MUSEUM<span>/</span>OF<span>/</span>CANDY</h1>
</div>
</div>
<div class="col-lg-6">
<img class="img-fluid" src="imgs/hand2.png" alt="">
</div>
</div>
</section>
<section class="container-fluid px-0">
</section>
So we want the content to go all the way across the screen and for it to have zero padding on the sides. Inside of it we'll make a div with class="row"
<section class="container-fluid px-0">
<div class="row">
</div>
</section>
We'll worry about the extra margin later that comes after our header. For now we also want a 50/50 placement so we'll make inside of our row div two div with class="col-6":
<section class="container-fluid px-0">
<div class="row">
<div class="col-6">
</div>
<div class="col-6">
</div>
</div>
</section>
Inside our first col-6 div we'll put an image called imgs/milk.png an we're going to give it the class="img-fluid":
<section class="container-fluid px-0">
<div class="row">
<div class="col-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-6">
</div>
</div>
</section>
Right now we have it to be 50/50 always and we're going to need to change that. They are stacking in our finished example up until medium after which they expand. So let's change both our col-6 divs to be col-md-6:
<section class="container-fluid px-0">
<div class="row">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6">
</div>
</div>
</section>
Now once we hit small, they stack. Now we need to add in some text on the right side. In the finished example we can see that the text does not go all the way across. If we inspect it, we'll see that it is contained inside a box inside of that col-md-6 div. Let's first add an h2 inside the col-md-6 div saying "MUSEUM OF CANDY":
<section class="container-fluid px-0">
<div class="row">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6">
<h2>MUSEUM OF CANDY</h2>
</div>
</div>
</section>
Underneath the text there should be an icon which is an image called imgs/lolli_icon.png so let's add that. Underneath we'll also add a paragraph of class="lead" which makes it stand out a little bit more with some lorem ipsum text inside it:
<section class="container-fluid px-0">
<div class="row">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</section>
At the moment nothing is centered neither horizontally nor vertically. So the text-center part is easy, we can just go to our col-md-6 div and add in "text-center":
<section class="container-fluid px-0">
<div class="row">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</section>
Now the text is centered. Now to make it centered vertically, the property for that is called align-items in flexbox utilities. If we had excess horizontal space, that would be justify-content. So we'll set our div class="row" to be also "align-items-center":
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</section>
Now it is centered but it doesn't look that good. So we need now to nest in another row. So we'll cur everything we have in our col-md-6 text-center div and add in another div with class="row". Inside the newly created row div we'll put another div with class="col-10" inside which we'll paste our content:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center">
<div class="row">
<div class="col-10">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
When we make a "row" div we get 12 units of space to work in again and we'll use 10 of them with the new "col-10" div to start. Now we can see that it is basically using 10 out of 12 but it's not centered where we want it to be. It should be those 10 in the middle. One way of doing this would be to add an empty col-1 div before and after our col-10 to get it centered. But a better way is to just use the flex utilities to center it horizontally. For this is the class called "justify-content-center" which we will add to the row div above the col-10 div:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center">
<div class="row justify-content-center">
<div class="col-10">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
So this spacing kind of looks fine but we'll make the text take up 8 units for screen size lg and greater. So let's add in col-lg-8 to our col-10 div:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center">
<div class="row justify-content-center">
<div class="col-10 col-lg-8">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
Let's now make the candy icon dissappear and give it the class d-none which hides it always and d-lg-inline to make it reappear when we get to large and greater sreen sizes.
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center">
<div class="row justify-content-center">
<div class="col-10 col-lg-8">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="" class="d-none d-lg-inline">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
The next thing we need to do now is tackle the ordering of everything so that when it shrinks down, the text comes before our image. This is currently with what we have not the case, the image goes first and we don't want that. We didn't talk about this but there are classes in Bootstrap that have to do with order. So we can actually assign order to our pieces. So what we do is use the classes "order-2" for the first item's div and "order-1" for the second
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6 order-2">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center order-1">
<div class="row justify-content-center">
<div class="col-10 col-lg-8">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="" class="d-none d-lg-inline">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
What we see now that they are swapped, but they are always swapped. That's not exactly what we want, we only want them swapped when the page is shrunk. We can fix that by adding order-md-1 to the first div and order-md-2 to the second div:
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6 order-2 order-md-1">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center order-1 order-md-2">
<div class="row justify-content-center">
<div class="col-10 col-lg-8">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="" class="d-none d-lg-inline">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
So what this does is says that it gives them normal order from sizes equal to or larger than medium, but until then they get switched.
Now let's go ahead and style our text in app.css. We only use h2's for the "MUSEUM OF CANDY" text so we can start by selecting all h2's and giving them color #EA1C2C, font-weight: 100 and font-size: 2.5rem:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
h2 {
color: #EA1C2C;
font-weight: 100;
font-size: 2.5rem;
}
#mainNavbar{
font-weight: 100;
font-size: 1.5rem;
}
#mainNavbar .nav-link {
color: white;
}
#mainNavbar .nav-link:hover {
color: #EA1C2C;
}
#mainNavbar .navbar-brand{
color: #EA1C2C;
}
#headingGroup span {
color: #EA1C2C;
}
#headingGroup h1 {
font-weight: 100;
font-size: 4rem;
}
@media(max-width:1200px) {
#headingGroup h1 {
font-weight: 100;
font-size: 3rem;
}
}
Let's give all of the div's that contain the text an extra class called "blurb" so that we can access them better.
<section class="container-fluid px-0">
<div class="row align-items-center">
<div class="col-md-6 order-2 order-md-1">
<img src="imgs/milk.png" alt="" class="img-fluid">
</div>
<div class="col-md-6 text-center order-1 order-md-2">
<div class="row justify-content-center">
<div class="col-10 col-lg-8 blurb">
<h2>MUSEUM OF CANDY</h2>
<img src="imgs/lolli_icon.png" alt="" class="d-none d-lg-inline">
<p class="lead" alt="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae
beatae, maiores deserunt
in voluptatibus
aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur
repellat eveniet quidem
voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam
autem nam ex deserunt debitis
eaque ratione! Nobis, quidem assumenda.</p>
</div>
</div>
</div>
</div>
</section>
So we can now chnage the h2 to .blurb h2 so that we can get all h2's from inside the element of class blurb:
body {
background: #f5d9d5;
font-family: "Nunito", sans-serif;
}
.blurb h2 {
color: #EA1C2C;
font-weight: 100;
font-size: 2.5rem;
}