Enhancing buttons with CSS styles

Check out the demo

  .special_button:active
  {
    box-shadow: 0px 3px 3px -2px #777;
    padding: 3px;
    width:80px;
  }

  .button_container
  {
    border: 1px solid;
    width: 100px;
    padding: 7px;
  }

I'm experimenting with creating special button-pressing effects without affecting the container. I want to only reduce the width and height of the button when pressed, not the entire container. Any suggestions?

Answer №1

To adjust the height of the .common_button_container, you may simply set it by including height: 30px;.

Answer №2

If you don't specify the size of the container, follow this guidance:

.custom_button_placeholder
  {
  background-color: transparent;
    color: transparent;
  }

.custom_button
  {
  position: absolute;
  }

.custom_button:active
  {
    box-shadow: 0px 3px 3px -2px #777;
    padding: 3px;
    width:80px;
  }

  .custom_button_container
  {
    border: 1px solid;
    width: 100px;
    padding: 7px;
  }
<div class="custom_button_container">
  <div class="custom_button">Submit</div>
  <div class="custom_button_placeholder">Submit</div>
</div>

The custom_button is positioned as absolute; while custom_button_placeholder is not. Therefore, custom_button_placeholder sits behind the original item, setting the container size, but custom_button does not affect it further.

To enhance the styling, consider adding a transition:

-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;

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

The radio button functionality is not functioning properly as intended

Having trouble with the current code that utilizes HTML and JavaScript. There is an HTML table on the page with a radio button and 4 other fields. The table is generated dynamically when values are set through the controller. It is also possible to add new ...

Animation does not trigger before switching pages

I'm attempting to create an animation that occurs before the page transitions. After finding a jQuery script on this site and tweaking it to match my HTML, I realized the code works in a fiddle but not on my actual page. Any assistance would be greatl ...

Changing an HTML5 attribute with the power of jQuery and ajax

I'm working on a rails view where I have a div that displays a collection of users: <div id="users" data-current_page="<%<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="635e2316100611104d00161111060d7">[email  ...

How can I modify the color of the text in a Contact Form 7?

I am looking to update the text color in my Contact Form 7 code provided below. -------------- <label> Your name [text* your-name class:accent class:form-fluid ] </label> <label> Your email [email* your-email class:form-fluid] </lab ...

What is the best way to conceal HTML5 dividers if there is a custom attribute present on at least 1 selected item?

In my HTML form, I have multiple checkboxes and I want to hide certain dividers only if at least one checked checkbox has a custom HTML5 attribute called "terminator". Otherwise, I want to display the dividers. To achieve this, I attempted to use the chan ...

Guide on incorporating an SVG file according to the user's role within an Angular application

How can I dynamically import an SVG file based on the user's role, whether they are an admin or a regular user? Currently, my code in layout.ts looks like this: <div class="layout-body h-100 "> <ng-container [ngTemplateOutlet]=&q ...

Responsive Bootstrap column with a fixed-width card

My Bootstrap-card is currently not adjusting its width properly. I want the card to occupy the full width of the column it's in. Below is a snippet of my code and a screenshot showing the current width along with the desired width indicated by a blue ...

Using the power of Javascript's jQuery library: the fantastic ".on()" Event Handler

I'm encountering an issue with the Jquery Event Handler ".on()". On my home page, I have a Favorite button on each post. If the post has not been favorited: li appears inactive Event 1 is triggered If the post has been favorited: li appears act ...

The animation for the CSS background image simply refuses to cooperate

My goal is to create a CSS background animation using the Body tag. Below is the code I am currently using: body { animation-name:mymove; animation-duration:5s; animation-direction:alternate; animation-iteration-count:infinite; -webkit-animation-name:mymo ...

utilizing the value within the useState function, however, when attempting to utilize it within this.state, the tab switching feature fails

I am struggling to implement tab functionality in a class component. Even though I'm using this.state instead of useState, the tab switching is not working correctly. I have read the following articles but still can't figure it out: http ...

Using jQuery, add an h1 tag to the body element with the ID "home", and an h4 tag for every other body

Hello everyone, I've been utilizing a PHP include to add my header section and I'd like to have my logo enclosed in an h1 for the homepage, and an h4 for the other pages. The homepage is identified by a body ID of "home" while each remaining page ...

The slider feature is malfunctioning on Internet Explorer version 8

Hello everyone, I am facing an issue with my website located at: http://210.48.94.218/~printabl/ When viewed in IE 8, the slider is not functioning properly (it is showing collapsed between the menu and product images section) The theme used for my site ...

Problem with the visibility of Grid Layout

Trying to create a Quiz web application, I want the quiz container to be hidden with the CSS property display: none; until I click "start game." Once the game starts, the container should change to display: grid;. However, when I try to reveal the div, it ...

Tips for making a background image responsive using ng-style in AngularJS

Can anyone assist me in fixing the gap space issue in a responsive view with an attached jpg background image? Follow this link for more details: enter image description here ...

Postpone the execution of the toggleClass function

I have a tab that, when clicked, fades in to reveal content loaded with AJAX. However, the content loads immediately upon clicking the button. I attempted to use toggleClass with delay, but it was unsuccessful. How can I effectively delay the loading of t ...

What is the best way to retrieve the initial cell from a row that the user is currently hovering over?

Is there a way to extract the first cell from a row when a user hovers over it and then clicks a specific key combination? (considering using jQuery) I have a table set up similarly where placing the mouse over a tr and pressing ctrl+c will copy the ID t ...

How to change a CSS class when clicking with AngularJS

I want to implement a feature where the CSS class of a div element changes when clicked. The default class should be 'input-large', and on click, it should change to 'input-large input-active'. This change should occur when clicking on ...

Creating dynamic selection options in an HTML select tag using PHP

When retrieving category and sub-category information from an API json file, the API returns category objects with a "parent" attribute. Main category objects have a parent attribute equal to 0, and sub-category objects have the parent attribute equal to t ...

What is the purpose of using multiple css classes together?

In my project, I have implemented CSS modules which allow me to use multiple classes. The variable open is a boolean that determines whether or not the Paper should shift. <Paper className={`${classes.paper} ${open && classes.paperShift}`}> Questio ...

An individual browsing through a different user's profile on the Django platform

I'm trying to create a feature where one user, A, can click on the profile picture of another user, B, and be redirected to B's profile automatically. Any suggestions on how I can achieve this? Take a look at my HTML code where I mentioned someth ...