Как сделать несколько контейнеров, находящихся рядом друг с другом?
Я хочу сделать общий контейнер #profile-container, в котором слева будут profile-info, profile-details, profile-ratings контейнеры (и всё, что в них лежит), расположенные друг под другом, а справа от них другие контейнеры, которые у меня и не получается добавить. Дело в том, что как бы я их не добавлял, они оказываются под первыми тремя контейнерами (profile-info, profile-details, profile-ratings), а не справа от них. Что делать?
function fetchData() {
const username = document.getElementById('username').value;
fetch(`https://api.saienterprises.ru/v2/apiTeslaCraft/${username}`)
.then(response => response.json())
.then(data => {
const profile = data[0].profile;
const profileContainer = document.getElementById('profile-container');
const profileNickname = document.getElementById('profile-nickname');
const profilePicture = document.getElementById('profile-picture');
profilePicture.src = profile.avatarImageUrl;
const profileDetails = document.getElementById('profile-details');
const ratingsContainer = document.getElementById('ratings-container');
const inputContainer = document.getElementById('input-container')
inputContainer.style.display = 'none';
profileNickname.textContent = profile.nickname;
profileDetails.innerHTML = `
<p>Дата регистрации: ${new Date(profile.registration).toLocaleDateString()}</p>
<p>Сообщений: ${parseInt(profile.forumData.messages?.replace(/\s+/g, ''), 10) ?? 0}</p>
<p>Рейтинги:
<font color="#62A201">${parseInt(profile.forumData.positiveRatings?.replace(/\s+/g, ''), 10) ?? 0}</font>
<font color="#767676"> / </font>
<font color="#2980B9">${parseInt(profile.forumData.neutralRatings?.replace(/\s+/g, ''), 10) ?? 0}</font>
<font color="#767676"> / </font>
<font color="#D90B00">${parseInt(profile.forumData.negativeRatings?.replace(/\s+/g, ''), 10) ?? 0}</font>
</p>
<p>Достижений: ${profile.achievements}</p>
<p>Баллов: ${parseInt(profile.forumData.points, 10) ?? 0}</p>
<p>Звание: ${profile.rankForum}</p>
`;
const profileRatings = profile.ratings;
const allRatings = Object.entries(profileRatings).map(([rating, values]) => ({
rating,
received: parseInt(values["Получено"].replace(/\s+/g, ''), 10),
}));
allRatings.sort((a, b) => b.received - a.received);
const topThreeRatings = allRatings.slice(0, 3);
// Добавление рейтингов в одну строку
ratingsContainer.innerHTML = '';
function appendRatingElement(imagePath, received) {
const container = document.createElement("div");
container.classList.add("rating-container");
const img = document.createElement("img");
img.src = imagePath;
img.classList.add("rating-image");
const label = document.createElement("p");
label.textContent = received;
label.classList.add("rating-label");
container.appendChild(img);
container.appendChild(label);
ratingsContainer.appendChild(container);
}
for (const { rating, received } of topThreeRatings) {
const imagePath = `./rating-icons/${rating.toLowerCase()}.png`;
appendRatingElement(imagePath, received);
}
profileContainer.style.display = 'block';
})
.catch(error => {
console.error('Error fetching data:', error);
});
}
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif, sans-serif;
background-color: #f2f2f2;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
text-align: center;
}
#profile-info, #profile-details {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2) inset;
text-align: center;
}
#profile-container {
display: none;
}
#profile-info {
align-items: center;
text-align: center;
margin: 10px;
}
#profile-details {
margin: 10px;
text-align: center;
}
#profile-nickname {
margin: 0;
font-size: 24px;
}
#profile-picture {
max-width: 200px;
max-height: 200px;
margin: 10px;
border-radius: 5%;
}
input {
padding: 8px;
margin-right: 10px;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
button {
padding: 8px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.rating-container {
display: inline-block;
margin-right: 10px;
border: 1px solid #ccc;
border-radius: 4px;
width: 6vw;
height: 7vh;
}
.rating-image {
display: block;
margin: 0 auto;
margin-top: 5px;
}
.rating-label {
margin-top: 5px;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Профиль TeslaCraft</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div id="input-container">
<h1>Информация о профиле<br>на сервере TeslaCraft</h1>
<input type="text" id="username" placeholder="Введите свой никнейм">
<button>Продолжить</button>
</div>
<div id="profile-container">
<div id="profile-info">
<h2 id="profile-nickname"></h2>
<img id="profile-picture" src="" alt="Profile-picture">
</div>
<div id="profile-details"></div>
<div id="profile-ratings">
<p><b>Самые получаемые рейтинги</b></p>
<div id="ratings-container"></div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Источник: Stack Overflow на русском