Using a zoom background image in an HTML document without any accompanying text

I am trying to create a zoom effect on a background image without affecting the text overlaying it.

Here is the CSS code:

.page1-box {
    width: 1200px;
    height:800px;
    overflow:hidden;
}
.page1 {
    width: 100%;
    height: 100%;
    background: url('../images/home_page.jpg');
    background-position:center center;
    background-size:cover;
    transform:scale(1);
    transition:all 5s ease-in;
}
.page1.zout {
    transform:scale(1.2);
}

And here is the JavaScript code:

setTimeout(function () {
    $('.pag1').addClass('zout');
}, 100);

Finally, this is the HTML Code:

<section class="page1">
     <div class="page_container">
        <div class="text">
            sample text here
        </div>
     </div>
 </section>

Currently, when I run this code, both the background image and the text get transformed. Is there a way to isolate the zoom effect only to the background image?

Any help would be appreciated.

Answer â„–1

Here are a couple of methods to achieve a zooming effect:

Method One: Using background image

 <div class="page-bg"></div>

Create an empty div within your section element and set a background image with defined height and width. Although not the most semantic markup, you can give it a try:

.page-bg {
    width: 100%;
    height: 100%;
    background: url('https://pbs.twimg.com/media/B6mjgHuCIAEgyli.jpg');
    background-position:center center;
    background-size:cover;
    transform:scale(1);
    transition:all 5s ease-in;
    z-index: -1;
    position: absolute;
}

Check out the JSFIDDLE for this effect.

Method Two: Semantic approach Instead of using images as background in CSS, directly include them in your HTML markup and adjust their positioning with parent elements through CSS. This provides more flexibility.

<div class="page1-box">
    <section class="page1">
        <img src="../images/bg-img.jpg" alt="bg">
        <div class="page_container">
            <div class="text">sample text here</div>
        </div>
    </section>
</div>

The CSS for this method is similar to the first one, so I won't repeat it here. Experiment with it and if you encounter any issues, feel free to leave a comment below. :)

Answer â„–2

Here are two solutions you can try:

'Zoom' in on your background image by adjusting the background-size property:

.page1.zout {
     background-size: [VALUE];
}

Experiment with different values for 'Value' until you achieve the desired size.

Move the text outside of the transformed element:

<section class="page1">
     <div class="page_container">
     </div>
 </section>

 <div class="text">
      Enter sample text here
  </div>

By moving the text outside of the section, the transformation will no longer affect it. However, you may need to adjust the positioning of the text since it is now separate from the page structure.

If placing the text outside the section compromises the semantic structure of your DOM, consider creating a separate element within the section for the zoomed background:

<section class="page1">
     <div class="background-to-transform">
     </div>
     <div class="text">
         Enter sample text here
     </div>
 </section>

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

Looking to dynamically update a date variable based on user selection from a drop-down menu in PHP

I am currently working with a PHP file (index.php) which features a title bar displaying the date in the format (MM YYYY). The dates themselves are extracted from another PHP file named latest_update.php. Within the latest_update file, the dates are specif ...

What is the best way to place a button within a line of text

I am trying to achieve a layout similar to this: -------------------button------------------ I can add text inside the line, but it doesn't look good when I add a button. Any suggestions on how I can improve this? ...

Inserting Multiple Inputs

I have a unique application interface that is structured in the following manner: The rows within the application consist of either group headings (displayed as rows with single inputs) or ingredient forms (comprising a small input field, followed by a se ...

Ensure that clicking on an element closes any currently visible elements before opening a new element

Take a look at my code snippet below. I am working on creating multiple clickable divs that reveal different content when clicked. However, the issue I am facing is that currently, both content blocks can be displayed simultaneously. My goal is to have onl ...

Inspecting element value on a website

On a marketplace website, I extracted the attribute (capacity_gold) from a table. Since the values are dynamic and constantly changing, I aim to develop a basic script that will notify me when the attribute value exceeds 100. The current value of the attr ...

Excessive width of Bootstrap container

Encountering a rather simple issue: the bootstrap container inside my navbar is too wide, causing an unwanted horizontal scrollbar as it expands the body. You can view the problematic page here. The theme used for this site can be found here. What's ...

I am looking to switch from a hamburger menu to a cross icon when clicked

Hey there, I'm currently working on a Shopify website and trying to make the hamburger menu change to a cross when clicked. I've been experimenting with different methods, but unfortunately haven't had any success so far. I have two images â ...

Is there a way to locate a parent class starting from a child class, and subsequently track down another child class from the parent?

I am facing a challenge with multiple tags structured like this: <div class="A"> <div class="B1">...</div> <div class="C1">Hello World!</div> <div class="C2">World Hell ...

Accordion not appearing on the webpage

I'm currently working on implementing a helpful feature at the bottom of my webpage to assist users with navigation. I was thinking of using an accordion as a dropdown helper, but I've been facing some challenges getting it to function properly. ...

Tips for applying multiple style properties to an element using JavaScript

I have been experimenting with different versions of this code in an attempt to modify a specific element for a coding challenge, but none of them seem to successfully change multiple styling properties of the element upon clicking on a button. Would great ...

Top method for uploading outside materials

My website is running smoothly with fast load speeds on a one-page layout, but I want to ensure it stays that way by preventing slow loading times. Right now, I have a portfolio page with tiles that pop up an overlay and slider when clicked. The current m ...

Conceal a script-generated div using CSS styling

Using the code below, you can create an HTML chatbox with a link in the top panel and multiple child divs. The structure is as follows: cgroup is the parent of CBG, which is the parent of CGW, and CGW is the parent of the div I want to hide. How can I u ...

Creating Layouts with Bootstrap 3

I'm exploring the codepen below in an attempt to mimic the appearance of the image provided consistently across all screen sizes. However, there are two issues that I am encountering - firstly, the green numbers on the first line which represent the d ...

Utilize API or alternative methods for analyzing Instagram data

My master's thesis requires me to dissect multiple Instagram profiles, each containing over 1000 posts. I am in need of a comprehensive list including the following details: Type of Post (Image, Multi Image, Video) Description Likes Comments (total c ...

Iterating through data to showcase vertical columns for a specific time span of 3 years, highlighting only the months with available data

If data has been available for every month over the past 3 years, I need it to be displayed in a specific format. You can refer to this example fiddle for reference: https://jsfiddle.net/bthorn/ncqn0jwy/ However, there are times when certain months may no ...

How can I achieve the functionality of an image changing when clicked and going back to its original state upon release with the help of HTML

I am facing an issue with styling an element to look like a button and function as a clickable link. My goal is to create a visual effect of a pressed button when it is clicked, while also loading the target page. For reference, here is a (non-working) J ...

The Epub text box feature is malfunctioning

I have a quiz task in an epub format where users need to enter their answers in a text box after reading the question. However, I am facing an issue where the text box does not display the keyboard for typing the answer. Is there a solution using javascr ...

Shades of Grey in Visual Studio Code

Whenever I use VSC, I notice these odd grey boxes that appear in my editor. They seem to be dynamic and really bother me. Interestingly, switching to a light theme makes them disappear. However, I prefer using a dark theme and haven't been able to fin ...

Customizing CSS for Various Browser Sizes

I have a query regarding window-dependent CSS. It seems to be a common issue, but I am facing some difficulties with it on Wordpress. I am currently using the script recommended by Nettuts. My goal is to apply different CSS styles based on the user's ...

Clear the default content from a Bootstrap modal form

Each object from the 'myData' array is being used to create divs. Additionally, there is a bootstrap modal with a form for adding an external object. Once this external object is added to the array 'myData', it will be displayed in the ...