An adaptive image-based menu design that adjusts based on screen size

Although I can get it to function properly, the trouble arises when I attempt to resize it for responsiveness, resulting in a strange scaling issue. Essentially, I want the images to remain at their natural size and align next to each other seamlessly without any gaps. Additionally, the text should be centered.

I've compiled everything into a JSFiddle with a relevant GIF. The GIF is crucial for understanding my dilemma.

I appreciate any assistance as I'm unable to solve this on my own.

Your help in advance is greatly appreciated.

<div class="aktivnostiList">

<div class="spacer">
</div>

    <div class="coverRevija">
        <img class="covers" src="file:\\C:\Users\andre\Desktop\karolin\web\hr\projekti\revija\revijacover.jpg">
        <div id="linkRevija"><h3 id="emphasis"><a href="#">Modna revija</a></h3></div>
    </div>

    <div class="spacerSmall"></div>

    <div class="coverCajanka">
        <img class="covers" src="file:\\C:\Users\andre\Desktop\karolin\web\hr\projekti\cajanka\cajankacover.jpg">
        <div id="linkCajanka"><h3 id="emphasis"><a href="#">Čajanka</a></h3></div>
    </div>

    <div class="spacerSmall"></div>

    <div class="coverIzlozba">
        <img class="covers" src="file:\\C:\Users\andre\Desktop\karolin\web\hr\projekti\izlozba\izlozbacover.jpg">
        <div id="linkIzlozba"><h3 id="emphasis"><a href="#">Izložba</a></h3></div>
    </div>

.aktivnostiIntro{
width: 75%;
height: auto;
margin: auto;
margin-top: 100px;
text-align: center;
}

.covers{
width: 100%;
position: absolute;
z-index: -1;
left: 0;
}

.aktivnostiList{
text-align: center;
}

.coverRevija{
line-height: 227px;
}

.coverCajanka{
line-height: 227px;
}

.coverIzlozba{
line-height: 227px;
}

Answer №1

It appears that your images are scaling proportionately when adjusting the width, causing the height to also decrease in order to maintain the image's aspect ratio. If you wish for the images to retain their height while resizing, consider switching from <img> tags in the HTML to using background-images in the CSS. Here is an example: https://jsfiddle.net/9rgk6nuo/7/

HTML

<div class="aktivnostiList">

    <div class="spacer">
    </div>

        <div class="covers-wrapper coverRevija">
            <div id="linkRevija"><h3 id="emphasis"><a href="#">Fashion Show</a></h3></div>
        </div>

        <div class="spacerSmall"></div>

        <div class="covers-wrapper coverCajanka">
            <div id="linkCajanka"><h3 id="emphasis"><a href="#">Tea Party</a></h3></div>
        </div>

        <div class="spacerSmall"></div>

        <div class="covers-wrapper coverIzlozba">
            <div id="linkIzlozba"><h3 id="emphasis"><a href="#">Exhibition</a></h3></div>
        </div>

</div>

CSS

.aktivnostiIntro{
    width: 75%;
    height: auto;
    margin: auto;
    margin-top: 100px;
    text-align: center;
}

.covers-wrapper {
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
}

.aktivnostiList{
    text-align: center;
    }

.coverRevija{
  background-image: url('http://placehold.it/1200x300'); //change this to your image source
    line-height: 227px;
}

.coverCajanka{
  background-image: url('http://placehold.it/1200x300'); //change this to your image source
    line-height: 227px;
}

.coverIzlozba{
  background-image: url('http://placehold.it/1200x300'); //change this to your image source
    line-height: 227px;
}

Answer №2

Give this a shot to enhance your CSS within the .covers class

`  .covers{
         min-width: 100%;
         height:100%;
         position: absolute;
         z-index: -1;
         left: 0;
     }`

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

Move a Div to be positioned directly underneath another DIV

There are two DIV elements, one with an absolute position in the lower left corner of the main DIV. The second DIV is hidden and only displayed when clicking on a link. I want the second one to appear just below the first one, but because the first div&ap ...

What is the best way to upload multiple files in Laravel using Guzzle?

Currently, I am facing an issue while trying to upload files to an external server using JWT for authentication. Here is a snippet of my form: <form action="{{ route('operations.photos-for-families.upload', [$operation, $current->index ...

AngularJS: Utilizing bold text to enhance the separation of concerns between controllers and templates

