What are some ways to improve the appearance of an HTML color box?

My goal is to display a colored rectangle within a table and have it look visually appealing, but my skills in HTML/CSS are lacking.

Here is what I currently have (which looks quite unattractive):

<table>
  <tr>
    <td>
      #2E21FF&nbsp;&nbsp;<span style="background-color: #2E21FF;border-width=1px;border-style:solid;border-color:rgb(204,204,204);padding:0;margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
  </tr>
</table>

This demonstration of minicolors showcases a beautiful swatch in the input field that I'm struggling to replicate:

Fiddle: https://jsfiddle.net/Kieveli/9hjm9Lkf/

Answer №1

It's worth noting that the td element is given a unique style using the class color-box, allowing individual colors to be managed separately through their respective classes. This not only promotes code reusability but also simplifies implementation.

.color-box span {
  border: 1px solid rgb(204, 204, 204);
  padding: 2px;
  padding-left: 25px;
  margin: 0px;
  margin-right: 10px;
  border-radius: 3px;
}
.color-box {
  border: 1px #aaa solid;
  padding: 6px;
  padding-right: 100px;
  border-radius: 3px;
  -moz-box-shadow: inset 0 0 2px 0 #888;
  -webkit-box-shadow: inset 0 0 2px 0 #888;
  box-shadow: inset 0 0 1px 0 #888;
}
.blue-box {
  background-color: #0088cc;
}
.red-box {
  background-color: #ff6161;
}
.green-box {
  background-color: #70c24a;
}
.yellow-box {
  background-color: #e0e03e;
}
<table>
  <tr>
    <td class="color-box">
      <span class="blue-box"></span> #0088cc
    </td>
    <td class="color-box">
      <span class="yellow-box"></span> #e0e03e
    </td>
  </tr>
  <tr>
    <td class="color-box">
      <span class="green-box"></span> #70c24a
    </td>
    <td class="color-box">
      <span class="red-box"></span> #ff6161
    </td>
  </tr>
</table>

Answer №2

Ready to get started?

Check out this helpful link

td {
  border: 1px solid #ccc;
  background-color: #efefef;
  padding: 5px 6px 5px 10px;
  border-radius: 5px;
  font-family: calibri;
  color: #777;
}

td span {
  background-color: #716bc7;
  border-left=1px solid #ccc;
  width: 20px;
  height: 100%;
  display: inline-block;
  border-radius: 5px;
}

Answer №3

Looking for inspiration? Check out various examples on this webpage: Design Shack

Take a peek at this demonstration featuring a square and a circle:

.square {
  height: 200px;
  width: 200px;
  background-color: #ff4136;
  border-radius: 50%;
  margin-bottom: 40px;
}

.circle {
    height: 100px;
    width: 100px;
    background-color: #0074d9;
    border-radius: 50%;
}
<h3>Experimenting with Shapes:</h3>
<div class="square"></div>
<div class="circle"></div>

Answer №4

Take a look at this demonstration of how to generate a colorful rectangle within a table.


td {
    border:solid thick darkblue; 
    border-radius: 1em; 
    border-width:3px; 
    padding-left:9px; 
    padding-top:6px; 
    padding-bottom:6px; 
    margin:2px; 
    width:980px;
}

<table>
  <tr>
    <td
      <span "background":#ff0000;    
        width:200px;
        height:100px;
        display: inline-block></span>;
    </td>
  </tr>

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 ensure a dropdown in an input group occupies the full width?

One of the challenges I'm facing involves a row with 2 columns - the first column contains a title and the second column features an input group. Within the input group, there is an icon and a dropdown menu. Unfortunately, the dropdown menu is not oc ...

Converting an Angular project into a Maven WAR file for Deployment on Tomcat Server

My company is embarking on a new Angular project, and I've been tasked with deploying the Angular Project as a War File. This will allow us to upload it to our artifactory and easily deploy it to Tomcat 8. However, I don't have much experience w ...

How can I activate page indicator and additional features in a TIZEN web app for wearables?

Switching 'data-enable-page-scroll' to true or false triggers different features and disrupts the section positions. Setting it to 'false' enables 'pageindicator' and the page displays perfectly, but 'moreoptions' fa ...

Displaying and hiding elements as the page is scrolled

Is there a way to create a single scrolling page with a fixed element that remains visible as the user scrolls down? Imagine an image of a car on a road, where the car appears to be moving down the road as the user scrolls. The car should go under certain ...

