Is it feasible to customize the css3 resize feature?

I'm curious - is there a way to customize the CSS3 resize property?

div {
  resize: both;
  overflow: auto;
}

Basically, I am looking for a horizontal resize with a vertical bar instead of the default handle. Take a look at the images for reference. Is it possible to achieve something like this using CSS, or do you have any other lightweight alternatives in mind?

Answer №1

Just a heads up: This solution is specifically for WebKit browsers, as attempts with other browsers and their named versions didn't yield successful results.


Code:

If you have an element styled like this in your CSS:

.styled {
    resize:both;
    overflow:auto;
    background:orange; /* just for looks */
}

You can customize the handle by adding WebKit's specific pseudo-selector ::-webkit-resizer:

::-webkit-resizer {
    border: 2px solid yellow;
    background: blue;
    box-shadow: 0 0 2px 5px red;
    outline: 2px dashed green;

    /*size does not work*/  
    display:block;  
    width: 150px !important;
    height: 150px !important;
}

Visual:

http://jsfiddle.net/RaphaelDDL/ryphs/1/

Final thoughts

I tried using ::-moz-resizer on FF22, but it didn't function properly. Therefore, resorting to creating a JavaScript alternative similar to StackOverflow's textarea handle might be necessary.


Extra info

When styling shadow DOM pseudo selectors, avoid combining them into one selector like

::-webkit-resizer, ::-moz-resizer { /*css*/}
, as it will invalidate the entire selection.

  • Here is a reference list of Shadow DOM selectors: https://gist.github.com/afabbro/3759334
  • For more information on Shadow DOM (HTML5Rocks), check here and here.
  • A visually appealing and well-organized list of shadow DOM selectors along with screenshots can be found here
  • Check out the list of Mozilla's selectors (no pseudo-selector for resizer) here

Answer №2

Allow me to present my innovative solution

https://jsfiddle.net/tomoje/x96rL2sv/26/

This solution is compatible with all browsers and devices, responsive to both mouse and touch input without relying on images.

The key is providing the user with a handle that expands to the entire working area, preventing issues when the javascript function slows down due to system overload or other factors.

<div class="cSuwakT" id="idSuwakKontenerGalka"></div>

Answer №3

UPDATE: I discovered a more efficient method to achieve the desired result. It requires less code and provides smoother behavior. This approach is based on the same principle as the previous one and has been successfully tested in both Chrome and Edge browsers.

.resize {
  width: 300px;
  height: 250px;
  position: static; /* default */
  resize: horizontal;
  overflow: scroll;
  padding-right: 10px; /* ensure scrollbar width is clickable */
  background-color: slategray;
  border: 1px solid darkgray;
}

.resize > div{
  position: absolute; /* required */
  box-sizing: border-box; /* prevents content from overflowing .resize with padding */
  padding: 10px; /* customize padding */
  width: inherit;  
  height: inherit; 
  overflow: clip; 
  overflow-clip-margin: content-box;
}

.resize::-webkit-scrollbar {
  height: inherit; 
  width: 10px; 
}

.resize::-webkit-resizer {
  background: silver;
  border: 1px solid darkgray;
}
<div class="resize">
  <div>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    <a href="#">Click</a>
  </div>
</div>

<div class="resize">
  <div>
  </div>
</div>


PREVIOUS VERSION:

This solution utilizes only CSS (specifically webkit) and can be slightly complex. However, it works well if your content is non-interactive. The concept leverages the dependency of resizer size on scrollbar dimensions.

I devised this technique by referencing another answer that explains how to synchronize parent and child element sizes using only CSS.

