Adjust multiple components at once

I'm working on creating a "textarea" with a toolbar that displays rich text content based on the HTML content stored in the background textarea. Here is an example of the HTML structure:

    <div class="primary-content">
        <div class="textarea-with-nav" id="outerWrap">
            <div class="navbar">
                <ul>
                    <li><a href="#">test1</a></li>
                    <li><a href="#">test2</a></li>
                    <li><a href="#">test3</a></li>
                </ul>
            </div>
            <textarea id="layer1"></textarea>
            <textarea id="layer2"></textarea>
        </div>
    </div>

The current CSS style for this layout is as follows:

html, body {
    margin: 0;
    height: 100%;
}
.primary-content {
    padding-top: 55px;
}
.navbar {
    grid-area: header;
    overflow: hidden;
    background-color: #333;
    width: 100%;
    z-index: 1;
}
.navbar.site-nav {
    position: fixed;
    top: 0;
}
.navbar ul { list-style-type: none; }
.navbar ul li { display: inline; }
.navbar ul li a {
    color: white;
    padding: 8px 16px;
    text-decoration: none;
}
.navbar ul li a:hover {
    background-color: #555;
    color: white;
    height: 100%;
}
.textarea-with-nav {
    transform: translate(50%);
    width: 400px;
    height: 300px;
    position: relative;
    border-radius: 5px;
    border: 1px solid #ccc;
}
.textarea-with-nav > .navbar {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}
.textarea-with-nav > textarea {
    border: none;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    width: 396px !important;
    height: 246px !important;
    resize: none;
}
.textarea-with-nav > textarea:focus { outline: none; }

#outerWrap {
    position: relative;
    z-index: 0;
}

#layer1 {
    position: absolute;
    z-index: 1;
}

#layer2 {
    position: absolute;
    z-index: 2;
}

I want the two textareas to resize simultaneously when the front textarea, layer2, is resized. Additionally, if I resize the textareas horizontally, the navbar should also stretch to match the new dimensions of the textareas.

Does anyone know how to achieve this? Will this require JavaScript or is CSS sufficient?

Answer №1

It seems like your ultimate objective is:

  • To develop a feature-rich text editor with specific parameters:
    • Containing two textarea elements
    • Incorporating a single tool-bar.
      • Clarification that this should not be mistaken for a nav-bar.

Although the details in your inquiry are slightly vague, it appears that the following criteria apply:

When one textarea is resized, the adjacent one should adjust accordingly, along with the toolbar.

Based on a comment you made on a different response, it seems you prefer the textareas to be arranged vertically rather than horizontally.

It is assumed that modifying the width of the textarea affects the other one, not the height.


Here is a basic example utilizing pure CSS to guide you in the right direction. It may have some glitches (resizing textareas can be tricky), but since this question is quite similar to your earlier one, I recommend exploring the CSS calc function.

Best wishes as you work on perfecting your text editor!

Answer №2

It appears that all your textarea elements have a style of position: absolute, which may not be functioning as expected.

Consider using flex instead:

.primary-content {
  position: relative;
  z-index: 0;
  height: 480px;
  width: 640px;
}

.navbar {
  grid-area: header;
  overflow: hidden;
  background-color: #333;
  width: 100%;
  z-index: 1;
}

.navbar.site-nav {
  position: fixed;
  top: 0;
}

.navbar ul {
  list-style-type: none;
}

.navbar ul li {
  display: inline;
}

.navbar ul li a {
  color: white;
  padding: 8px 16px;
  text-decoration: none;
}

.navbar ul li a:hover {
  background-color: #555;
  color: white;
  height: 100%;
}

.textarea-with-nav {
  transform: translate(50%);
  width: 400px;
  height: 300px;
  position: relative;
  border-radius: 5px;
  border: 1px solid #ccc;
}

.textarea-with-nav>.navbar {
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

.textarea-with-nav>textarea {
  border: none;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  width: 100%;
  height: 100%;
  resize: both;
}

#layer1 {
  z-index: 1;
  height: 100%;
}