Updating a dropdown menu dynamically using PHP PDO according to the previous selection

Although this question has been answered previously, I am posing it again for two specific reasons. Firstly, my search for resources that utilize PDO has been fruitless. Secondly, the existing resources I have come across are devoid of comments or explanat ...

Choosing the child anchor element within a list item

Having trouble selecting the anchor link in the DOM that is a direct child of my list item "dropdown-nav". I want it to change when the list item is clicked, but it's not working. The active class is being applied correctly. What could be the issue he ...

Why doesn't setting the SVG viewBox to "0 0 100 100" scale my path to 100%?

My current dilemma involves an SVG path that is only displaying at 50% of its intended size. How can I adjust it to show at 100%? Below is the code snippet in question: <div className="svgPathContainer"> <svg width="100%" he ...

Choose from a range of options using a dropdown menu with the ability to make multiple selections

Looking for a way to have a simple city drop down with multiple selection options? I tried using the 'multiple' attribute of the select tag, but it changed the dropdown into a box shape with multiple select options. What I really want is for the ...

What could be causing the uneven application of CSS padding when it is applied to a div that serves as the parent of an HTML form?

Padding has been added only to the top and bottom of a div. The padding attribute is displaying consistently for the form element, however, it is not behaving uniformly for the parent div of the form as illustrated in the image provided below. Output:- h ...

Use .empty() method to remove all contents from the tbody element after creating a table

Currently, I am working on a project where I am creating a drop-down list to assist users in selecting media and ink for their printers. The goal is to then generate a table displaying the selected results. While I have managed to successfully generate the ...

Looking to shrink the image dimensions for optimal mobile display using bootstrap

In one section, I have two columns - one for an image and one for text. https://i.sstatic.net/QMLNF.png Here is the HTML code: <div class="row aboutRow"> <div class="col-lg-3 col-sm-2 col-xs-3 col-md-3 text-center"> ...

Avoid having two DIVS appear simultaneously in IE for half a second upon page load

I'm encountering an issue with my HTML and jQuery code. Here is what I have: <div id="block1"> some text </div> <div id="block2"> some more text </div> Along with the following piece of jQuery code: jQuery(document).ready(fu ...

What is the best way to achieve an ellipsis-like effect for non-string elements while limiting the number of rows to a maximum of 2?

The objective is to achieve the following: https://i.sstatic.net/lcChx.png However, the challenge lies in adding two "hardcoded" elements at the end of row 2: The "# more" button (only when necessary) The "face-plus" button (always) This pertains to th ...

Fade all list items other than the one that is selected

I have a group of items in a list. Whenever you click on an item, it expands to show more information. I would like all other items in the list to be blurred except for the one that is expanded. <li href="#" class="list-group-item" ng-repeat="task in t ...

Utilize a single CSS class or theme to style multiple boxes within a stack - Material-UI

I'm currently diving into the world of React js and MUI components. I'm in the process of creating a stack with multiple boxes, each with its unique style that's consistent across all boxes in the stack. Is there a simpler way to define one ...

Creating a Dynamic List in JQuery Fancy Box for an iframe

I am new to using JQuery and I have a table with a checkbox. When the checkbox is clicked, I want a dynamic list to appear in a pop-up window. I've been having trouble implementing this. <html> <head> <label align="center">Select a ...

"Trouble with getting the Twitter Bootstrap dropdown menu to function properly

Currently, I am facing a challenge with my project as the dropdowns on the menu are not functioning properly. Despite having all the necessary files included, it seems like there might be an issue within my code. You can view the page here: (please try t ...

Access the freshly launched URL

I am relatively new to PHP and have a table displayed on my webpage. Each row in the table has an auto-incremented rowid that is not being displayed. When clicking on a row, it opens a new page in the format of www.newpage.com/newpage/rowid. If I inspect ...

Clicking a button in Angular JS to refresh a specific ID element

Just diving into AngularJS for my mobile web app development. I have different id divs for each view, as that's how AngularJS operates with one HTML page. My goal is to use specific javascript for each id page, as they need to retrieve JSON data objec ...

Looking to achieve a stretch-auto-auto column layout in Bootstrap 4 - how can this be done?

Essentially, I am looking for something similar to this: https://i.sstatic.net/ss3Ir.png Can this layout be achieved using columns instead of floats? <div class="clearfix"> <div class="float-left"><button class="rounded btn btn-outline ...