Below is a simplified version of a Twitter-like website, including HTML, CSS, and JavaScript, all in a single file. This example focuses on the core components such as the header, tweet input, tweet display, and basic styling. Note that this is a very simplified version and real Twitter has much more complex functionality, styling, and backend support.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twitter Clone</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
.header {
background-color: #1DA1F2;
color: white;
padding: 10px;
text-align: center;
}
.tweet-input {
display: flex;
padding: 10px;
background-color: white;
border: 1px solid #ddd;
border-radius: 5px;
margin: 10px;
}
.tweet-input input {
width: 80%;
padding: 10px;
border: none;
border-radius: 5px 0 0 5px;
}
.tweet-input button {
width: 20%;
padding: 10px;
border: none;
background-color: #1DA1F2;
color: white;
border-radius: 0 5px 5px 0;
cursor: pointer;
}
.tweets {
margin: 10px;
}
.tweet {
background-color: white;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 10px;
}
.tweet p {
margin-bottom: 10px;
}
.tweet .username {
font-weight: bold;
}
</style>
</head>
<body>
<div class="header">
<h2>Twitter Clone</h2>
</div>
<div class="tweet-input">
<input type="text" id="tweetText" placeholder="What's happening?">
<button id="tweetBtn">Tweet</button>
</div>
<div class="tweets" id="tweetsContainer">
<!-- Tweets will be displayed here -->
</div>
<script>
let tweets = [];
const tweetInput = document.getElementById('tweetText');
const tweetBtn = document.getElementById('tweetBtn');
const tweetsContainer = document.getElementById('tweetsContainer');
tweetBtn.addEventListener('click', () => {
const tweetText = tweetInput.value.trim();
if (tweetText) {
const newTweet = {
username: 'You', // Simplified, in real app this would be the logged-in user's username
text: tweetText
};
tweets.push(newTweet);
displayTweets();
tweetInput.value = ''; // Clear input field
}
});
function displayTweets() {
tweetsContainer.innerHTML = ''; // Clear previous tweets
tweets.forEach((tweet, index) => {
const tweetHTML = `
<div class="tweet">
<p><span class="username">${tweet.username}</span> ${tweet.text}</p>
</div>
`;
tweetsContainer.insertAdjacentHTML('beforeend', tweetHTML);
});
}
</script>
</body>
</html>
This code creates a basic Twitter-like interface where you can input a tweet and see it displayed below the input field. It includes:
- Header: A simple header with the title "Twitter Clone".
- Tweet Input: A text input where you can type your tweet, accompanied by a "Tweet" button.
- Tweets Display: Below the input, tweets are displayed with the username and the tweet text.
This example lacks many features that the real Twitter has, such as user authentication, tweet deletion, editing, liking, retweeting, and more. It's meant to provide a very basic starting point for understanding how such a layout and functionality could be approached with HTML, CSS, and JavaScript.