Overflowing text in the div element

Attempting to generate a sample document and aiming to enlarge the font-size by clicking the "Medium" & "Large" button.

Encountering an issue where the font-size overlaps with other divs when pressing the "large" button, though not experiencing any problems with the "medium" button.

Query: Why does the text overlap when the font-size is increased?

<!DOCTYPE html>
<html>

    <head>

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
        </script>

        <script>
            $(document).ready(function(){

                $("#switcher-medium").click(function(){
                    alert('This is medium');
                    //$('body').removeClass();
                    $('body').addClass('medium');
                });

                $("#switcher-large").click(function(){
                    alert('This is large');
                    //$('body').removeClass();
                    $('body').addClass('large');
                });

            });
        </script>

        <style>
            body{
                background-color:white;
            }

            #header-1st{
                height:30px;
                width:70%;
                float:left;
            }

            #switcher-control{
                height:30px;
                width:30%;
                float:left;
            }
            .medium{
                font-size: 1.5em;
            }

            .large{
                font-size: 2.5em;
            }

        </style>

    </head>

    <body>

        <div id="main-container">
            <div id="header-1st">
            </div>
            <div id="switcher-control">
            <button id="switcher-default"> 
                Default
            </button>
            <button id="switcher-medium"> 
                Medium
            </button>
            <button id="switcher-large"> 
                Large
            </button>
            </div>
            <div id="content">
            This is a test page and you can increase the font-size by clicking the default, medium and large on top corner.
            </div>
        </div>

    </body>

</html>

Answer №1

Click here for a LIVE DEMO

To improve your design, simply delete the line height:30px; from your top elements

Here is the revised CSS:

#header-1st{
  width:70%;
  float:left;
}
#switcher-control{
  float:left;
  width:30%;
}

JavaScript function:

var sizes = [1, 1.5, 2.5];  
$("#switcher-control button").click(function(){
    var i = $(this).index();
    $('body').css({fontSize: sizes[i]+"em"});
});

Your HTML structure should look like this:

<div id="main-container">

  <div id="header-1st">HEADER</div>  
  <div id="switcher-control">
        <button>Default</button>
        <button>Medium</button>
        <button>Large</button>
  </div>

 <div id="content">
        This is a test page and you can increase the font-size by clicking the default, medium and large on top corner.
 </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

Steps for refreshing Google reCAPTCHA on an AJAX-enabled webpage

I am encountering an issue with two captchas on my website. One captcha is loaded upon refresh, while the second captcha is loaded on a different page via ajax. The problem arises when I click on the "No" button after selecting it on the second page. I wan ...

constructing an array in real-time with the help of jQuery

I am working with HTML checkboxes and trying to store the value of any checked checkbox in an array. However, my function is currently returning an empty array. var arry = []; function CheckBox(check) { debugger for (i = 0; i < check.length; i+ ...

Wrapping a group of elements with opening and closing tags using jQuery

I have a collection of distinct elements, like so: <section class="box-1"></section> <section class="box-2"></section> <section class="box-3"></section> My objective is to enclose all three elements within a div with a ...

What is the method for adding 24 hours to a 12-hour timestamp while preserving the AM and PM designation?

I have created the following code to display real-time, but I am struggling with adding a timestamp that switches from 24-hour format to 12-hour format with AM and PM. setInterval(function() { var date = new Date(); var hours = date.getHours(); va ...

When using Material UI TextField with input type "date", the event.target.value does not seem to be accessible

I am currently working with Material UI and React Grid from DevExtreme to build a table that includes an input field of type date. However, when I attempt to enter the date, it does not register the change in value until I reach the year field, at which po ...

Using canvas in Bootstrap can lead to columns wrapping onto the next line due to margins

My goal is to align two charts side by side with some padding or margins between them. It seems to work fine when the columns contain text, but I'm running into issues when using the canvas tag. Whenever I try to add space between the charts, they end ...

Switch your attention to the following input text using AngularJS

In my controller, I have an object variable called `myObject` with 3 input text fields in the user interface. I am looking for a way to automatically shift the focus to the next input field once the current one reaches its maximum length. var myObject = ...

The issue of Access-Control-Allow-Origin restriction arises specifically when using the gmap elevation API

My attempts to retrieve the elevation of a site using latitude and longitude have been unsuccessful due to an error I encountered while making an ajax call. Regardless of whether I use HTTP or HTTPS, I receive the following error message: "No 'Access ...

Using jQuery to toggle between multiple divs, turning one on while turning off the others

Hey there, I'm currently brainstorming ways to utilize an accordion widget in a unique way. Specifically, I want each h3 trigger to reveal a different div when selected, hiding the previous one in a seamless manner. Picture this - A sleek three ...

Responsive Video Embed Using Bootstrap-5

I'm facing some challenges with Bootstrap responsive video embedding. It seems like the parent container is not responding to changes, only the content within the <iframe> tag is being responsive. Any idea what might be going wrong? .embed- ...

Can a single value be stored in a table using a radio button?

I have created an HTML table that is dynamically generated from a database. I am using a for loop to populate the table. However, I am facing an issue where each radio button in the table holds only one value. What I actually want is for each row to have ...

Cloning a checkbox using Jquery

I am working on a search page that utilizes checkboxes to display results. After the user selects certain options and triggers a reload of the page, I want to provide an easy way for them to remove their selections by displaying them at the top of the page ...

Adjust the color of a selected edge in Three.js

let cubeEdges = new THREE.EdgesHelper(cube, 0xff0000); cubeEdges.material.linewidth = 5; scene.add(cubeEdges); A cube has been created using the following code: new THREE.Mesh(new THREE.BoxGeometry(200, 200, 200, 1, 1, 1, materials), new THREE.MeshFaceMa ...

Errors with pointer events occurring within nested iframes on Chromium 78

At first glance, it seems like a bug specific to Chromium. I have already reported this issue in a bug report. Since progress is slow on that front, I am posting a question here primarily to see if anyone else has encountered similar or related issues and ...

Removing a Dynamic Element in ReactJS

--CustomFieldSection.js-- import React, { Component } from 'react'; import CustomField from './CustomField.js'; class CustomFieldSection extends Component{ constructor(props){ super(props); this.stat ...

Tips for maintaining an open ng-multiselect-dropdown at all times

https://www.npmjs.com/package/ng-multiselect-dropdown I have integrated the ng multiselect dropdown in my Angular project and I am facing an issue where I want to keep it always open. I attempted using the defaultOpen option but it closes automatically. ...

Is there a way to adjust the size of a video thumbnail to fit within a

Currently, I am developing a system to remotely control home electrical devices via the web. However, I am facing an issue with fitting camera images properly within their container. How can I ensure that the video thumbnail fits perfectly in the designat ...

Maintaining responsiveness, CSS grid will automatically adjust the height of each element to be equal

I am facing an issue with my grid layout. Each element in the grid has an image and other divs below it. The problem arises when the screen size changes, causing the elements to scale automatically due to responsive width. I want all the images to have the ...

Expanding space underneath for inline-block elements

Is there a way to create a page layout with inline-block elements that are vertically aligned to the top and fold into open space like floated elements do when placed below another set of inline block elements? It seems as though they follow row-like rules ...

Preventing mouse clicks on checkboxes and triggering events using JavaScript - a complete guide

We have a Table grid with multiple columns, one of which is a Select Box (CheckBox). The expected behavior is that when a row is clicked, the respective CheckBox should get checked, and clicking on the CheckBox itself should update it. I tried implementin ...