The column width in Bootstrap HTML is too excessive

  var parentDiv = document.getElementById("cc");
  var statementDiv = document.createElement("div");
  var statementName = document.createElement("div");
  // var removeIconDiv = document.createElement("div");
  // removeIconDiv.className = "col w-25";
  // removeIconDiv.setAttribute(
  //   "style",
  //   "padding-left: 7px !important; padding-right: 0px !important; width: 10px !important;"
  // );
  // statementDiv.appendChild(removeIconDiv);
  var trashcan = document.createElement("span");
  trashcan.className = "ml-4 col bi bi-trash";
  trashcan.setAttribute(
    "style",
    "padding-left: 0px !important; padding-right: 0px !important; width: 10px !important;"
  );
  // removeIconDiv.appendChild(trashcan);
  statementDiv.appendChild(trashcan);
  statementDiv.appendChild(statementName);
  statementDiv.className = "mb-3 option row text-left";

  /* STATEMENT NAME ************************ */
  statementName.className = "ml-2 col-2";
  statementName.insertAdjacentText("beforeend", "Your Statement");
  statementName.setAttribute(
    "style",
    "padding-left: 7px !important; padding-right: 0px !important; width: 110px;"
  );
  statementName.setAttribute("contenteditable", "true");
  /***************************************** */

  /* RADIO BUTTONS* ************************ */
  for (let i = 0; i < 5; i++) {
    var radioTemp = document.createElement("div");
    radioTemp.className = "col text-center";
    radioTemp.setAttribute(
      "style",
      "margin-right: 3px !important; width: 110px;"
    );
    var temp = document.createElement("input");
    temp.className = "form-check-input";
    temp.setAttribute("type", "radio");
    temp.setAttribute("name", "2");
    temp.setAttribute("disabled", "true");

    radioTemp.appendChild(temp);
    statementDiv.appendChild(radioTemp);
  }
  /***************************************** */

  parentDiv.appendChild(statementDiv);
 <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Survey Generator</title>
    <link rel="stylesheet" href="Vanessa.css" />
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"
      integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
      crossorigin="anonymous"
    />
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="33515c5c4740474152431e5a505c5d4073021d061d03">[email protected]</a>/font/bootstrap-icons.css"
    />
    <link
      href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900"
      rel="stylesheet"
    />

    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/4.5.6/css/ionicons.min.css"
    />
    <link rel="stylesheet" href="css/style.css" />
    <link rel="stylesheet" href="css/owl.carousel.min.css" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>

<div id="cc"></div>

I have a span element as shown below:

 var trashcan = document.createElement("span");
  trashcan.className = "ml-4 col bi bi-trash";
  trashcan.setAttribute(
    "style",
    "padding-left: 0px !important; padding-right: 0px !important; width: 10px !important;"
  );

This icon serves as a trashcan, which I intend to make clickable for a specific action. However, the width of the icon is not ideal, as illustrated in the following images:

https://i.sstatic.net/9UrTK.png

https://i.sstatic.net/8S8Oo.png

Despite attempting to modify the width using width: 10px !important;, the issue persists. Is there a way to adjust the width to match the actual size of the icon? I also experimented with width: fit-content without success. Any suggestions would be greatly appreciated. Thank you.

Answer №1

The width of the column is determined by the flex property. You have the option to set it to initial and then apply width:fit-content to adjust the size accordingly.

.col:first-child{
  flex:initial;
  width:fit-content;
  background-color:orange;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c0e0303181f181e0d1c2c59425d425f">[email protected]</a>/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="40222f2f3433343221306d29232f2e3300716e756e70">[email protected]</a>/font/bootstrap-icons.css">

<div class="row">
  <div class="col"><span class="bi bi-trash"></span></div>
  <div class="col">A</div>
  <div class="col">A</div>
  <div class="col">A</div>
</div>

Answer №2

An important issue arises when utilizing Flex-Options such as flex-grow and flex-shrink, as they have the capability to dynamically override the width settings to conform to the window width.

To address this problem, one can establish a max-width with the desired value or eliminate the existing values by using flex-shrink: initial; and flex-grow: initial;

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

Unfulfilled expectation of a promise within an array slipping through the cracks of a for loop

I have a function that generates a Promise. Afterward, I have another function that constructs an array of these promises for future utilization. It is important to note that I do not want to execute the promises within the array building function since so ...

Automatically storing modified text from richtextbox into the database for safekeeping

I have developed a basic note-taking application using jquery and php. Currently, when the user clicks the save button, it sends an ajax request with all the data to update it in the mysql database. Everything is functioning correctly. However, I now want ...

Javascript functions properly on Chrome, Opera, and Edge browsers, but unfortunately does not work on FireFox and IE 11

If you're interested, I have some code available on JS Fiddle that showcases my skills. var getJSON = function (url) { "use strict"; return new Promise(function(resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open('get' ...

Can bootstrap and all of its dependencies be imported in just one file?

Is it possible to utilize <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f1fcfce7e0e7e1f2e3d3a6bda3bda2">[email protected]</a>/dist/js/bootstrap.bundle.min.js&qu ...

What is the best way to delete information from a database with the help of Redux

Lately, I've been grappling with the task of integrating redux into my project. Successfully posting data to the database using redux and then retrieving it in react was a win, but now I find myself struggling with how to handle deleting data through ...

Validating various Google Sheet tabs in real-time

I am currently working on a script for validating localization tests in Google Sheets and I have run into some challenges with the logic. The main goal of the script is to 1) Go through all tabs, 2) Identify the column in row 2 that contains the text "Pass ...

