Tips for creating a fixed width div

Here in this code snippet

http://jsfiddle.net/sjD24/6/

You will see a table (or matrix as some may call it) of bookmarks. Each row is identified by a tag. The challenge here is to make sure that the column for tags has a consistent width.

The specific class that requires a constant width is

.tag_hold

I attempted the obvious approach of setting

width: 100px;

However, there was no visible change when I did this.

Answer №1

Setting a width for an inline element won't work because of its nature. To make the width take effect, consider using display: inline-block; instead of display: inline;.

However, if you are dealing with tabular data, it's recommended to use the <table> element as it is specifically designed for such purposes – no need to create something from scratch.

Answer №2

The issue with the functionality lies in the fact that the display is set to inline instead of inline-block

http://jsfiddle.net/sjD24/11/

Answer №3

Update the display: inline; to display: inline-block;

.tag_container{
    position: relative;
    top: -2px;
    display: inline-block;
    font-size: 13px;
    color: #000000;
    padding: 0px 0px 0px 0px;
    width:100px;
}

Answer №4

When you use display:inline, the width is ignored and the element is pushed regardless. To address this, you can switch to either display:block or display:inline-block and float the elements based on your desired appearance.

Alternatively, consider utilizing Twitter Bootstrap for a more streamlined approach.

Answer №5

Using inline-block as suggested by previous answers is the way to go.

I have gone ahead and tidied up your CSS for you, removing any unnecessary styles. You can view the updated version here: http://jsfiddle.net/sjD24/12/

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

Managing HTTP requests across different HTML pages in a Cordova mobile application

I have developed a Multiple Page Application (MPA) for Android and iOS which navigates to different pages when users want to view them. Everything is running smoothly so far, but I now want to add some backend sync features. The issue I am facing is that I ...

Simultaneously sending jQuery.ajax data while submitting a form

I'm facing a bit of a dilemma here. I have a form with multiple fields, including one for entering links. When you input a link and click the add button, the link is added to a link_array using jQuery. My goal is to send this array through the jQuery. ...

JavaScript or HTML can be used to store external embed PDF files in a cache

I have a PDF file from an external source embedded on this page. Although it displays correctly, I am concerned about the file being downloaded each time the page is visited. Would using an object tag instead help to cache the PDF and prevent repeated do ...

Is it possible to change the CSS of a parent element using a child element?

My current challenge involves altering the background-color of a parent <td> element, without being able to directly modify the HTML structure. The software system utilized at my workplace strictly relies on SQL queries for data manipulation and gene ...

What is the best way to give a user the option to select the destination for file uploads?

I currently have a basic upload form set up. Here's the HTML code: <html> <head> <title>Upload a File</title> </head> <body> <font face=verdana size=2> <form enctype="multipart/form-data" method="post" act ...

Enhancing dynamically generated elements with CSS styling

I have been working on developing my own jQuery Gallery Plugin. The crucial initial markup that is required to initialize the plugin includes: Initial HTML <div class="riGallery"> <ul> <li><a href="http://www.example.com" ...

What is the best way to include a Bootstrap CSS class in a select field using a loop within a Rails application?

Currently, I am dealing with a select field setup in the following way: <%= f.select(:avaliador_id) do %> <% @usuarios_array.each do |u| %> <%= content_tag(:option, u.first, value: u.last) %> <% end %> <% end %> My q ...

I am struggling to prevent the background image from endlessly repeating despite my best coding efforts

I am struggling to correctly write the code to display the background image in this page only once, without repeating, and centered about 500px down the page. I tried something like "background-image: norepeat" but it didn't work. I looked at the W3C ...

Utilize JQuery to inject both standard HTML elements and safely rendered escaped HTML onto a webpage

After storing some data in firebase that can be retrieved on the client side, I use JQuery to add it to the HTML. Although the process of prepending the data to the DOM element is straightforward, there is a security concern as raw code can make the applic ...

In Google Chrome, the edges of hexagons appear jagged and not smooth

I have encountered an issue in Chrome where I created a hexagon group using HTML and CSS. While it displays fine in Firefox, the edges of the hexagons appear distorted in Chrome. Here are my code snippets: HTML <div class="col-sm-12 margin-left-100" i ...

CSS selector for GTM trigger that is not specific to any particular element

I am attempting to develop a CSS selector that can target the specific entries within the page-top-menu: Header menu - Menu 1 DE #page-top-menu > div > div.menu-wrapper > ul > li.i39.dropdown.layer.item-type-1.catid-0eca5a6c6e53f281b9e0469ca3d ...

Controlling CSS Styles in Angular using TypeScript

Currently, I am working on an Angular project that involves dynamically populating a calendar. In addition to this, I have a range of dates and the task at hand is to modify the background for specific days within this date range. To manage dates effective ...

What are some effective methods for creating a sidebar that allows content to scroll beneath it seamlessly?

My goal is to create a webpage with the following structure: I want to display content in a large scrolling slideshow while allowing it to scroll left under a white sidebar. Although this may seem simple, I have experimented with various structures and am ...

Flex items refusing to wrap in Firefox

I am facing an issue with my layout setup in different browsers. When I have a list of divs inside a flex div, it displays correctly in Chrome: However, in Firefox, it only shows a horizontal scroll with one line. Is there a way to prevent the forced hor ...

Why does appending to a TextArea field fail in one scenario but succeed in another when using Javascript?

There is a JavaScript function that captures the value from a select dropdown and appends it to the end of a textarea field (mask) whenever a new selection is made. function addToEditMask(select, mask) { var selectedValue = document.getElementById(sel ...

The elements within the divs cannot be aligned next to each other

Having a bit of trouble positioning two div's side by side. Divs are usually block elements, but this time I'm facing some challenges in getting them to sit next to each other. Here's the HTML code: <div class="contact"> <div ...

Creating a fixed column in an Angular Material Table for enhanced user experience

Has anyone found a method to implement a sticky first column in Angular Material using CSS? Check out the editable Stackblitz code here. I attempted to modify this approach from https://jsfiddle.net/zinoui/BmLpV/, but encountered issues where the first c ...

Using mousedown, mousemove, and mouseup to handle touch events in vanilla JavaScript instead of jQuery

Can someone guide me on how to set up a touch event handler in JavaScript using the mousedown, mousemove, and mouseup events? I would really appreciate any suggestions or tips! ...

Django is refusing to display my CSS and JavaScript files - static files

Within my code in settings.py, I define the static URL like so: STATIC_ROOT = os.path.join(BASE_DIR, "static") STATIC_URL = '/static/' The location of my static files and folders is at /home/myLinuxUsername/myApp/static/interactive-preview-depe ...

What is the best method for deleting scripts to optimize for mobile responsiveness?

My current plugin.js file houses all my plugins for responsive design, but it is unnecessarily large and cumbersome for mobile devices. I am considering creating two separate plugin.js files to toggle between for mobile and desktop views. What are the r ...