Populate a table cell with a div element in HTML

How can I make a div inside a rowspanned table cell 100% high of the cell? Check out this example for reference: https://jsfiddle.net/gborgonovo/zqohw286/2/

In the provided example, I want the red div to vertically fill the yellow cell. Any suggestions on achieving this?

<table>
  <tbody>
    <tr>
      <td rowspan="2" style="background-color: yellow;">
        <div style="background-color: red; width: 200px; height: 100%;">
          Some text
        </div>
      </td>
      <td style="background-color: lightgreen; width: 200px;">
        Row 1.1<br /> Row 1.2<br /> Row 1.3
      </td>
    </tr>
    <tr>
      <td style="background-color: lightblue; width: 200px;">
        Row 2.1<br /> Row 2.2<br /> Row 2.3
      </td>
    </tr>
  </tbody>
</table>

Answer №1

<table style="height: 100%;">
   <tbody>
      <tr>
         <td rowspan="2" style="background-color: yellow;">
            <div style="background-color: blue;width: 150px;height: 80%;">
               Some unique content
            </div>
         </td>
         <td style="background-color: lightgray; width: 180px;">
              New Row 1.1<br />
              New Row 1.2<br />
              New Row 1.3
         </td>
      </tr>
      <tr>
      <td style="background-color:pink; width:170px;">
              New Row 2.1    <br /> 
              New Row 2.2    <br /> 
              New Row 2.3
         </td>
      </tr>
   </tbody>
</table>

Answer №2

Consider this div style:


<div style="background-color: blue; width: 250px; height: 120px; display: flex; justify-content: center; align-items: center">Unique text here</div>

Answer №3

I have made some adjustments to center the content.

UPDATE

After receiving your feedback, I have improved the layout to be more interactive on JSFiddle (link).

td[rowspan] {
  position: relative;
  width: 200px;
}

.fill {
  position: absolute;
  top: 0;
  bottom: 0;
}

.centeredContent {
  display: flex;
  align-items: center;      /* Vertical */
  justify-content: center;  /* Horizontal */
}
<table>
  <tbody>
    <tr>
      <td rowspan="2" style="background-color: yellow;">
        <div class="fill centeredContent" style="background-color: red; width: 200px; height: 100%;">
          Some text
        </div>
      </td>
      <td style="background-color: lightgreen; width: 200px;">
        Row 1.1<br /> Row 1.2<br /> Row 1.3
      </td>
    </tr>
    <tr>
      <td style="background-color: lightblue; width: 200px;">
        Row 2.1<br /> Row 2.2<br /> Row 2.3
      </td>
    </tr>
  </tbody>
</table>

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

Float over Material UI Icon and Text

Currently, I am tackling a React JS Project. My task involves creating a breadcrumb that contains both text and an icon. To accomplish this, I have incorporated a material UI icon. import UpdateIcon from "@material-ui/icons/Update"; ...

I have a question regarding the CSS universal selector

I've been working on developing a website, but I'm having trouble with the universal selector. No matter how many times I try, it just won't work. If you'd like to see an example of what I'm dealing with, check out this link: https ...

Spin a sphere within a semicircle using html and css

I have been working on a project to animate a ball inside a crescent shape using HTML and CSS. You can check out my codepen here. However, I am facing an issue where the ball is currently stuck at the top of the crescent. I would greatly appreciate any as ...

Attempting to update an AJAX field with the returned value, but it only updates after clicking away from it

Image of form utilizing AJAX & JS The current setup involves a maintainer that uses AJAX to update the "Calc" field in response to a number entered in the "Order No" field. The issue is that the "Calc" field does not update immediately after typing in the ...

Tips for creating a responsive background image without excessive scaling:

I'm currently working on a website with a focus on responsibility, and I've incorporated 'waves' SVG images as a background-image. The issue arises when viewing the site on smaller screens, such as mobile devices, where the background a ...

Using a DIV to contain a FileUpload Control in an ASPX page

Scenario: I have an ASPX page (Page A) without a form element, which contains a DIV displaying another ASPX page (Page B) with a FileUpload Control inside a form element. Requirement: Submit the form to upload the file without refreshing or navigating awa ...

Avoiding clashes between CSS styles in web applications

As I work on developing a web application that can be embedded on external websites, one of the challenges I am facing involves constructing dialogues with their own unique stylesheets. This could potentially lead to conflicts if both my dialogue container ...

Modifying the appearance of the search box

I'm looking to customize the appearance of my search box. On Stack Overflow, you'll notice the search box is a perfect rectangle. I want mine to have rounded edges, like an ellipse, rather than being rectangular. How can I achieve this look? Than ...

How does JQuery handle color parsing in text?

Is there a way to automatically parse colors in text and apply them to CSS? For instance, if I type #40464f, I want the color to be caught and included in some CSS styles. I am familiar with how to achieve this by adding markup: <span data-color=""> ...

Working condition may vary depending on the size of the item

I have integrated the Masonry jQuery plugin into my design, but it is not functioning properly. The CSS class mentioned in the documentation only includes: width: 25% For my purposes, I modified it to: width: 24% float: left margin-right: 5px This modi ...

Customize button design with data from API request

I am currently working on a project to showcase the status of multiple servers within a cluster. To achieve this, I have established a status route in my web service that returns 'ok' if the server is functioning correctly and an error message if ...

Occasions focused on the <input type="file"> feature

Looking for a way to write a file input in React that accepts CSV files, validates them, and prevents upload if there are errors? Check out the code snippet below: <CustomInput type="file" id="fileBrowser" name="file" label={filename || 'Choos ...

How to adjust animation timing for various elements during a CSS 3D flip with a delay?

Here is a CSS flip setup that I have been working on in this fiddle: http://jsfiddle.net/6r82fzk6/ The Goal: I am trying to achieve a slower transition for the back element compared to everything else. The idea is to have the child element of the back fac ...

Creating a stylish gradient text color with Material-UI's <Typography /> component

Is there a way to apply a gradient font color to a <Typography /> component? I've attempted the following: const CustomColor = withStyles({ root: { fontColor: "-webkit-linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)", }, })(T ...

javascript issue with showing content on click

I'm currently working on a school assignment where I am using the onclick() function to display information about an object. However, I am facing an issue where the information is not popping up as expected. HTML <!DOCTYPE html> <html> ...

Ways to extract information from a website using the data within a span element

I am struggling to extract the R1200 value from the "one Way drop off surcharge" section. Despite trying different methods, I have not been successful in retrieving this information. My goal is to copy the 1200 value and paste it into an Excel cell. I am f ...

Font malfunctioning on Microsoft Edge and Internet Explorer

Apologies if this seems like a silly question, but I recently imported a font from my computer into a CSS file. While it displays correctly in Chrome, it's not working in Microsoft Edge or Internet Explorer. Unfortunately, I don't have access to ...

file_put_contents - store user-defined variables

When I execute this script, it successfully generates the html page as expected. However, I am encountering challenges in incorporating variables, such as the $_GET request. The content is enclosed in speech marks and sent to a new webpage on my site usin ...

Is there a way to create a dynamic CSS class without relying on the use of IDs?

Is there a way to create a dynamic CSS class without using an ID? $( "#mydiv" ).css( "width", $("#widthtextbox").val() ); $( "#mydiv" ).css( "height", $("#heighttextbox").val() ); I am looking to implement multiple CSS classes for this task. ...

Troubleshooting problems with encoding in Python Selenium's get_attribute method

Currently, I am utilizing Selenium with Python to crawl the drop-down menu of this particular page. By employing the find_elements_by_css_selector function, I have successfully obtained all the data from the second drop-down menu. However, when attempting ...