Is it possible to create a horizontal navigation bar with buttons that scrolls when media queries are activated? I am looking for a solution using HTML,CSS, JavaScript, and Bootstrap

Struggling to create a horizontally scrollable navigation with buttons for media queries in Bootstrap 5.2, using SCSS for styling. This project is starting to feel overwhelming as we try to replicate the EA site. We're aiming to mimic the behavior of ...

Filtering JSON data with JavaScript

Looking to group data in AngularJS using UnderscoreJS. Here is the JSON data: data = [ { "Building*": "Building A", "Wing*": "Wing C", "Floor*": "Floor 3", "Room Name*": "Room 3", "Room Type*": ...

Adjust the text color of a particular word as you type using the contenteditable property set to "true"

I'm attempting to jazz things up a bit. For instance, I have a div that is set as contenteditable="true". What I want to achieve is changing the color of a specific word I type while writing. In this case, let's say the word "typing" sh ...

What is the process of building a service in AngularJS?

I have written this code using a service in angular.js. Upon running the code, I encountered an error Uncaught Error: [ng:areq]. </ons-toolbar> <div ng-controller="testAppController"> Search: <input ng-model="query" type=" ...

When using a wildcard router in Node.js/Express.js, the static router may not be recognized

While using this specific route along with my other routes, I encounter an issue with serving static files: var public_dir = path.join(__dirname, 'public'); app.use('/public', express.static(public_dir)); However, when I add the follo ...

- increase clarity and readability- separate sections for better

I'm working on a code snippet to showcase 4 buttons: #buttons { text-align: center; padding-top: 4%; } #buttons img { display: inline-block; list-style: none; padding: 10px; } #buttons p { color: #fff; font-family: ; font-weight: ...

Eliminate any unauthorized characters from the email address

My goal is to assist users in avoiding entering invalid characters in an email input field (prior to server-side validation and cleanup). Please note: I am not validating emails on the frontend, only cleaning them up. // Coffeescript $(Element).find(&apo ...

Align an element to the center and then align a second element to the right using Tailwind CSS

Here is a visual representation of my goal: the dashed line indicates the center of the container. My objective is to horizontally center one div element and then right-align a second div within the same row, all while keeping both elements centered. htt ...

Incorporate JQuery into your NodeJS project by leveraging the existing minified file

Can we integrate JQuery into Node.js and make JQuery AJAX calls without altering the syntax by using a pre-downloaded minimized JQuery file? To clarify, I have the minified file and wish to incorporate it into Node.js in this manner: var jquery = require( ...

Discover the process of dynamically importing JavaScript libraries, modules, and non-component elements within a Next.js

Lately, I have been utilizing Next.js and mastering its dynamic import feature for importing components with named exports. However, I recently encountered a particular npm package that functions only on the client-side (requires window) and has a substant ...

What could be causing my Vue component to not refresh?

Can anyone help me figure out why this component isn't re-rendering after changing the value? I'm attempting to create a dynamic filter similar to Amazon using only checkboxes. Here are the 4 components I have: App.vue, test-filter.vue, filtersIn ...

Display picture on webpage in 10 seconds

Hi, I'm working on a website project and I've run into an issue where I need to use JavaScript, but I haven't mastered it yet. I have a background image slideshow set up where a new image appears every 6 seconds. My idea is to have the sec ...

Tips for adjusting the button spacing on a bootstrap navbar

As someone who doesn't work on front-end tasks frequently, I have encountered an issue while creating a navbar using Bootstrap. The problem arises when trying to add multiple buttons as it causes the spacing between them to appear strange. Does anyon ...

What steps should be taken to transform this client-side code into server-side code?

I recently encountered a situation where I needed to convert client-side code into server-side code. Here is an example of what I did: strHTMLGrid = strHTMLGrid + "<link rel='shortcut icon' href='/EVServer/Images/favicon.ico'/> ...