/* An invisible scrollbar overlays the content when not using a parent container.
You may omit the parent if the content is not interactive.
Using a parent allows for clickable content and avoids unnecessary scrolling,
though it adds complexity overall.

.resize-parent {
  background-color: orange;
  position: relative;
  display: inline-block;
  overflow: clip;
}

.resize {
  background-color: wheat;
  width: 300px;
  height: 250px;
  position: relative;
  resize: horizontal;
  overflow-x: overlay;
  z-index: 0;
}

.resize::before {
  content: "";
  width: 105%;
  height: 105%;
  background: transparent;
  pointer-events: none;
  display: block;
  position: absolute;
}

.resize-content {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
  box-sizing: border-box;
  padding-left: 10px; 
  margin-left: -10px; 
  background: silver;
}

.resize::-webkit-scrollbar {
  height: 250px; 
  width: 10px; 
}

.resize::-webkit-resizer {
  background: cadetblue;
}

.resize::-webkit-scrollbar-corner {
  background: gold;
}
<div class="resize">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  </p>
  <a href="#">Click</a>
</div>

<div class="resize-parent">
  <div class="resize-content">
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliqué ex ea commodo consequat.
    </p>
    <a href="#">Click</a><br>
  </div>
  <div>
    <div class="resize"></div>
  </div>
</div>

Link to demonstration on jsFiddle Hopefully, this explanation proves beneficial to someone.

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

Ensure that any modifications made to an Angular service are reflected across all components that rely on that service

I am currently in the process of replicating a platform known as Kualitee.com, which serves as a test-management tool utilized by QA Engineers. Within Kualitee, users can access multiple projects, each containing various test cases and team members. The ab ...

The ElementNotInteractableException error occurred because the element cannot be interacted with as it is currently not visible, therefore it cannot be manipulated using robot framework

I am encountering an issue with a dropdown menu. When running the script, I receive the error message "ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated." Upon inspecting the HT ...

Can two BootstrapVue tooltips be displayed on a single element with different target settings?

While working in Vue with BootstrapVue, I encountered a problem where the bottom 2 tooltips that I am using both appear on the button targeted by the click to mask this value button. The tooltip containing the SSN is also only appearing on top of the butto ...

My attempts to integrate PHP into jQuery tabs have been unsuccessful

My code seems to be acting strangely, as the PHP code I originally entered in tab 2 has somehow escaped that tab and spread into all the other tabs. This means it is visible in multiple tabs instead of just one. The purpose of this PHP code is to retrieve ...

What is the reason behind the inconsistent behavior of Javascript's Date.getDate() and .setDate() methods?

As a hobbyist coder, I'm facing a challenging problem with building a dynamic HTML/CSS calendar. My goal is to have cells filled in based on today's date. However, when I attempt to add days to fill in another 13 days by looping through HTML elem ...

What is the best way to ensure that my grid remains contained within its designated area?

I need to incorporate a grid of 16x16 or 64x64 into my layout without it overflowing. I'm considering using flexbox, but unsure of the implementation process. My goal is to have the grid resize based on the container size rather than exceeding its bou ...

Vanishing Submenus

I'm experiencing an issue with my navbar and its drop-down menus. When I hover over the submenu, it doesn't stay visible as expected. I've tried different approaches such as using jQuery, the + operator in CSS, and even creating a separate h ...

Discovering specific values for an ID using API calls in Angular (Implementing CRUD Operations in Angular with API Integration)

My current project involves CRUD operations in Angular utilizing the API created in Laravel. I have successfully added and fetched values, but encountered an issue when attempting to update values using their respective IDs. This snippet is from my app.co ...

customizable path settings for sprites using css

Currently, I have a situation where I am using many sprites in my CSS file, and all the image locations are hardcoded within the CSS itself. Now, I am considering moving all these images to a CDN. The problem is that it's quite cumbersome to change th ...

What is the most effective way to add HTML from a dynamically loaded document using AJAX?

I am attempting to attach the information from a .html file to the body of my main webpage. Essentially, I am striving to create a reusable section of html that can be loaded into any page with a basic JavaScript function. Below is the content of my navig ...

I've been attempting to upload application/pdf files, but I'm having trouble. Can you provide me with instructions

'<?php $allowedExts = array("jpg", "jpeg", "gif", "png"); $extension = end(explode(".", $_FILES["file"]["name"])); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/ ...

"Struggling to divide CSS Code with PHP containing nested brackets? Here's how you can tackle it

I'm currently attempting to break down my CSS code stored in variables, but I consistently encounter issues when dealing with media queries or similar elements. While I don't require every single rule to be outlined, I am looking for a solution ...

Cross-Platform: Varied functionalities in disabled input fields (avoiding any direct replication)

My input HTML field is disabled, but I've noticed that in some browsers (such as Chrome, Edge, Internet Explorer, and Opera), it's still possible to select and copy the text. However, in Firefox, this functionality does not work. To test this yo ...

Utilizing CSS3 Animation for enhanced hover effects

I have a setup with two divs. One of the divs expands in height when I hover over it. What I'm trying to achieve is to display text with a fade-in effect somewhere on the screen when I hover over that specific div. Additionally, I want to show another ...

The color of the button in HTML5 will remain constant and not shift

I have several buttons that function like radio buttons - only one can be selected at a time: <button id="btn-bronze" name="btn-bronze" type="button" class="blue-selected">Bronze</button> <button id="btn-silver" name="btn-silver" type="butt ...

Challenges with HTML and Session Handling

It's not functioning properly! <?php session_start(); ?> <p class="username"><?php echo $_SESSION['name']; ?></p> ...

a versatile tool or JavaScript module for dissecting different HTML documents

Looking to develop a versatile wrapper or JS plug-in that can parse HTML content and locate tables within the files, allowing users to generate visual graphs like pie charts and bar graphs. The challenge lies in the fact that the HTML structure is not fixe ...

Tips for minimizing excess white space in Shiny applications

Encountering an issue with plot output in Shiny. When using standard ggplots, the output is correct without any extra white margins. However, when utilizing the "ggmap" package (which also produces ggplot-type outputs), white margins suddenly appear. (Ple ...

Preventing Paste Function in Electron Windows

Currently, I am utilizing Electron and attempting to prevent users from pasting into editable content. While paste and match style remains enabled, the functionality is flawless on Mac devices. However, there seems to be an issue on Windows where regular ...

Creating two dropdown menus from a PHP array

Currently, I have a PHP array structured like this. $food = array ("Fruits" => array("apple","mango","orange"), "vegies"=> array ("capsicum", "betroot", "raddish"), "bisucuits"=>array("marygold", "britania", "goodday")); My task is to create two ...