How can I stack images on top of each other within a div

Currently, I am in the process of creating a blackjack game and encountering an issue with overlapping cards. Despite implementing the code below, all I see is a column of cards displayed.

I have looked at similar questions for guidance, but I'm unable to pinpoint what mistake I might be making.

Any assistance would be greatly appreciated! Thank you in advance!

html,
body {
  margin: 0px;
  background-color: rgb(0, 46, 0);
  color: white;
}

.title {
  text-align: center;
  background-color: black;
  color: white;
  padding: 20px;
  font-size: 25px;
}

.card {
  position: relative;
  width: 150px;
  left: 100px;
  margin-left: -75px;
}
<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">

  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b0bdbda6a1a6a0b3a292e7fce2fce2ffb0b7a6b3e1">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
  <title>Blackjack</title>

  <link rel="stylesheet" href="assets/css/styles.css">
</head>

<body>

  <header class="title">
    Blackjack
  </header>

  <div class="row mt-2">
    <div class="col text-center">

      <button class="btn btn-danger">New Game</button>
      <button class="btn btn-primary">Hit</button>
      <button class="btn btn-primary">Stand</button>

    </div>
  </div>

  <div class="row container">
    <div class="col">

      <h1>Player <small>0</small> Points</h1>
      <div id="player-cards">
        <img class="card" src="assets/cartas/10C.png">
        <img class="card" src="assets/cartas/10C.png">
        <img class="card" src="assets/cartas/10C.png">
        <img class="card" src="assets/cartas/10C.png">

      </div>

    </div>
  </div>

Considering my limited experience, it's entirely possible that my mistake is trivial. Nevertheless, any guidance or solution would be immensely helpful as I'm struggling to identify the error on my own.

Answer №1

Here is a different approach to try.

html,
body {
  margin: 0px;
  background-color: rgb(0, 46, 0);
  color: white;
}

.title {
  text-align: center;
  background-color: black;
  color: white;
  padding: 20px;
  font-size: 25px;
}

#player-cards {
  position: relative;
  width: 150px;
  left: 100px;
  margin-left: -75px;
}

img.card{
  position:absolute;
  left:0px;
  top:0px;
}

img.card:nth-child(2) {     
  transform: translate(0, 50%);
} 
img.card:nth-child(3) {      
  transform: translate(0, 100%);
} 
img.card:nth-child(4) {     
  transform: translate(0, 150%);     
} 
<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">

  <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
  <title>Blackjack</title>

  <link rel="stylesheet" href="assets/css/styles.css">
</head>

<body>

  <header class="title">
    Blackjack
  </header>

  <div class="row mt-2">
    <div class="col text-center">

      <button class="btn btn-danger">New Game</button>
      <button class="btn btn-primary">Hit</button>
      <button class="btn btn-primary">Stand</button>

    </div>
  </div>

  <div class="row container">
    <div class="col">

      <h1>Player <small>0</small> Points</h1>
      <div id="player-cards">
        <img class="card" src="assets/cartas/10C.png">
        <img class="card" src="assets/cartas/10C.png">
        <img class="card" src="assets/cartas/10C.png">
        <img class="card" src="assets/cartas/10C.png">

      </div>

    </div>
  </div>

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

Is there a WebKit equivalent to the MDC (Mozilla Documentation Center)?

Experimenting with the newest HTML5 features is rewarding, yet challenging as standards and browser-specific implementations constantly evolve. While Mozilla provides a valuable resource with their MDN Doc Center documenting Gecko changes, I'm curious ...

Having trouble determining why the design is not displaying correctly

I'm currently working on a calendar webpage, and everything looks perfect until I add the new JavaScript element. Suddenly, the numbers in the first row start behaving strangely. I've tried to troubleshoot but can't seem to figure out what&a ...

What is the proper way to insert a video using html5?

Hi there! I've been working on creating a webpage and have successfully added all other elements except for embedding a video using html5. It is crucial to the overall design of my website, so any assistance you can provide would be greatly valued. ...

Identifying the HTML elements beneath the mouse pointer

