Tips for accurately aligning a relative p tag within a td

Description: I am trying to prevent text overflow in a table cell and position the text underneath a header without wrapping it under an image. I have tried setting a static width for the image and adjusting the left property, but it is not working as expected.

table.service_section{
    width: 80%;
    margin-left: 10%;
    border-spacing: 10px;}

  table.service_section td{
    border: 2px solid #ccc;
    box-sizing: border-box;
    border-radius:5px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);}

  table.service_section td img{
    display: inline-block;
    width: 50px;
    height: 25px;}
  table.service_section td h5{
    display: inline-block;
    margin: 0;
    padding: 0;
    position: absolute;}
  table.service_section td p{
    display: inline-block;
    position: relative;
    margin: 0;
    top: 0px;
    left: 50px;
    font-size: 10;}
<table class = "service_section">
  <tr>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> <h5>Home Button</h5>
      <p>This is going to be information regarding the service/product which is provided by Odeyale Corporation.</p>
    </td>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> <h5>Home Button</h5>
      <p>This is going to be information regarding the service/product which is provided by Odeyale Corporation.</p>
    </td>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> <h5>Home Button</h5>
      <p>This is going to be information regarding the service/product which is provided by Odeyale Corporation.</p>
    </td>
  </tr>

  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

Answer №1

Give This a Shot:

table.service_section {
  width: 80%;
  margin-left: 10%;
  border-spacing: 10px;
}

table.service_section td {
  border: 2px solid #ccc;
  box-sizing: border-box;
  border-radius:5px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

table.service_section td img {
  float: left;
  width: 20%;
  height: 25px;
}

table.service_section td h5 {
  margin: 0 0 5px 0;
  padding: 0;
  position: relative;
  width: 100%;
  word-wrap:break-word;
}

table.service_section td p {
  position: relative;
  font-size: 10;
  margin-top: 0;
  word-wrap:break-word;
}

.wr {
  width: 75%;
  float: left;
  margin-left: 4%;
}
<table class = "service_section">
  <tr>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" />
      <div class="wr">
        <h5>Home Button</h5>
      <p>This section will contain details about the service or product offered by Odeyale Corporation.</p>
      </div>
    </td>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" />
      <div class="wr">
         <h5>Home Button</h5>
      <p>This section will contain details about the service or product offered by Odeyale Corporation.</p>
      </div>
    </td>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> 
      <div class="wr">
      <h5>Home Button</h5>
      <p>This section will contain details about the service or product offered by Odeyale Corporation.</p>
      </div>
    </td>
  </tr>

  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

Answer №2

Isaac - Your CSS code for "table.service_section td p" is currently pushing the paragraph element 50px from the left using "left: 50px;". This causes the paragraph to extend beyond the width of the td. One quick solution would be to add a margin-right of 50px to balance out the push and keep the paragraph within the desired window. Alternatively, you could explore more efficient methods such as utilizing Bootstrap or Flex Box. The Flex Box guide at https://css-tricks.com/snippets/css/a-guide-to-flexbox/ offers valuable strategies. Consider implementing Bootstrap Cards for a similar effect. Additionally, resizing your image to the necessary dimensions can streamline your code and expedite achieving the desired outcome. I hope these suggestions prove helpful.

table.service_section{
    width: 80%;
    margin-left: 10%;
    border-spacing: 10px;}

  table.service_section td{
    border: 2px solid #ccc;
    box-sizing: border-box;
    border-radius:5px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);}

  table.service_section td img{
    display: inline-block;
    width: 50px;
    height: 25px;}
  table.service_section td h5{
    display: inline-block;
    margin: 0;
    padding: 0;
    position: absolute;}
  table.service_section td p{
    display: inline-block;
    position: relative;
    margin: 0;
    top: 0px;
    left: 50px;
    margin-right: 55px;
    font-size: 10;}
<table class = "service_section">
  <tr>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> <h5>Home Button</h5>
      <p>This is going to be information regarding the service/product provided by Odeyale Corporation.</p>
    </td>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> <h5>Home Button</h5>
      <p>This is going to be information regarding the service/product provided by Odeyale Corporation.</p>
    </td>
    <td>
      <img src="https://image.flaticon.com/icons/svg/23/23665.svg" /> <h5>Home Button</h5>
      <p>This is going to be information regarding the service/product provided by Odeyale Corporation.</p>
    </td>
  </tr>

  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</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

What is the best way to arrange two divs inside a main div so they remain fixed in place at all times?

Struggling with aligning two smaller divs within a main wrapper for my website. Despite confining them to the main div, they don't stay fixed or aligned properly. How can this issue persist even when contained within a main div? I've attempted s ...

How do I use CSS to organize data by row and column within a table?

I'm looking to format the table data in a column-row layout for mobile devices. Can anyone provide an example or guidance on how to achieve this? I've browsed through some discussions but haven't found a solution that works with tables. The ...

