Tips for utilizing the transform scale feature to expand the contents of a container while keeping the border intact

My goal is to create an animation using the transform scale property to enlarge the content of a box. However, I'm facing an issue where the border of the box also increases in size along with the content. I want only the content to change in size without affecting the border. The code snippet looks like this:

HTML:

<span id='box'>content</span>

CSS:

#box{
  position: absolute;
  left: 240px;
  border-bottom: 1px dashed white;
  width: 120px;
  height: 120px;
  text-align:center;
  font: bold 90px Tahoma;
  color: white;
  cursor: pointer;
  -webkit-transition: -webkit-transform 0.8s;
}
.explode{
  -webkit-transform: scale(1.2);
}

Javascript:

$('#box').addClass('explode');

After adding the explode class, the border of the box also enlarges. Is there a way to resize only the content and not the border?

Answer №1

By including the border in the element, it will also increase along with the size. To prevent this, you can add another span with the class .wrap to contain the border without scaling.

JSFiddle Demo

CSS:

#box{
  position: absolute;
  text-align:center;
  font: bold 90px Tahoma;
  color: white;
  width: 120px;
  height: 120px;
  cursor: pointer;
  -webkit-transition: -webkit-transform 0.8s;
}
.explode{
  -webkit-transform: scale(1.2);
}
#container{
  position: absolute;
  left: 240px;
  width: 120px;
  height: 120px;
  border-bottom: 1px dashed black;
  display:inline-block;
}

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

Locating and updating a subdocument within an array in a mongoose schema

Here is the mongoose schema I created: The userId is a unique number that Okta generates for user profiles. var book_listSchema = new mongoose.Schema({ userId:{type: String, required: true}, first_name: { type: String, required: true}, last_name:{ type: ...

Unable to display a recursive component with Vue3 CDN

I am currently working on a project using Vue3 CDN because the project environment cannot run npm. I have been trying to create a component with html+CDN, but when attempting to create a recursive component, it only renders the top-level element. Is there ...

Having trouble retrieving data from the table with AJAX and CodeIgniter

I am currently developing a comprehensive HRM+CRM system (Human Resource Management and Customer Relation Management). I have encountered an issue while trying to generate an invoice for each customer. I am struggling to resolve this problem and would appr ...

A guide on leveraging refs to set props in React JS

Is it possible to change props in my component using refs in react js? <MyComponent ref={'input1'} name={'input1'} label={interestsName} disabled={ false} onChange={this.myFunction}/> After the onChange event, I call a ...

Is there a way to align an image to the center using the display grid property?

Having some trouble centering an image within a 'display: grid' layout. Screenshot I attempted to use 'align-items' but it didn't seem to work either. Code: <section style="padding-top: 30px;"> <h4 sty ...

Encountering this issue despite confirming the presence of data on the line before! What could be the missing piece here? Error: Unable to access property 'includes' of undefined

Here is the situation.. I'm retrieving data from a database and storing it in an array of objects. These objects represent articles. I am working on implementing a filter system based on categories. The objective is to apply a filter that checks for a ...

Transferring data between two TypeScript files of different Angular 2 components

I have two components, Component A and Component B, which are not parent-child components but I need to pass data from Component A to Component B. Example: Component A.ts has an array of data: myData: [ {'name':'some a','email& ...

Determine whether to create or update with a Node.js API

I have developed a nodejs API where users can add new entries by sending a POST request. If the entry already exists, it should be updated. However, I am facing an issue with the findOne() method from mongoose not triggering the update function as expecte ...

Automatically redirect dynamic URLs to the home page in NextJS

In my NextJS project, I've set up a dynamic page that retrieves and displays blog content. The URL for this page is as follows: https://example.com/blog/[blogId] However, when attempting to access this URL on the production site, instead of landing o ...

Transferring information from a template to a view within Django

I am currently in the process of creating a bus reservation platform using Django. When a user searches for buses on a specific route, a list of available buses is displayed. Each bus in the list has a 'book' button that redirects to a new page c ...

What is the alternative method for applying functions in Angular without utilizing $scope?

For my application, I have opted to use this instead of $scope for storing variables and functions. I am utilizing controller alias in HTML for access. In this scenario, how can I update my view? Should I perform actions similar to $digest() or $apply() u ...

Switching the div to display or hide

Within this block of code, I have successfully implemented functionality to hide and show two separate div elements. However, I am facing a minor issue where the display value of #MSOZoneCell_WebPartWPQ2 needs to be returned to 'table', as it is ...

Error: API Not Responding to Switch Button Commands

I'm encountering an issue with a switch button that is based on an API. Initially, the button changes from "on" to "off" in my view when clicked. However, when I click the button to turn it back "on", it doesn't work. What's even more peculi ...

Transform the entire content with a simple click on input labels

tab3 > brand-sidebar-wrapper > lacquer-type-wrapper > input Whenever I click on the input labels, the .content div moves to the top and leaves a lot of space at the bottom. I have attempted to modify the JavaScript code, but the issue seems to b ...

Using PHP to convert user input from an HTML form into an SQL file within the current folder (Inquiry)

I am seeking an alternative method to create a database without using myphpadmin or MySQL. I have been encountering difficulties in setting them up. Is there a simpler approach where I can use a .html file with a form and PHP code to collect user input and ...

Tips for setting a state as the height for a div in React

I've been involved in a project that involves user input for the height and width of a div to be displayed with specific dimensions. Although the state is successfully being updated, the height of the div remains unchanged. import { useState } from & ...

Guide to retrieving and showing specific items from a DropDownList in a Text box using JavaScript, HTML, and AngularJS

Can someone explain how to extract and select items from a DropDownList and display them in a Textbox using JavaScript/HTML/AngularJS? Here are more details: I have a dropdown list with many items. When I click on an item from the list, it should be dis ...

Tips for ensuring all data is properly set before saving in mongoose

Struggling to update undefined or defined values in Mongoose due to the need to await their assignment. It seems like the code is not saving the data because USER.save() is executed before the values are set. How can I ensure that the data is updated/set ...

What is the best way to include an object within an array that is a property of another object in React.js?

Greetings, I apologize for the somewhat ambiguous title. It was a challenge to find a clearer way to express my thoughts. Currently, I am engrossed in my personal project and have encountered a particular issue. I would greatly appreciate any advice or gu ...

Backgrounds filled by nested <li> elements inside another <li> element

My website features a sidebar menu with nested lists. When hovering over a list item, a sub-list appears. However, I am having an issue where the background color fills the entire sub-list instead of just the first list item. See the images below for clari ...