Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css image won't show up

Tags:

html

css

I want to do a responsive design and it would be easier to add 2 different images in CSS then HTMl, but the image won't show, tried sizes and different styles, moved the image from image folder to the html css folder, nothing works, here is my code:

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

                main {
                width: 100vw;
                height: 100vh;
                display: flex;
                flex-direction: column;
                background-color: var(--main-background);
                position: relative;
                 }

               .card {
               display: flex;
               flex-direction: column;
               width: 200px;
               height: 400px;
               background-color: var(--card-background);
               position: absolute;
               top: 50%;
               left: 50%;
               transform: translate(-50%, -50%);
               }

               .image {
               background-image: url(./image-header-mobile.jpg);
               width: 100%;
               }



               <body>
                 <main>
                  <section class="card">
                   <div class="image"></div>
                   <div class="info"></div>
                  </section>
                 </main>
               </body>
like image 216
MarniD Avatar asked Jan 29 '26 17:01

MarniD


1 Answers

Add height: 100%; to your .image CSS.

Because your div is empty, the image isn't shown. Your div doesn't have any height.

.image {
  background-image: url("image.png");
  width: 100%;
  height: 100%;
}
like image 76
ChenBr Avatar answered Feb 01 '26 10:02

ChenBr