Does anyone know the method to retrieve the HTML tag located directly under the mouse cursor on a webpage? I am currently developing a new WYSIWYG editor and would like to incorporate genuine drag and drop functionalities (rather than the common insert at ...

jQuery smooth scrolling problem causing a one-second page "blinking" issue

Currently, I have implemented a smooth scrolling effect on my website using the following jQuery code: jQuery('html,body').animate({scrollTop:scrollTarget}, 1000, "swing"); Although the effect works well in general, I have noticed that when mul ...

Is it possible to resize a Div using pure CSS?

Here is the HTML structure I am working with: <div class="outer"> <div class="inner"> <a href="#"/> <a href="#"/> <a href="#"/> </div> </div> This is the corresponding CSS: div.outer{ position:relative; ...

The include_once function is functioning correctly on one page, but encountering issues on another page. No errors are being displayed

I am currently using Bootstrap for my website. When I include the bottom and footer sections in actualites.php (at the end of the file), everything works smoothly. As I construct my website, I am trying to incorporate content via URL. My code looks like t ...

Abnormal scrolling issues observed on handheld devices like mobile phones and tablets

I recently added a parallax effect to the hero section of my website, and while it works perfectly on desktop, I encountered some scrolling issues when viewing it on mobile or tablet devices. Sometimes the scrolling behaves as intended, and other times it ...

implementing jquery typewriter plug-in for a responsive bootstrap image

I am using Bootstrap and my image response dynamically, but I am having trouble adding text to it. I would like to use a jQuery typewriter plugin for the text on the image, which should resize according to screen size. Here is my HTML code and I have used ...

What is the best way to ensure the font size is responsive in Laravel's welcome.blaze.php file?

On a large screen, the word "LaravelProject" and its links have ample space which I prefer. https://i.sstatic.net/AcnQ3.png A newly created Laravel project appears differently on a small screen. https://i.sstatic.net/O4fBq.j ...

What is the best way to stop vertically aligned elements from overlapping the navbar in Bootstrap 4?

I have successfully aligned my content vertically, but I encountered an issue when resizing the browser window vertically - the aligned content overlaps with the navbar. What I want is for the vertically aligned content to stop at the navbar. I have exper ...

Is there a way to retrieve the widths of several <span> elements at once?

Having a few <span> elements generated dynamically, I need to find out their combined width. Wrapping them in a <div> and using alert($("#spanWrap").width()); resulted in the container's width instead of that of the <span> elements. ...

Tips for dynamically displaying images in both horizontal and vertical orientations

I would like to showcase images in the imageList. Here is what I want: AB CD How can this be achieved? It's not a matter of being even or odd Perhaps the list could look something like this: ABCDE FG I simply want a new row or display:block when ...

Tips for adjusting custom spacing margins within Material UI Grid

Is there a way to adjust the spacing between Grid items in Material UI? Here's the code I currently have: <Grid container spacing={1}> <Grid item xs={6}>Node 1</Grid> <Grid item xs={6}>Node 2</Grid> ...and so ...

Striving to make edits that will reflect changes in the database, however, I continue to encounter error CS0123 stating that there is no matching overload for 'Insert_Click' with the delegate 'EventHandler'

Welcome to the front-end of my webpage: <div class="div"> <asp:Button style="background-color: #007aff; width: 100%; padding: 5px" Text="SAVE" OnClick="Insert_Click" ID="InsertID" runat="s ...

My HTML grid table is not being properly rendered by the JSON data

I'm currently facing a challenge with rendering my HTML grid table in Angular using JSON data retrieved from a MySQL database. I would greatly appreciate any assistance or guidance on how to solve this issue. View the output of the Angular code here ...

Methods like jQuery blink(), strike(), and bold() offer dynamic ways to manipulate

I'm currently tackling an inquiry. The code I crafted seems to be functioning without any issues: (function () { if($('#target:contains("bold")')) { $('#target span:first').css('font-weight','bold ...

Attempting to design a customized dropdown navigation feature using HTML

I am having some trouble creating a dropdown menu that functions properly. Here is the code I have written: <div> <H1><FONT="TIMES ROMAN" FONT-COLOR="BLUE" > SELECT A Subject:</H1> <select id ="dropDownId"> <!-- as ...

Pseudo-element fails to display in React when applied to a paragraph tag, even with display block property set

I am experiencing an issue where the pseudo element ::after is not appearing in my browser. I am currently working with React.js and Material UI's makeStyles. Here is the code snippet causing the problem: modalTitle: { borderBottom: '2px sol ...

Get the large data file in sections

I ran a test script that looks like this: async function testDownload() { try{ var urls = ['https://localhost:54373/analyzer/test1','https://localhost:54373/analyzer/test2'] var fullFile = new Blob(); for (le ...