Substitute the division

Can I make the old div change its position and move to the side when I add a new div? And can all the old divs be hidden when adding four new divs? This is for my full news website and I want this applied to all four pages.

First page:

More pages:

2 pages have the same format and 1 has another format.

$(".js-post").on("mouseover", function() {
  const mainSrc = $(".js-main").attr("src");
  const targetSrc = $(this).attr("src");

  $(".js-main").attr("src", targetSrc);
  $(this).attr("src", mainSrc);
});
.wrapper {
  display: flex;
  width: 100%;
  padding-left: 200px;
  padding-top: 30px;
}

.main-view {
  width: 70px;
  height: 500px;
  margin-right: 30rem;
  object-fit: cover;
}

img.main.js-main {
  width: 500px;
  object-fit: cover;
  height: 400px;
}

thumbnail-view {
  width: 200px;
  padding-top: 20px;
  height: auto;
}

.post {
  width: 100%;
  height: 100px;
}

.box {
  background: white;
  top: 50%;
  left: 50%;
  padding: 10px;
}

box .imgBx {
  width: 150px;
}

* {
  font-family: 'Lato', sans-serif;
}

.hey {
  display: flex;
  width: 70%;
  justify-content: space-around;
  margin-top: 100px;
  margin-left: 180px;
  margin-bottom: 100px;
}

.card {
  width: 280px;
  height: 260px;
  padding: 2rem 1rem;
  background: grey;
  display: flex;
  position: relative;
  align-items: flex-end;
  transition: 0.5s ease-in-out;
  box-shadow: 0px 7px 10px rgba(0, 0, 0, 0.5);
}

card:hover {
  transform: translateY(20px);
}

card:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, rgba(0, 176, 155, 0.5), rgba(150, 201, 61, 1));
  z-index: 2;
  transition: 0.5s all;
  opacity: 0;
}

card:hover:before {
  opacity: 1;
}

card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

card.info {
  position: relative;
  z-index: 3;
  color: black;
  opacity: 0;
  transform: translateY(30px);
  transition: 0.5s all;
}

card.info h1 {
  padding-top: 25px;
  font-size: 30px;
  padding-left: 70px;
  padding-right: 50px;
}

card.info.btn {
  text-decoration: none;
  background: rgb(70, 218, 203);
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.4s ease-in-out;
  margin-top: 20px;
  margin-left: 70px;
}

card:hover.info {
  opacity: 1;
  transform: translateY(0px);
}

footer {
  padding: 50px 0;
  background-color: rgb(70, 218, 203);
  bottom: 0;
  padding: 2px 0px 5px 0px;
  position: relative;
  margin-top: auto;
  clear: both;
}

.on {
  width: 70px;
  white-space: nowrap;
  height: 30px;
  margin-left: 170px;
  margin-top: 60px;
  position: absolute;
}

on p {
  font-weight: bold;
}
<!-- jQuery dependency -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<!-- Body -->
<div class="wrapper">

  <div class="main-view">
    <div>heading</div>
    <img class="main js-main" src="{% static 'images/banner/pic9.jpg' %}" width="300px" height="100" alt="yoga">
  </div>
  <div class="thumbnail-view">
    <div class="box">
      <div class="imgBx">
        <img class="post js-post" src="{% static 'images/banner/pic1.jpg' %}" height="100" alt="handshake">
      </div>
    </div>
    <div class="box">
      <div class="imgBx">
        <img class="post js-post" src="{% static 'images/banner/pic5.jpg' %}" width="300px" height="100" alt="peoplejoined">
      </div>
    </div>
    <div class="box">
      <div class="imgBx">
        <img class="post js-post" src="{% static 'images/banner/pic8.jpg' %}" width="300px" height="100" alt="peoplejoined">
      </div>
    </div>
    <div class="box">
      <div class="imgBx">
        <img class="post js-post" src="{% static 'images/banner/pic7.png' %}" width="300px" height="100" alt="peoplejoined">
      </div>
    </div>
  </div>

</div>
<div class="on">
  <p> Must Read </p>
</div>
<div class="hey">

  <div class="card">
    <img src="{% static 'images/banner/m.PNG' %}">
    <div class="info">
      <h1>US's Miami Fashion </h1>

      <a href="#" class="btn">Read More</a>
    </div>
  </div>
  <div class="card">
    <img src="{% static 'images/banner/c.PNG' %}">
    <div class="info">
      <h1>Muted demand for cotton </h1>

      <a href="#" class="btn">Read More</a>
    </div>
  </div>
  <div class="card">
    <img src="{% static 'images/banner/ss.jpg' %}">
    <div class="info">
      <h1>Srilanka garment export </h1>

      <a href="#" class="btn">Read More</a>
    </div>
  </div>
</div>

Answer №1

It seems like you're looking for a solution in JavaScript to manage a list of items with one main item and four additional ones on the side. One approach could be to place all 5 items within the same parent container, assigning them the same classes. By using CSS (specifically first-child/nth-child) you can style the first item differently to make it stand out.

