Is it time to switch out HTML tables for Divs?

I am looking for advice on creating a consistent header for all of my website pages. Currently, I use a div element to wrap a table that contains one row with three cells.

These cells hold three images: one in the top-left corner, one in the top-center, and one in the top-right corner of the page.

The code snippet I have been using is:

<div class="div_Header">
  <table class="table_Header">
    <tr>
      <td class="td_Left"><img src="./IMAGES/Logo_Left.png" alt="Left Logo" /></td>
      <td class="td_Center"><img src="./IMAGES/Center_Title.png" alt="Center Header" /></td>
      <td class="td_Right"><img src="./IMAGES/Logo_Right.png" alt="Right Logo" /></td>
    </tr>
  </table>
</div>

I currently use CSS styles to position the images accordingly. However, I am wondering if there is a better way to achieve this layout. If so, how would you suggest updating the code?

Answer №1

Typically, a solution involving three floated divs within a wrapper is the preferred method.

<div>
  <div id="d1">left</div>
  <div id="d2">right</div>
  <div id="d3">center</div>
</div>


#d1 {
  float: left;
  border: 1px solid red;
}


#d2 {
  float: right;
  border: 1px solid blue;
} 

#d3 {
  margin-left: 100px;
  margin-right: 100px;
  border: 1px solid green;
}

Check it out here: http://jsbin.com/evagat/1/edit?html,css,output

Answer №2

Apply the style display:inline-block to all the div elements

div {
  display: inline-block;
  width: 100%;
  text-align: center;
}
div > div {
  width: auto;
}
div > div:first-child {
  float: left
}
div > div:last-child {
  float: right
}
<div>
  <div id="d1">content 1</div>
  <div id="d2">content 2</div>
  <div id="d3">content 3</div>
</div>

Answer №3

It seems like what you're looking for is a table with a background for each row. Unfortunately, this cannot be achieved out-of-the-box. However, there are alternatives you can consider:

  • Avoid using HTML table tags as they have multiple drawbacks and may be rendered differently by various browsers, especially Firefox. Instead, utilize CSS declarations for styling.

  • For each cell, use the background-image: url('') property to customize the appearance of the image. This will give you more control over the visuals, particularly in a responsive layout. You can target specific cells using :nth-child(1,2,3,etc..) within the HTML tags or :nth-of-type(1,2,3,etc..) if you opt for using classes for the divs.

Alternatively, you could implement @briansol's float trick as a secondary option. Keep in mind that floats are not typically recommended for web design purposes.

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

Embedding SVG styling directly into the HTML document

When importing svg images with color into Mapbox Studio, they appear as black and white. The troubleshooting website mentions: If your SVG appears black after adding to Mapbox Studio, it may be due to using style properties in tags instead of inline sty ...

Adding a certain number of days to a date within an existing ng-module in AngularJS

Hey everyone, I'm new to using AngularJS and I am currently attempting to incorporate one ng-module value into another ng-module date input within AngularJS. For example: if the date is 17-08-2016 and we add 20 days, the expected result should be 03-0 ...

Could you please provide instructions on how to manipulate the :root CSS variable using JQuery?

