Text appears too long for smaller screens and is not fully visible, creating a cutoff effect

Looking for a solution to make the domain name always visible on small screens? I have an HTML template with basic PHP that displays the domain name prominently for sale but it doesn't fit properly on devices like an iPhone SE. The challenge is to adjust the font size dynamically to ensure the entire domain is visible within the screen width.

The template utilizes HTML, PHP, CSS, JS, and Bootstrap 5. Below is a snippet of the index code where the issue arises:

<div class="container py-5 px-4 px-lg-5 my-auto">
    <div class="row">
        <div class="col-12 text-center mx-auto">
            <h1 class="text-7 text-white bg-danger d-inline-block fw-700 rounded px-4 mb-4">This is the domain:</h1>
            <h2 class="text-18 fw-700 text-white mb-4"><?php echo $_SERVER['HTTP_HOST']; ?></h2>
            <h3 class="text-white fw-400 mb-4"></span></h3>

The CSS class "text-18" controls the font size for smaller screens. Here's a part of the CSS related to it:

.text-18 {
    font-size: calc(1.625rem + 4.5vw) !important;
}
@media (min-width: 1200px) {
    .text-18 {
        font-size: 5rem !important;
    }
}
.fw-700 {
    font-weight: 700 !important;
}
.text-primary, .btn-link:not(.text-white):not(.text-light):not(.text-dark):not(.text-body) {
    color: #0d6efd !important;
}

If you're struggling to make the full domain name visible on small screens, check out this example with a domain of 19 characters.

Answer №1

Regarding the code snippet provided: Could you please specify the exact length of the host you are targeting in terms of characters? I have conducted tests on your code using the provided style, and it is functioning properly across various screen sizes, from small phones to 4k displays.

Solution 1: Ensure that other classes combined with 'text-18' do not pose any issues, as their absence makes it difficult to assess.

Solution 2: Check if any of the classes like 'fw-700 text-white mb-4' have an '!important' size declaration, as this can override the importance of the 'text-18' class. If present, ensure that 'text-18' is declared last.

<h2 class=" fw-700 text-white mb-4 text-18"><?php echo $_SERVER['HTTP_HOST']; ?></h2>

Answer №2

give this a shot! It's been working flawlessly for me

<style>
.text-18 {
  font-size: calc(1.625rem + 2.5vw);
}
.fw-700 {
  font-weight: 700 !important;
}

.text-primary, .btn-link:not(.text-white):not(.text-light):not(.text-dark):not(.text-body) {
  color: #0d6efd !important;
}
</style>
<div class="container py-5 px-4 px-lg-5 my-auto">
  <div class="row">
    <div class="col-12 text-center mx-auto">
      <h1 class="text-7 text-white bg-danger d-inline-block fw-700 rounded px-4 mb-4">This is the domain:</h1>
      <h2 class="text-18 fw-700 text-white mb-4">somelongtextdomainname.com</h2>
      <h3 class="text-white fw-400 mb-4"></span></h3>
    </div>
    </div>
</div>

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

Highlight the parent item when the child item is being hovered over

I am working on a menu that has 2 submenus. I want to use jQuery to highlight the item when it is hovered over. However, I am struggling with how to also highlight the parent item when the cursor is on the child item. The class I am using for highlighting ...

Enlarge the input field when it is selected