For adding a new item dynamically, consider utilizing jQuery's .prepend() method (refer to https://api.jquery.com/prepend/) which allows you to insert content at the beginning of the parent container. To control the display of items beyond the fifth, you could either use CSS to hide them or employ jQuery's .remove() function (check https://api.jquery.com/remove/). This will help manage the list effectively based on your requirements.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The process of implementing web-based online diagramming software involves a strategic approach to designing and integrating various

I'm really interested in learning how web-based online diagramming software works. If anyone could provide guidance or point me to example resources, I would greatly appreciate it. Here are some of the web-based online tools that I have been explorin ...

Attempting to Create a New User and Display the Resulting Page Using JavaScript and Handlebars Templates

I've implemented a form that allows users to input data. Once the user hits "Add User", they are successfully added to the database. However, instead of transitioning to the next page as expected, the form remains populated on the current page. The h ...

Ways to calculate the total number of keys within a JSON object at a certain level

I need to process a JSON file by extracting values from keys located at a specific depth. The initial value I want to access is situated here: json.children[0].children[0].children[0] Is there a method to navigate through the JSON object at a particular ...

Extension for Chrome - Personalized pop-up notification when page loads

I am looking to create a custom alert box that triggers on page load instead of the default one, which I find unattractive and possibly irritating for users. alert('hello'); My current approach involves the following code: manifesto.js "cont ...

How do I use jQuery to target a specific list item based on its data attribute and the ID of the list it belongs to?

Can anyone provide me with the correct jQuery syntax for selecting a list item based on a data attribute within a specific list? Below is an example list: <ul id="menu"> <li data-code="soup">Soup</li> <li data-code="salad">Salad< ...

Ways to transfer information from HTML form components to the Angular class

I am currently working with angular 9 and I have a requirement to connect data entered in HTML forms to the corresponding fields in my Angular class. Below is the structure of my Angular class: export interface MyData { field1: string, textArea1 ...

What is the method for triggering a JavaScript function by clicking a button within a CakePHP application?

<button type="button" id="addleetdata" class="btn btn-primary addleetdata float-left">Add</button> JS File $("#addleetdata").click(function () { console.log("entering into function") startLoading(); console.log("editin ...

What is the best way to adjust the height of the second column downwards?

I am trying to achieve a 2-column layout with both columns at the same height. This is how it currently appears: And this is how I want it to be: Here is my code snippet: html { background-color: lightblue; font-family: Tahoma, Geneva, sans-serif ...

AngularJS: Recommendations for structuring code to dynamically update the DOM in response to AJAX requests

Within Angular's documentation, there is a straightforward example provided on their website: function PhoneListCtrl($scope, $http) { $http.get('phones/phones.json').success(function(data) { $scope.phones = data; }); $scope.order ...

How can I use AJAX to remove a record from a MySQL table?

I am looking to create a button with an image X that, when clicked, will delete a row from the database at that exact moment. teste-checkbox.php <style> table { font-family: verdana; font-size: 12px; } table th { text-align: left; backgrou ...

How can I position text below a ticked checkbox?

Having an issue with my HTML and jQuery code. Everything is working fine, but when I click on a checkbox, the text "FINISHED" appears below all checkboxes instead of just the one I clicked on. This is my html code: $('.label__checkbox').cli ...

How to Initialize Multiple Root Components in Angular 4 Using Bootstrap

We are working on a JQuery application and have a requirement to integrate some Angular 4 modules. To achieve this, we are manually bootstrapping an Angular app. However, we are facing an issue where all the Angular components are loading simultaneously wh ...

Using Node.js and MongoDB to filter a sub array within an array of objects

Hello everyone, I currently have an array of objects containing some populated fields. Below is the product schema: import mongoose, { Schema } from 'mongoose'; const productSchema = new mongoose.Schema( { name: String, description: S ...

Ways to customize the appearance of a react-chartist component

I recently created a React JS component that utilizes the amazing react ChartistGraph component. However, I've run into an issue where the default CSS of ChartistGraph seems to be conflicting with my custom styling. While there is plenty of documentat ...

Developing Modules in NodeJS using Constructors or Object Literals

I am currently developing a nodejs application that needs to communicate with various network resources, such as cache services and databases. To achieve this functionality, I have created a module imported through the require statement, which allows the a ...

Enhance your interface with stunning JQuery code snippets

We are in the process of developing a web application that will be fully 2.0 compliant (utilizing AJAX and more). Although I am primarily a rich-client and server-side developer, my knowledge of Javascript is limited to a functional level. However, based ...

What is the best way to remove an active item from a Vue v-list?

When using Vuetify's v-list-item directive, I encountered an issue where the active prop cannot be removed once an item has been selected. Here is my approach so far: <v-list-item-group pb-6 color="primary" class="pb-3 text-left"> ...

Initiate a unidirectional ajax request

My WCF service has a slow processing time when called for the first time, but caches the results in HttpRuntime.Cache afterwards. To initialize this cache, I want to initiate a fire-and-forget ajax call from JavaScript. Currently, my page contains the fol ...

When adding values, they remain in their original positions

I am populating a select dropdown with options using AJAX. These options are added based on the selection made in another dropdown. The first function that appends the data: var appendto_c = function(appendto, value, curcode) { appendto.append("& ...

What is the best way to add padding to each line within a block of text containing multiple lines

My <span> tag has a background color and left and right padding applied to it. However, the padding is only visible at the beginning and end of the <span>, not on each line when the text wraps onto multiple lines. Is there a way to add padding ...