Is there a way to update the :root css variable using jquery? :root { --color: #E72D2D; } .box-icon { background-color: var(--color); } I tried but it doesn't seem to work $("#blueColor").click(function(e) { $(":root").css("-- ...

"Discovering a button press using the Gamepad API: A Step-by-Step Guide

I'm currently building a web page that can detect button presses on an Xbox controller and display a boolean value based on the pressed button. Right now, I have successfully managed to detect when a controller is connected and show it as a string. Ho ...

Utilizing Multiple Checkboxes for Precision Search Refinement

Big thanks to Khalid Ali for the support provided up until now. I am currently working with an array of songs that each have descriptions, keywords, etc. I have a set of checkboxes that I want to use to refine a search. Essentially, if someone selects the ...

No validation errors are currently being displayed. I am attempting to retrieve the error message when validation fails

My form validation error has suddenly stopped working. It was functioning properly yesterday, so I must have made a mistake somewhere, but I can't seem to pinpoint it. Now, when I attempt to sign up without entering any information, it just redirects ...

Using window.open and appending a new feature to it

Below is the code found in my index.html file: <!DOCTYPE html> <html> <head> <script> function createDialogBox() { var dialogBox = window.open("in1.html"); dialogBox.nameBox= "my little box" } window.onload = createDialogBox; wind ...

How can I extract data from a swiffy animation?

Suppose I am tracking the number of mouse clicks in Flash. To do this, I have utilized the following code: import flash.events.MouseEvent; plus.addEventListener(MouseEvent.CLICK,aaa) var i:int=0; function aaa(e:MouseEvent) { i++; var a:Number ...

Selections made from the dropdown menu will automatically generate additional fields in the

The code I'm working with is too lengthy to post in its entirety, so here is the JSFiddle link instead: https://jsfiddle.net/c0ffee/pew9f0oc/1/ My specific issue pertains to this screenshot: https://i.sstatic.net/swLqN.png Upon clicking on the dro ...

What is the best way to only load a specific div from another webpage onto my own webpage without loading the entire page?

I am currently working with two webpages named internal.html and external.html Within internal.html, I have the following code snippet that loads external.html into a div with the id "result": <script src="http://ajax.googleapis.com/ajax/libs/jquer ...

The PHP index is not being identified when accessed through the post method

I am delving into the world of PHP as a beginner and still learning the ropes. I tried to replicate a small script exactly from one language to another, but encountered an issue where the index from my HTML file is not being recognized in PHP. The tutorial ...

What is the best way to integrate HTML code within a JavaScript function?

I need the HTML code to execute only when a specific condition in JavaScript is met. Here is the JavaScript code: <script type="text/javascript"> $(document).ready(function () { if(window.location.href.indexOf("index.php") > -1) { ...

Using Puppeteer to Retrieve Data from a Web Page with Multiple Divs of the Same Class

I am in the process of creating a puppeteer script to scrape an announcements website. The challenge I am facing is how to extract the content of each page element with the same class using a loop. Upon inspecting the DOM, it's evident that all the co ...

Move the button text back to its original position with animation

I have a button with text that shifts to the right by 15px when hovered over. However, when the cursor is removed, the text immediately snaps back instead of smoothly transitioning back to its original position. I tried setting the ease-in-out property but ...

To modify the color of the breadcrumb navigation bar from purple to #d6df23 using PHP

Can someone help me figure out how to change the color of the bar displayed in this link: I need assistance with modifying the breadcrumb navbar. Is there a way to change the color to yellow? I attempted editing the header file, but it didn't produ ...

Leverage jQuery to retrieve information and fill in an HTML form

Seeking assistance with retrieving data based on a dropdown selection change. Specifically, choosing an Item ID from the dropdown and then populating textboxes and other dropdowns with values from the database. The other dropdowns already have assignment o ...

Having trouble with HTML code displaying correctly in R leaflet for labels instead of popups

While working with leaflet in R Studio, I encountered an issue when trying to add HTML code to the labels of the icons. Strangely enough, it works for the popups but not for the labels. Below is the code snippet causing the problem: library(leaflet) libr ...

Solving the style upload issue with NextJS and Module Federation in ReactJS

My current project utilizes React 18 and webpack 5 with the module federation plugin. I am exploring the possibility of integrating Next JS with module federation, but I am encountering an issue where the host project is not able to fetch styles from the r ...

The jQuery attr() method is universally compatible across platforms and stands independent

I have a jQuery statement that is currently working for me, but I am unsure if it is cross-platform independent. Can anyone confirm? $("input[name='confirmed']").attr("checked",false); It is functioning correctly on the latest version of Firefo ...

Using @font-face to include several files for different font-weight variations

I have a collection of font files that I want to assign to specific font weights. @font-face { font-family: "custom-font"; src: url("font300.eot"); src: url("font300.eot?#iefix") format("embedded-opentype"), url("font300.woff2") format ...