#layer2 {
  z-index: 2;
  height: 100%;
}
.flex{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.insideTextArea{
  width: "50%"
}
<div class="textarea-with-nav" id="outerWrap">
  <div class="navbar">
    <ul>
      <li><a href="#">teste1</a></li>
      <li><a href="#">teste2</a></li>
      <li><a href="#">teste3</a></li>
    </ul>
  </div>
  <div class="flex">
     <textarea id="layer1" class="insideTextArea"></textarea>
     <textarea id="layer2" class="insideTextArea"></textarea>
  </div>
</div>

While I haven't tested this myself, modifying the styles as described above could potentially resolve the issue.

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

Tips for managing fetch API AJAX response in React

Currently, I am working on an AJAX request using the fetch API in React, specifically inside the componentDidMount() function. The request seems to be successful as the result is being logged in the console. However, I am facing an issue with accessing th ...

Reduce the number of divs on a webpage while incorporating animated transitions

I've been attempting to incorporate an animation on the width property for my div .panels. I've tried using transition-property in CSS and also with .animate() in jQuery, but unfortunately, it doesn't seem to be working. I also noticed that ...

Manage and update events in the Angular Bootstrap Calendar

For the past few days, I have been working on integrating a calendar into my project. I decided to repurpose an example provided by the developer. One issue that I've come across is related to the functionality of deleting events when using the dropdo ...

Is there a way to create more space between the cards in my project?

Could someone help me with separating the cards in my HTML project? I'm new to coding and struggling with this. The cards are too close together for my liking, is there a way to adjust the spacing? Below is the code I currently have: * { box-sizin ...

Is there a way to prevent the p-checkbox from taking focus, thus avoiding the screen from jumping to center on the p-checkbox?

I'm working with p-checkbox components inside a table and I'm trying to prevent the component from receiving focus and centering the view when clicked. This is the code in my HTML: <p-checkbox name="select-{{rowIndex}}" [(ngModel)]=" ...

The video in the TypeScript code within the Owl Carousel is not displaying properly - only the sound is playing. The video screen remains stationary

I recently updated my query. I am facing an issue while trying to play a video in Owl Carousal with a button click. The video plays sporadically, and most of the time it doesn't work properly. When playing without the carousel, a single video works fi ...

What is the method for obtaining the total number of steps taken in a day (pedometer) exclusively for the current day on the

Is there a way to retrieve the total steps count for the current day only? The tizen.humanactivitymonitor.setAccumulativePedometerListener function allows me to access the accumulativeTotalStepCount, which represents the cumulative walking and running ste ...

Is it important to minify JavaScript npm packages?

In my journey of creating numerous npm packages, I find myself pondering over the question: "Should JavaScript npm packages be minified?" I have always held the belief that minifying already minified code is not a good practice, which is why I have refrai ...

Ways to incorporate a custom JavaScript function that is activated by an external server system?

I'm currently exploring a JavaScript widget that needs to operate within specific constraints: The widget initiates a request to a third-party server using a callback URL The third-party server pings the callback URL after a set period, triggering a ...

What is the best way to transform a date such as '2021-06-01T11:17:00-07:00' into the corresponding date and time for a specific location (New Delhi) using JavaScript?

How can I convert a date in the format '2021-06-01T11:17:00-07:00' to ISO standard? What does this format represent? let date = new Date('2021-06-01T11:17:00-07:00'); console.log(date.getHours() + " :" + date.getMinutes()); I ...

Is it a Mozilla Firefox glitch or something else?

After writing the code, I noticed a bug in Firefox and a small bug in Chrome. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ...

Ways to manage properties that are non-existent

Whenever vm8 encounters a property that doesn't exist, it will display an error message like this: Cannot read property 'value' of null. For example, when passing an id that doesn't exist: var pass = document.getElementById('pass ...

Is there a way to display session messages in a CakePHP .ctp file?

There is a button on a view page that requires validation to check the type of user clicking it. We want to restrict certain users from clicking this button and making changes. To achieve this, we are checking the session ID at the time of button click. If ...

CSS: The element's relative size causes the background image to vanish

I am facing an issue with displaying a background-image that is 800x480 pixels. The background image appears when the element has a fixed size, but not when the element has a relative size or a max-width. Functional CSS code: .audio-container, .settings- ...

What is the best method to assign a CSS class to specific nodes within a TreeView using CodeBehind?

I need to apply unique styling to certain nodes in the codebehind. Within my TreeView, parents have two categories of children. One category matches the parent type (e.g. organizationalUnit), while the other does not (e.g. organizationalMembers). I aim t ...

Creating dynamic JSX content in NextJS/JSX without relying on the use of dangerouslySetInnerHTML

I have a string that goes like "Foo #bar baz #fuzz". I'm looking to create a "Caption" component in NextJS where the hashtags become clickable links. Here's my current approach: import Link from "next/link"; const handleHashTag = str => st ...

css avoiding code duplication with nested classes

I created a custom CSS class named button.blue: button.blue { background-color: blue; ... } button.blue:active { background-color: darkblue; ... } button.blue:hover { background-color: lightblue; ... } To implement this class, I use the following code: ...

Dynamic Label Editing on ASP Page Using Master Page

I am working on an ASP page with a Masterpage element on my website. The specific functionality I am trying to implement involves having multiple labels with an edit hyperlink next to each one. When the user clicks on the Edit hyperlink, I want the label t ...

Using VueJs, create a dynamic css class name to be applied inline

Can VueJs handle a scenario like this? Html: <div class="someStaticClass {{someDynamicClass}}">...</div> JS: var app = new Vue({ data: { someDynamicClass: 'myClassName' }, mounted: function() { ...

Designing personalized visual elements that can be colored using HTML and CSS

https://i.sstatic.net/wILgJ.jpg I have a custom graphic that needs to be filled with three different colors. Each color will fill from 1% to 100%. For example, the blue color should fill from the legs to the head (1-100%), the red color should fill from t ...