Another CSS style is creating additional gaps within the div container

The code I'm working with currently looks like this:

    <div id="img_preview_text_container" style="width: 376px; height: 75px; top: 156px; left: 50px; color: rgb(255, 0, 0);">
  <div id="customOnePreviewText" style="font-family: Oklahoma; width: 376px; height: 75px;">FABO</div>
</div>

Here is the CSS styling used:

#customOnePreviewText {
  margin: 0;
  position: absolute;
}

#img_preview_text_container {
  position: absolute;
  display: flex;
  align-items: center;
}

The text looks good as it is.

To dynamically fit the text into its container, I utilized a JavaScript library called text fit js.

After applying the text fitting process using this method, the HTML code becomes:

        <div id="img_preview_text_container" style="width: 376px; height: 75px; top: 156px; left: 50px; color: rgb(255, 0, 0);">
  <div id="customOnePreviewText" style="font-family: Oklahoma; width: 376px; height: 75px; text-align: center; white-space: nowrap;">
    <span class="textFitted" style="display: inline-block; text-align: center; font-size: 80px;">FABO</span>
  </div>
</div>

This is what I get now: https://i.sstatic.net/Tkuko.png

The text is no longer centered and there's extra space below. This was not an issue before implementing textFit.js. How can I remove the excess spacing and align the text in the center again?

Answer №1

Consider adding line-height:1 to the #customOnePreviewText element

<div id="customOnePreviewText" style="font-family: Oklahoma; width: 376px;line-height:1;">FABO</div>

Answer №2

Adjust the height attribute of the outer container with id="img_preview_text_container". You can reduce it to a lower value, set it to 0, or use 'auto' for better results.

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

Generate a fresh line within the source code

Currently, I am facing a challenge with dynamically loading CSS, JS, and other components as it appears messy when viewed from the source. Although this issue does not impact functionality, I am not satisfied with how it looks in the source code. When exam ...

Is the div height set to 100% until the content surpasses the height of the browser window

Is there a method to make a div fill 100% of the available page height, until it contains enough content to require a scrollbar? // For example, if the browser height is 600px: <div> // Initially empty, so it will be 600px tall. </div> . ...

When an element is transferred to a different <div>, it does not automatically inherit its new CSS styles

There's an element with existing behavior that needs to be moved to meet new requirements without losing its original styles. The challenge is applying new styles to the element after it's been moved. For example: <div id="existingStructure" ...

Creating a Distinctive HTML Structure with Div Percentage (HTML 4)

I am new to web design and have a unique approach; I believe in the importance of flexibility. It puzzles me why pixels (px) are commonly used instead of percentages, maybe my perspective is misunderstood. I've been on the hunt for a basic HTML layo ...

Is it possible to apply a :before or :after pseudo-element to an input field element?

I'm having trouble incorporating the :after CSS pseudo-element on an input field. It seems to be working fine with a span, but not with the input field. <style type="text/css"> .mystyle:after {content:url(smiley.gif);} .mystyle {color:red;} < ...

Using CSS, create a layout with a small 2x2 box positioned beside a larger 2x2 box

https://i.sstatic.net/nC2PI.png Can a flexible ul li structure be achieved with flexbox? I attempted to set the width of the squares to 25% and make the 1st, 3rd, or 5th one 50% wide using a combination of float:left, clear[left|right], but the last squar ...

Enhance your website with a MultiItem Bootstrap Carousel SlideShow next to a Basic SlideShow feature

As I'm designing a website, my goal is to showcase products using sliders. I've implemented both a simple Carousel slideshow and a multi-item Slide Show on the same page. The multi-item Slide Show has a specific CSS class associated with it. The ...

The migration from Bootstrap 4's sticky-top class to thead is a seamless transition

For the past few days, I've noticed that the .sticky-top class is no longer working on thead tags. It was functioning perfectly fine last week, but now it's not responding when I try it on my App. Does anyone know why this might be happening? &l ...

Batch script prematurely ends when compiling .less files in a batch for-loop

Recently, I decided to try my hand at using batch scripts as a way to compile the .less files for my website into .css files before deploying. It seemed like an efficient solution for my needs. However, after successfully utilizing a for loop in my batch ...

The Facebook like button seems to be missing from the webpage

Hi everyone, I'm having trouble getting the like button code to work. I used the wizard on Facebook but the button still isn't showing up, even with a simple HTML setup like this: <!DOCTYPE html> <html> <head> </head> < ...

Concealing the toolbars on iOS 7 with the overlay technique

After researching on Stack Overflow and Google, I have been trying to find a reliable method to hide the toolbars on iOS 7 since the old scroll trick is no longer effective. I came across this resource: I attempted the following code: <!doctype html& ...

What is the best way to increase the width of an individual list item beyond the width of the list itself?

I am dealing with a situation where I have a list that has a fixed width in pixels. Within this list, there are two items: one with content that fits within the width of the list, and another item whose content is longer than the width of the list itself. ...

issue with href attribute not functioning as intended

I found this code snippet on this website. It seems to work fine, but when I click on a tab, instead of changing the content in the body (<a href="#tab2success" data-toggle="tab">), it redirects to localhost:9000/#tab2success, which doesn't exis ...

Tips for Removing Scrollbars on Mobile Devices

Currently, I have implemented -webkit-scrollbar{ display:none; } on my website, and it functions well on desktop devices. However, upon inspecting on Chrome devtools for mobile devices, the scrollbar still appears. Initially, the scrollbar does not seem ...

The images and full paragraph were intended to be displayed horizontally using the `display: flex` property

I'm having difficulties with my website layout when trying to display text on the left side and images on the right using flexbox. Can anyone help me troubleshoot why it's not working? .presentation { display: flex; width: 90%; margin: ...

What is the best way to target sibling elements in CSS 3?

I need help selecting the element that comes before and after li.active. Here is the HTML: <ul class="inline avancement"> <li>Réception des réponses</li> <li class="active">Achat</li> <li>Eva ...

Two CSS borders of varying heights

Just wondering, can we achieve something similar to the style shown in the attachment using only CSS? <h3 style="border-bottom:1px solid #515151"><span style="border-bottom:3px solid #0066b3">HEADER</span></h3> ...

Change the appearance of a div based on the presence of a certain class within a child div using jQuery styling techniques

I'm trying to set a default padding of 15px for div.content, but if it contains a child div.products-list, I want the padding to be removed. I've looked into solutions using jquery, but nothing seems to work. Here's how my layout is structur ...

Creating a server-side HTML template: A step-by-step guide

I need to create a consistent layout for all of my website pages using Bootstrap. While I already have a layout designed for a single page, I want to apply the same design across all pages. My initial thought was to utilize Jade for this task, but I want t ...

Flex Item will only respect the margin or padding when both are set simultaneously

I've been playing around with CSS and running into a problem where a flexbox item isn't respecting margin and padding correctly, causing the right side to have no margin. Here's a simplified example I came up with: <body> <div c ...