In my AngularJS version 1 application with Ecmascript 6, I have a requirement to display a string where one part is in normal weight and the other part is bold. For instance, consider the following scenarios: Will start now Will start in 6 minutes Will ...

Incorporating orientation settings within a media query using MUI

In my current project, I am utilizing MUI in conjunction with React. To specifically style the iPad resolution using MUI breakpoints, I have implemented the following code snippet: contentBox:{ width:"10%", paddingLeft:"10p ...

Looking to modify the HTML layout in order to be compatible with a specific script

Utilizing a form validation script with required:true data-validation will stop the form from submitting and highlight invalid fields in red by adding "has-error" to the parent container when the user submits the form. In the code snippet below, "has-erro ...

Enhancing design precision from Figma to flawless pixels

I'm facing the challenge of converting a figma design into an HTML and CSS template with a fixed dimension of 1440px. I'm unsure about where to begin coding in terms of screen size - should I start at 1440px and scale down/up, or begin with mobil ...

Struggling to create horizontal buttons for my design

Does anyone have any suggestions for fixing my navigation bar? I attempted to create it myself, but I'm struggling to make everything function properly. https://i.stack.imgur.com/h4yA1.jpg Below are the images of the button in all three states: htt ...

The autoComplete feature in my ReactJs form is not functioning properly

I have a form in React where I would like to enable auto complete so that when users input the same value again, it will be suggested as an auto complete option. Below is the code snippet: <form className={classes.container} noValidate> <Grid c ...

Unable to display background image on Webpage due to blank page issue while uploading it with HTML and CSS

I've been attempting to build a webpage with an image as the background, but I seem to be facing some issues. Instead of seeing the desired image, all I get is a blank white page. The folder named "images" is located in the same directory as my HTML a ...

Angular routing is failing to redirect properly

After creating a sample Angular app, the goal is to be redirected to another page using the browser URL http://localhost:1800/demo. The index.html file looks like this: <!doctype html> <html lang="en"> <head> <title>Sample Ang ...

What is the best approach to retain a user's selection for dark mode?

I have created a small website to showcase my work, but I'm struggling to figure out how to make the website remember a user's choice of dark mode. After searching on Stack Overflow, I came across suggestions like using cookies or localStorage. ...

Navigating through each element of an array individually by using the onClick function in React

I'm currently working on a project that involves creating a button to cycle through different themes when pressed. The goal is for the button to display each theme in sequence and loop back to the beginning after reaching the last one. I've imple ...

Converting Milliseconds to a Date using JavaScript

I have been facing a challenge with converting milliseconds data into date format. Despite trying various methods, I found that the solution provided in this link only works for a limited range of milliseconds values and fails for higher values. My goal is ...

Retrieve information from the text input field and proceed with the action outcome

Currently, I am in the process of developing a form on an asp.net website. The objective is to have users land on a page named Software, where two variables are checked for empty values upon loading. If the check reveals emptiness, the Software View is ret ...

CSS opacity is currently not working as intended

Why doesn't the opacity work here? I've tried using hex and rgba colors, but nothing changes. Even adding classes to tr and td didn't help... First attempt: .done{ background-color: rgba(0,175,51,5); color:white; opacity: 50; ...

The React Bootstrap modal refuses to fully close no matter how many times I click away or even on the close button

I am facing an issue with a modal in my React component. When I open the modal, it does not completely close when I try to click away or hit the close button. The backdrop disappears but the modal itself remains on the screen. (Screenshots attached for r ...

What is the best method for style.scss to communicate with style.css - should it be through @import, --watch,

As I observe the use of @import with mixins and partials in the code, I find myself puzzled as to why the programmers did not simply write @import style.css. Instead, they imported Susy, bourbon, vendors, utilities, and bases. It's a bit confusing to ...

What is the process for turning off bootstrap form validation?

I am facing an issue with utilizing the default input email validation in my development project. It seems that Bootstrap, which is being used for the website, has its own validation mechanism. Whenever I begin typing in a Bootstrap input field, an error m ...

How can I make JavaScript skip over a specific portion of my HTML code?

I have a script running on all pages of my website. I would like it to continue running on the specific page, but ignore a certain section. For example: <p>process with javascript</p> <p>skip, instruct javascript function to ignore</ ...

How can I modify the appearance of the bootstrap scrollbar with scrollspy?

I'm struggling to modify the color of the scrollbar in Bootstrap scrollspy despite having a functional scrollbar. Here is an example of my code: HTML: <body> <div class="container, scrollbar" id="myScrollspy"> <div class=" ...