Is there a way to expand a search box towards the left instead of the right when focused? The code provided below expands the search box to the right. HTML: <input type="text" placeholder="search"> CSS: input[type="text"] { background: #444; ...

Tips for obtaining the HTML document as a string within an Android web browser

I am trying to retrieve the source code (HTML document) of a webpage when it loads in my code. I have written a function onPageFinished() with view.loadUrl("javascript:(function() { document.getElementByTagName('html')[0].innerHTML"); to get the ...

Designing checkboxes with accompanying labels

I am looking to create a vertical list of checkboxes with labels, following the layout below: My options [x] Checkbox 1 [ ] Checkbox 2 [ ] Checkbox 3 [ ] Checkbox 4 I have implemented the method suggested in this Stac ...

I possess a solitary div element that requires dynamic replication

I have a single container and an unspecified number of rows of data. I want to display this data on HTML cards that are generated dynamically based on the number of rows. For example, if there are 10 rows of data, I need to create 10 card elements with ea ...

jQuery unable to target Bootstrap button

I've been experiencing some trouble trying to attach a listener to a button I made with Bootstrap. <button type="button" id="buttonone" class="btn btn-default btn-lg good"> <span class="glyphicon glyphicon-minus" aria-hidden="true">< ...

The idea of a webpage completely powered by Ajax

I'm currently in the process of creating a compact website that utilizes full ajax requests for features such as login and registration, all done asynchronously. However, I've come across an issue where if a user decides to refresh the site, any ...

Is there a way to adjust the font color when the expiration date passes?

My goal is to change the color of text to green when the expiration date has not been reached yet. If the expiration date has passed, then the text should be red. .curentDate { color: rgb(54, 168, 54) } .expirationDate{ color: red; } <div cl ...

On a Samsung tablet with Moodle, the body background image is set to display at the top

Encountered an issue with Sambungs tables. I have a background image set on the body. Here is how the CSS looks: html, body{ background: url('img/background.jpg') no-repeat; background-position: top; // I also tried cover, fixed, etc } The ...

Dynamic row additions causing vanishing rows in the table due to JS/jQuery implementation

I am currently facing an issue while trying to create a table where I can add rows dynamically. Despite looking at various solutions on this topic, none of them seem to resolve the problem I am encountering. The newly added rows disappear immediately after ...

Executing npm run build index.html results in a blank page being generated without any error messages or warnings

After building my react app with npm run build, I encountered a problem where clicking on index.html resulted in a blank page opening in the web browser. I explored several solutions to address this issue but none seemed to work. Some of the strategies I ...

Using JQuery to load a table and inject it with html()

I am looking to populate an HTML table within a specific div element. The HTML code is being loaded using the following jQuery function: $("#table_wrapper").hide(); $.get("<?echo base_url();?>schichtplan/employee_fields/"+plan_id+"true",function(da ...

Text element within a container of unspecified dimensions

I find it challenging to explain what I have in mind without a visual reference: https://i.sstatic.net/5MSVr.png Some Background - There are certain aspects that can't be altered or shouldn't be changed: On my blog's front page, I utilize ...

Ways to create a border button with a matching width to the text above using CSS

Is it possible to style a border button in CSS so that the width matches the text above? I am trying to achieve a clean look for the navigation selected text, where the border-bottom aligns with the text above. Here is an example of what I have attempted ...

Strategies for storing component data within an Angular service

Recently, I have implemented a dice game feature using Angular. The outcome of the dice rolls is stored in a TypeScript array and then displayed on the HTML page. However, I have been tasked with persisting these results even if I navigate to another pag ...

Preventing checkbox selection with CSS

Can CSS be used to deactivate clicks on checkboxes while still maintaining their functionality for dynamically setting values using Javascript? I have not been able to find a suitable solution. pointer-events:none Unfortunately, this did not work as expe ...

"Discover the power of D3.JS with three dazzling charts on a single page, plus a host of additional

As a student, I struggle with English and it makes me feel sorry and anxious... Despite that, I want to create three scatter plot charts on the same page using a single data file (csv). The dataset includes columns for Name, Height, Weight, and Grade (ra ...

Guide on implementing various styles for a class in Tailwind CSS when transitioning to dark mode with the help of Next.js 13.4 and next-theme

Is it possible to apply unique styles for a class in Tailwind CSS when transitioning to dark mode using Next.js 13.4 and next-theme? I am currently setting up a dark theme in Tailwind CSS with Next.js 13.4 utilizing next-theme. Within my globals.css file, ...

Having trouble retrieving the value from a textarea in HTML using CodeIgniter with AJAX and PHP

Having trouble fetching the value of your textarea in PHP from AJAX? It seems that when you try to retrieve the value from HTML to JavaScript using var content = $('textarea[name=post_content]').val(); console.log(content);, it displays the value ...

How can I set up a cycling image background for the main div and a floating menu?

I was wondering how I could keep a cycling image background stationary behind the main content while scrolling through the page. You can check out the project itself by following this link. Feel free to use any of the code, including the fixed header menu, ...