Issue with Bootstrap 3 Modal: Missing Title and Input Labels

I'm currently working on customizing a bootstrap template for my friend's church website. My goal is to create a simple web presence for them, and I am in the process of setting up a contact form. I want this form to appear as a modal where users ...

Utilize the :not() and :hover selectors in Less when styling with CSS

Some of my elements have a specific class called .option, while others also have an additional class named .selected. I want to add some style definition for the :hover state on the .option elements, but only for those without the .selected class. I' ...

Replacing CSS conditional statements with jQuery

My CSS code is set to hide the #global-widget-base tag and display a tab #aside-expander when the browser width is less than 1200px. @media screen and (max-width: 1200px) { aside#global-widget-base { display: none !important; } #aside- ...

Selenium Mouse/Pointer Display

Is there a way to visualize the selenium mouse movements during test execution? Can we display a windows cursor image or any kind of indicator like a dot or crosshair? I am currently working on implementing a drag and drop feature using Selenium and Java ...

The responsive menu refuses to appear

my code is located below Link to my CodePen project I'm specifically focusing on the mobile view of the website. Please resize your screen until you see the layout that I'm referring to. I suspect there might be an issue with my JavaScript cod ...

Display a pop-up directly below the specific row in the table

I am working on creating a table where clicking on a row will trigger a popup window to appear right below that specific row. Currently, the popup is displaying under the entire table instead of beneath the clicked row. How can I adjust my Angular and Bo ...

I'm puzzled as to why my JavaScript code only functions correctly when I place it after the HTML, despite having a window.onload event handler in place

Just beginning my journey in a CS class and seeking guidance for my lack of basic knowledge. I've noticed that this JS code only works if placed after the HTML, not within the head tag. Shouldn't window.onload handle that? Can someone clarify wha ...

The functionality of changing the checkbox to "checked" by clicking on the span is not

How can I create a toggle button with a checkbox using css and jquery? Clicking on the span representing the toggle button should change the checked property of the checkbox. Currently, the span does not change the property, even though it triggers the c ...

What is the process for designing a menu with animated scaling effects?

I have a design file in PSD format that looks like this. https://i.sstatic.net/R46Ko.jpg My goal is to create a website similar to , where when a user hovers over a link, a circle will appear around it. I am using Bootstrap 4.5 for this project. Here is ...

Show the total sum of a specific column in a datatable and enable the option to export the data to an Excel

When exporting a datatable as an Excel file with 4 columns, the third column contains product prices. After the export, I would like to see an additional row at the end of the table labeled "Total" that displays the sum of all values in column 3. I initia ...

Unveil as you scroll - ScrollMagic

I am working on a skill chart that dynamically fills when the document loads. I am exploring the possibility of using ScrollMagic to animate the chart filling as the user scrolls down. After trying various combinations of classes and pseudo-classes in the ...

Ensuring elements are properly centered within a Bootstrap grid while adjusting the window size

I've been facing a challenge with making my web page resizable. Even though I managed to center the elements using margin properties, whenever I try resizing the browser window, the logo and ship images lose their positions. They end up falling out of ...

Guide to adding customized CSS and JavaScript to a specific CMS page on Magento

I'm trying to incorporate a lightbox for video playback on a specific page of my CMS. I've placed my CSS file in JS/MY THEME/JQUERY/PLUGIN/VENOBOX/CSS/myfile.css and the JS files in JS/MY THEME/jquery/plugins/venobox/js/myfile.js, but it doesn&ap ...

Make individual term span the entire width of 100%

Is it feasible to expand a single word like "News" to occupy 100% width of the div element? My goal is to automatically adjust letter spacing and justify individual words. Currently, I have a menu with items such as: Home About News Etc It would be idea ...

What is the best way to maintain the layout design when resizing the font?

Here is the HTML and CSS code snippet: .navi ul li { float:left; list-style-type: none; border-right: 1px solid #c0c0c0; margin:0px 0 0 0; } .navi ul li:last-child { border:none; } .navi ul li a { display:block; margin:0 20px; text-dec ...

JavaScript detecting improper XHTML syntax

Is there an effective method to detect malformed XHTML within a string using JavaScript? Given that my page allows user-generated XHTML (from trusted users) to be inserted into the DOM, I aim to identify unclosed or overly closed tags. If found, I intend ...

Why is it that @font-face fails to function properly even after being defined correctly?

Here's the @font-face code I've been using: @font-face { font-family: "NotesEsa-Bold"; src: url("C:\Users\test\Desktop\Webpage\Fonts\NotesEsaBol.ttf") format("truetype"); /* Safari, Android, iOS */ font-we ...

Bootstrap 5 does not support tab navigation functionality

I created a new HTML page, and I encountered an issue while trying to enable tabs using JavaScript. <html> <head> <title>Excel Viewer</title> <link hr ...