How to create a post section something like twitter using HTML, CSS and JavaScript

What is post section?

In my mind a post section is a section where you can share your idea or any kind of knowledge.

 

Let’s create a post section like twitter?

HTML

<!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>Twitter | Post</title>
    <link rel="stylesheet" href="style.css">
    <!--Font Awesome CDN Link-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
        integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
    <!--Font Family CDN Link-->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    <!--Jquery CDN Link-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>

<body>

    <section class="post-sec">
        <div class="post-header">
            <div class="user-image">
                <img src="img/my-image.jpg" title="User Image" alt="didasoff">
            </div>
            <div class="user-name">
                <h2>Mohammad Didar</h2>
                <p><span>@</span>didasoff</p>
            </div>
        </div>
        <div class="post-area">
            <form action="">
                <textarea class="post-input" onkeyup="inputCount(this)" placeholder="What's happening?"></textarea>
                <div class="text-limit-set">
                    <p>Text Limit</p>
                    <p class="text-type-count">300</p>
                </div>
                <div class="post-footer">
                    <div>
                        <ul>
                            <li><a href="#" title="Image"><i class="far fa-image"></i></a></li>
                            <li><a href="#" title="Imoj"><i class="far fa-laugh"></i></a></li>
                            <li><a href="#" title="Location"><i class="fas fa-map-marker-alt"></i></a></li>
                        </ul>
                    </div>
                    <div>
                        <button type="submit" class="post" title="Post">Post</button>
                    </div>
                </div>
            </form>
        </div>
    </section>


    <script>
        function inputCount(val) {
            var len = val.value.length;
            if (len >= 300) {
                val.value = val.value.substring(0, 300);
            } else {
                $('.text-type-count').text(300 - len);
            }
        };
    </script>
</body>

</html>

 

CSS

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
}

.post-sec {
    height: fit-content;
    width: 500px;
    padding: 20px;
    border-radius: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: rgba(0, 0, 0, 0.1) 0px 10px 50px;
}

.post-sec .post-header {
    display: flex;
}

.post-sec .post-header .user-image img {
    height: 50px;
    width: 50px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid #2f3640;
    padding: 2px;
}

.post-sec .post-header .user-name {
    padding-left: 20px;
}

.post-sec .post-header .user-name h2 {
    color: #2f3640;
    font-size: 20px;
}

.post-sec .post-header .user-name p {
    color: gray;
    font-size: 15px;
    padding: 5px 0px;
}

.post-sec .post-area .post-input {
    color: #2f3640;
    height: 200px;
    width: 100%;
    resize: none;
    font-size: 17px;
    font-family: 'Roboto', sans-serif;
    padding: 10px;
    margin: 20px auto 10px auto;
    border: 1px solid gray;
    border-radius: 10px;
    outline: none;
}

.post-sec .post-area .post-input::placeholder {
    color: gray;
}

.post-sec .post-area .text-limit-set {
    display: flex;
    margin: 0px auto 20px auto;
}

.post-sec .post-area .text-limit-set p:first-child {
    padding-right: 5px;
    color: #2f3640;
    font-size: 13px;
}

.post-sec .post-area .text-limit-set p:last-child {
    font-size: 13px;
    font-weight: bold;
    color: #1d9bf0;
}

.post-sec .post-area .post-footer {
    display: flex;
    width: 100%;
}

.post-sec .post-area .post-footer div {
    flex: 1;
}

.post-sec .post-area .post-footer div:first-child ul {
    list-style: none;
    display: flex;
}

.post-sec .post-area .post-footer div:first-child ul li:nth-last-child(2) {
    padding: 0px 20px;
}

.post-sec .post-area .post-footer div:first-child ul li a {
    text-decoration: none;
    color: #1d9bf0;
    font-size: 30px;
    transition: all 0.3s ease;
}

.post-sec .post-area .post-footer div:first-child ul li a:hover {
    color: #1d9cf0da;
}

.post-sec .post-area .post-footer div:last-child button {
    background-color: #1d9bf0;
    padding: 8px 30px;
    border-radius: 50px;
    border: 1px solid #1d9bf0;
    font-size: 13px;
    color: white;
    cursor: pointer;
    float: right;
    transition: all 0.3s ease;
}

.post-sec .post-area .post-footer div:last-child button:hover {
    background-color: transparent;
    color: #1d9bf0;
}

 

 

Hello my name is Mohammad didar and I am the frontend designer of adoff framework

Related Posts

This Post Has 6 Comments

  1. You are so awesome! I do not suppose I’ve read a single thing like that before. So great to discover another person with a few genuine thoughts on this topic. Seriously.. thanks for starting this up. This website is something that’s needed on the internet, someone with a bit of originality!

Leave a Reply

Your email address will not be published.