Chapter Text
Contents
This chapter will go through the process of building all the components shown in the example demonstrated in chapters 3 and 4. The constituent parts are as follows:
Basic structure
First, here are the elements that make up the overall structure and inside which everything else needs to be nested. We’ll be making a lot of use of <div>
elements here: our outermost component is a <div>
with the class whatsapp
plus one of the classes light
or dark
. I’ll be showing both light and dark themes side by side in this chapter (if you’re on mobile, you’ll probably need to scroll to the right to see the dark theme examples).
Inside the outer <div>
, there are three elements that represent the header (class topbar
), the message area (class messages
), and the bottom bar for typing input (class bottombar
). The topbar
element is a <table>
; the others are <div>
elements.
<div class="whatsapp light">
<table class="topbar"></table>
<div class="messages"></div>
<div class="bottombar"></div>
</div>
|
<div class="whatsapp dark">
<table class="topbar"></table>
<div class="messages"></div>
<div class="bottombar"></div>
</div>
|
So far, this gives us something that isn’t especially forthcoming:
Most obviously, the bottom bar is hidden, but this will reveal itself once we start adding messages!
The top bar
We’ll work through these three components in sequence, though, starting with the top bar. Let’s replace <table class="topbar"></table>
with this structure:
<table class="topbar">
<tbody>
<tr>
<td rowspan="2" class="backarrow"></td>
<td rowspan="2" class="pp">
<img src="URL of profile image goes here" alt="group icon"/>
</td>
<td class="groupname">
<p>name of chat goes here</p>
</td>
<td rowspan="2" class="icons">
</td>
</tr>
<tr>
<td class="members">
<p>list of group members goes here</p>
</td>
</tr>
</tbody>
</table>
Here’s an example:
|
|
🦎🦎🦎
|
|
You, Asshole, St Braska 🙏
|
|
|
|
🦎🦎🦎
|
|
You, Asshole, St Braska 🙏
|
|
A couple of things to note before moving on: firstly, the name of the group and the list of members will automatically be truncated with an ellipsis if they spill over the boundary of the table cell. So when these are too long, we’ll see something like this:
|
|
An extremely long group name
|
|
An enormous number of people, certainly more friends than I or any sane person should have
|
|
|
|
An extremely long group name
|
|
An enormous number of people, certainly more friends than I or any sane person should have
|
|
Secondly, for the sake of realism, group members should be listed in the following order:
- “You” (i.e. the person whose phone it is);
- Contacts stored in the phone, in alphabetical order;
- Numbers of group members not stored as contacts in the phone, in numerical order.
This can also be replaced with a message such as Name is typing … when appropriate.
The message area
Now for the fun part! We’ll move into the <div>
with class messages
for all the code that has to do with the messages sent and received.
Received messages
Let’s start with messages that the viewer receives, and then move on to sent messages in a moment. So, for each uninterrupted sequence of messages sent by the same person, the first thing we’ll need is another <div>
with the class in
. Inside that, each individual message will be its own <div>
, and each of these will have the class text
. Inside that, you’ll have a <p>
element, in which the content of the message is stored.
So here’s a very basic example, with just one sent message:
<div class="in">
<div class="text">
<p>Took Yuna to the zoo today 😊</p>
</div>
</div>
And here’s how that looks in the context of the overall structure that we’ve already seen:
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Took Yuna to the zoo today 😊
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Took Yuna to the zoo today 😊
|
There are a couple of things missing from this: an indication of who has sent the message, and a timestamp. We’ll add these as additional <p>
elements within the text
element, with the classes from
and time
respectively. For our from
element, we also need to indicate a colour to represent the sender by adding the name of the colour as an additional class. Based on SMWSTW, our colour options are the following: red1
, red2
, pink
, blue1
, blue2
, blue3
, blue4
, brown
, orange
, yellow
, purple
, green1
, green2
, green3
, green4
, and green5
. Here’s an example:
<div class="in">
<div class="text">
<p class="from blue2">St Braska 🙏</p>
<p>Took Yuna to the zoo today 😊</p>
<p class="time">17:26</p>
</div>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
Took Yuna to the zoo today 😊
17:26
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
Took Yuna to the zoo today 😊
17:26
|
Let’s make this slightly more complex by adding a second message to the sequence. To do this, we add another <div>
with the class text
right after the first one. This time, there’s no need to include the first <p>
, the one with the from
class, because the sender’s name has already been specified in the first message. We do still include a timestamp, though. So the sequence will look something like this:
<div class="in">
<div class="text">
<p class="from blue2">St Braska 🙏</p>
<p>Took Yuna to the zoo today 😊</p>
<p class="time">17:26</p>
</div>
<div class="text">
<p>She loved the lizards!</p>
<p class="time">17:28</p>
</div>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
Took Yuna to the zoo today 😊
17:26
She loved the lizards!
17:28
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
Took Yuna to the zoo today 😊
17:26
She loved the lizards!
17:28
|
In sequences like this, only the first message will have the tail.
Sent messages
The syntax for sent messages is exactly the same as for received messages. Just change the class in
to out
for the <div>
representing the overall message group, and the appearance will changes accordingly.
<div class="out">
<div class="text">
<p class="from blue2">Braska</p>
<p>Took Yuna to the zoo today 😊</p>
<p class="time">17:26</p>
</div>
<div class="text">
<p>She loved the lizards!</p>
<p class="time">17:31</p>
</div>
</div>
|
|
boyzz 💫
|
|
You, Auron ✨, THE GREAT JECHT
|
Braska
Took Yuna to the zoo today 😊
17:26
She loved the lizards!
17:28
|
|
|
boyzz 💫
|
|
You, Auron ✨, THE GREAT JECHT
|
Braska
Took Yuna to the zoo today 😊
17:26
She loved the lizards!
17:28
|
There are a couple of things to take note of here: firstly, the <p>
element telling us who has sent the message is hidden, as this evidently doesn’t show up on outgoing messages. I’d recommend keeping it there in the HTML nonetheless, for accessibility reasons and to make the code easier to modify.
Secondly, in sent messages the timestamp is automatically followed by the blue double tick symbol, meaning the message has been read by all group members. Of course, there may be cases where this hasn’t happened – we’ll see how to account for this later.
Here’s a longer exchange of messages as a further example:
<div class="in">
<div class="text">
<p class="from blue2">St Braska 🙏</p>
<p>Took Yuna to the zoo today 😊</p>
<p class="time">17:26</p>
</div>
<div class="text">
<p>She loved the lizards!</p>
<p class="time">17:28</p>
</div>
</div>
<div class="out">
<div class="text">
<p class="from orange">Jecht</p>
<p>dawwwwww</p>
<p class="time">17:34</p>
</div>
</div>
<div class="in">
<div class="text">
<p class="from red2">Asshole</p>
<p>Cute 🦎</p>
<p class="time">19:07</p>
</div>
</div>
<div class="out">
<div class="text">
<p class="from orange">Jecht</p>
<p>Asdfhjk auron did u jsut</p>
<p class="time">19:08</p>
</div>
<div class="text">
<p>omg did u even know theres an eomji keyboard</p>
<p class="time">19:08</p>
</div>
</div>
<div class="in">
<div class="text">
<p class="from blue2">St Braska 🙏</p>
<p>Lol!</p>
<p class="time">19:15</p>
</div>
</div>
<div class="in">
<div class="text">
<p class="from red2">Asshole</p>
<p>I know how phones work, Jecht.</p>
<p class="time">19:56</p>
</div>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
Took Yuna to the zoo today 😊
17:26
She loved the lizards!
17:28
Jecht
Asdfhjk auron did u jsut
19:08
omg did u even know theres an eomji keyboard
19:08
Asshole
I know how phones work, Jecht.
19:56
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
Took Yuna to the zoo today 😊
17:26
She loved the lizards!
17:28
Jecht
Asdfhjk auron did u jsut
19:08
omg did u even know theres an eomji keyboard
19:08
Asshole
I know how phones work, Jecht.
19:56
|
Status messages
There’s one more type of message to add in addition to sent and received messages, which consists of the status messages displayed by WhatsApp to specify what day it is, or to announce a change to the group such as an edit to the group name or the addition/removal of a member. Again, we use a <div>
element for these, this time with the class info
, and again include a <p>
inside with the content. Here are a couple of examples:
<div class="info">
<p>Today</p>
</div>
<div class="info">
<p>You changed the subject from “boyzz 💫” to “🦎🦎🦎”</p>
</div>
|
|
🦎🦎🦎
|
|
You, Asshole, St Braska 🙏
|
You changed the subject from “boyzz 💫” to “🦎🦎🦎”
|
|
|
🦎🦎🦎
|
|
You, Asshole, St Braska 🙏
|
You changed the subject from “boyzz 💫” to “🦎🦎🦎”
|
Images
To include a message that consists solely of an image, a <div>
element with class img
should be used inside the <div>
with class text
. This should then contain a <p>
element with the image inside, followed by the usual <p>
element with the timestamp (note that this final <p>
is inside the additional <div>
, while the initial <p>
stating who sent the message is not). Here’s an example:
<div class="text">
<p class="from blue2">St Braska 🙏</p>
<div class="img">
<p>
<img src="https://i.ibb.co/FD1w2DC/yuna.jpg" alt="Young girl holding lizard"/>
</p>
<p class="time">17:34</p>
<div>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
17:34
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
17:34
|
However, if the message contains text as well as an image, both this text and the timestamp should be outside the <div>
element that contains the image. This ensures that the timestamp applies to the whole message, not just the image itself.
<div class="text">
<p class="from blue2">St Braska 🙏</p>
<div class="img">
<p>
<img src="https://i.ibb.co/FD1w2DC/yuna.jpg" alt="Young girl holding lizard"/>
</p>
</div>
<p>With her new friend 😂</p>
<p class="time">17:34</p>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
With her new friend 😂
17:34
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
St Braska 🙏
With her new friend 😂
17:34
|
Replies
Replies that quote an earlier message can be included if we use a <div>
element with the class quote
. Another class should be added to this element to indicate the colour. Inside this, we can embed a <p>
element with the class from
to indicate who sent the message (no need to indicate the colour for a second time – it’ll inherit from the outer <div>
), and then, below this, the content of the quoted message in a <p>
.
<div class="text">
<p class="from red2">Asshole</p>
<div class="quote orange">
<p class="from">You</p>
<p>omg did u even know theres an eomji keyboard</p>
</div>
<p>I know how phones work, Jecht.</p>
<p class="time">19:56</p>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Jecht
Asdfhjk auron did u jsut
19:08
omg did u even know theres an eomji keyboard
19:08
Asshole
You
omg did u even know theres an eomji keyboard
I know how phones work, Jecht.
19:56
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Jecht
Asdfhjk auron did u jsut
19:08
omg did u even know theres an eomji keyboard
19:08
Asshole
You
omg did u even know theres an eomji keyboard
I know how phones work, Jecht.
19:56
|
As usual, if we switch our in
and out
classes, the message positions and colours will update accordingly. Here’s an example with a message being quoted by the sender:
|
|
boyzz 💫
|
|
You, Braska, Jecht
|
Jecht
Asdfhjk auron did u jsut
19:08
omg did u even know theres an eomji keyboard
19:08
Auron
Jecht
omg did u even know theres an eomji keyboard
I know how phones work, Jecht.
19:56
|
|
|
boyzz 💫
|
|
You, Braska, Jecht
|
Jecht
Asdfhjk auron did u jsut
19:08
omg did u even know theres an eomji keyboard
19:08
Auron
Jecht
omg did u even know theres an eomji keyboard
I know how phones work, Jecht.
19:56
|
Links
Links in WhatsApp (including @-mentions) show up in blue text. To enable this here, we can wrap them in a <span>
with the class link
.
<div class="text">
<p class="from red2">Asshole</p>
<p>
<span class="link">@Jecht</span> where are you? Is anyone with you?
</p>
<p class="time">20:12</p>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Asshole
@Jecht where are you? Is anyone with you?
20:12
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Asshole
@Jecht where are you? Is anyone with you?
20:12
|
Link previews
Valid links to websites normally show up on WhatsApp with an image preview and brief summary. We can do this using the same sort of structure as our quote
class: a <div>
element with class preview
. This time, we just include one <p>
element inside, which contains firstly the image preview, then the title for the summary inside a <span>
of class preview-title
, followed by a line break (i.e. a <br/>
element) and then the rest of the summary.
<div class="text">
<p class="from orange">Jecht</p>
<div class="preview">
<p>
<img src="https://i.ibb.co/y0JbTDT/yevon.jpg" alt="Yevon glyph"/>
<span class="preview-title">Spira Wildlife Park</span><br/>Witness the glory of Yevon’s creation!
</p>
</div>
<p>this one? <span class="link">https://spira-wp.sp</span></p>
<p class="time">17:28</p>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Jecht
Spira Wildlife Park
Witness the glory of Yevon’s creation!
this one? https://spira-wp.sp
17:28
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Jecht
Spira Wildlife Park
Witness the glory of Yevon’s creation!
this one? https://spira-wp.sp
17:28
|
As before, if we switch our out
and in
classes, the colours will update to match.
|
|
boyzz 💫
|
|
You, Auron ✨, THE GREAT JECHT
|
THE GREAT JECHT
Spira Wildlife Park
Witness the glory of Yevon’s creation!
this one? https://spira-wp.sp
17:28
|
|
|
boyzz 💫
|
|
You, Auron ✨, THE GREAT JECHT
|
THE GREAT JECHT
Spira Wildlife Park
Witness the glory of Yevon’s creation!
this one? https://spira-wp.sp
17:28
|
Unread messages
As mentioned above, sent messages automatically include a double blue tick after the timestamp to indicate that they’ve been read by everyone. When this doesn’t apply we can add the class unread
to the <p>
element containing the timestamp. For messages that have been sent but not received by all recipients, use the class unsent
instead (this is slightly inaccurately named, but please forgive me the brief fandom reference).
<div class="out">
<div class="text">
<p class="from red2">Auron</p>
<p>Are you drunk?</p>
<p class="time">19:58</p>
</div>
<div class="text">
<p>
<span class="link">@Jecht</span> where are you? Is anyone with you?
</p>
<p class="time unread">20:12</p>
</div>
<div class="text">
<p>We’ve talked about this.</p>
<p class="time unsent">20:13</p>
</div>
</div>
|
|
boyzz 💫
|
|
Jecht is typing …
|
Auron
Are you drunk?
19:58
@Jecht where are you? Is anyone with you?
20:12
We’ve talked about this.
20:13
|
|
|
boyzz 💫
|
|
Jecht is typing …
|
Auron
Are you drunk?
19:58
@Jecht where are you? Is anyone with you?
20:12
We’ve talked about this.
20:13
|
These look slightly different if the message consists solely of an image (and remember that the way the elements are nested is slightly different in this case):
|
|
boyzz 💫
|
|
You, Auron ✨, THE GREAT JECHT
|
Braska
17:34
Lol just realised I sent the wrong picture, old age haha
17:47
17:49
17:50
|
|
|
boyzz 💫
|
|
You, Auron ✨, THE GREAT JECHT
|
Braska
17:34
Lol just realised I sent the wrong picture, old age haha
17:47
17:49
17:50
|
Oversized emoji
WhatsApp increases the size of emoji if they appear in groups of three or fewer with no other text in the same message. To achieve this here, we can wrap the contents of the message (the two <p>
elements with the emoji and the timestamp, but again, not the <p>
with the name of the sender) in another <div>
and give this the class onemoji
, twomoji
or threemoji
as appropriate. Here are examples of all three:
<div class="out">
<div class="text">
<p class="from orange">Jecht</p>
<div class="onemoji">
<p>💖</p>
<p class="time">17:35</p>
</div>
</div>
<div class="text">
<div class="twomoji">
<p>💖💖</p>
<p class="time">17:35</p>
</div>
</div>
<div class="text">
<div class="threemoji">
<p>💖💖💖</p>
<p class="time">17:35</p>
</div>
</div>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Asshole
We get the message.
17:57
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Asshole
We get the message.
17:57
|
The bottom bar
We can add text in the bottom bar to show a message that is being typed by the focal character but isn’t sent yet. To do this, we add another <div>
inside the <div>
with class bottombar
; the new <div>
should have the class typearea
. You can then insert a <p>
inside this with the content of the unsent message (and if you include an indication of the sender here using the from
class, this will be hidden as it is for sent messages). The content will be truncated automatically.
<div class="bottombar">
<div class="typearea">
<p class="from">Jecht</p>
<p>chill aurofn im finnee</p>
</div>
</div>
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Asshole
Are you drunk?
19:58
@Jecht where are you? Is anyone with you?
20:12
Jecht
chill aurofn im finnee
|
|
|
boyzz 💫
|
|
You, Asshole, St Braska 🙏
|
Asshole
Are you drunk?
19:58
@Jecht where are you? Is anyone with you?
20:12
Jecht
chill aurofn im finnee
|