Changing text size on the fly with CSS

Here are the HTML and CSS codes I am currently using:

HTML :

<div>
    <a href="#">ITALIANO</a>
    <a href="#">ENGLISH</a>
    <a href="#">FRANÇAIS</a>
    <a href="#">DEUTSCH</a>
</div>

CSS :

div>a{
   margin-left: 30px;
}

div{
   font-size: 28px;
   width: 70%;
   margin: 2% auto;
}

When zooming in or out, the text size becomes problematic by either wrapping to two lines or becoming too small. Is there a way to dynamically adjust the font size without using JavaScript?

Thank you

Answer №1

According to a response on this Stack Overflow post, adjusting font size based on viewport width is possible.

p {
    font-size: 30px;
    font-size: 3.5vw;
}

For more details, visit CSS Tricks.

Answer №2

One idea that comes to mind is setting a universal font-size in your HTML and CSS code to create responsive typography. The base font-size can be set to 16px=1em, with the rest of the CSS code font sizes in percentage relative to this base. This approach allows the font sizes to adjust according to screen width.

html {
font-size: 1em;
}

div>a{
margin-left: 30px;  <-- To ensure responsiveness, consider using a left margin as a percentage instead of fixed pixels.
    }

div{
font-size: 175%;  <-- This translates to 28px
width: 70%;
margin: 2% auto;
}

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

Developing a logic for a Tagging System in PHP and MySQL

As a novice developer, I am seeking advice on my current project. I am in the process of creating a platform where users can upload images and tag them. After researching various methods of storing tags, I came across the following structure: Tag Storag ...

The MySQL Query Maker

To fetch data from a database for only one row and then generate separate pieces of information, use the following code: <?php session_start(); ob_start(); error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set("display_errors", 1); set_time_limit(1 ...

Can the input field offer guidance on its own?

While browsing, I came across an HTML5 checkout form that grabbed my attention. You can view the source here I decided to make some changes to the form and discovered that entering an incorrect email address triggers helpful tips. Strangely, upon closer ...

Traversing a series of HTML form elements in order to extract their current values and store them in an object

Suppose we have an HTML structure like this: <nav data-filters class=""> <input type="radio" name="type" value="company" checked>Company <input type="radio" name="type" value="product">Product <input type=" ...

Registering a change event for a table's value

I am a beginner in Angular and struggling with writing an event that can successfully pass the changed value from a table cell to my component. Below is the HTML code for the table cell, where the user should be able to change the value and have it passed ...

Encountering issues with implementing useStyles in Material-UI components

Currently, I am working on a project utilizing Material-UI's library and encountering styling issues. This project marks my initial venture into ReactJS and JavaScript in general. Therefore, any assistance would be greatly appreciated! I am struggli ...

React Scroll and Material-UI button active link not functioning correctly

Whenever the link goes to the correct page, I want to add a special background effect or change the font color. Despite trying to use CSS for this purpose, it didn't work as intended. If you want to take a look at my code on codesandbox, follow this ...

Differentiate your borders with CSS styling of various colors

Is there a way in CSS to create multiple lines with different colored borders stacked on top of each other without using a background image? Take a look at the example below: https://i.sstatic.net/w9F44.jpg ...

Stacking components on top of one another using CSS

I have been experimenting with a dynamic sliding jQuery menu. By adjusting the drop-down area slightly upward using a negative margin, I was hoping to layer the dropdown on top of its parent element that triggers the action. I attempted using z-index witho ...

Building a Compact Dropdown Menu in Bootstrap

I am looking to implement a compact Bootstrap dropdown feature, but I am unsure of how to do it. Take a look at this image for reference. base.html: <a class="text-light" data-bs-toggle="dropdown" aria-expanded="false&qu ...

Step-by-step guide for setting up CodeMirror

I'm feeling a bit lost with what to do next: <link rel="stylesheet" href="lib/codemirror.css"> <script src="lib/codemirror.js"></script> <script> var editor = CodeMirror.fromTextArea(myTextarea, { mode: "text/html" }); ...

How do I get my navbar to change color using a JavaScript scroll function?

I've been struggling with changing the color of my navbar when it's scrolled. I have some JavaScript code at the bottom that should handle this, but for some reason, it's not working as expected. I've double-checked that my bootstrap CD ...

Remove Vue Component from the styling of current application

We integrated a Vue component (using Vuetify) into our existing .NET MVC application. The issue we are facing is that the Vue component is inheriting all the CSS styles from the rest of the application. Here's a simplified version of the HTML structur ...

Using conditional statements in CodeIgniter to display various menus

I encountered an issue with a variable in my code. When I attempt to retrieve its value, it shows up as undefined despite having stored the session of the variable "$level" and passing it to the view. I find it strange that the condition of the variable tu ...

What are some techniques for creating a responsive table in CSS that includes images?

After much searching, I am confident that using "Skeleton CSS" will help achieve my goal. The concept is simple, but implementation is proving to be difficult. I am trying to create a table with multiple images that will change width to 750px when display ...

What is the best way to restrict users from accessing more than 5 Bootstrap Tab-Panes at once?

Users are restricted to opening only a maximum of 5 tab panes, even if there are multiple tab buttons available. If the user tries to click on the 6th tab, an alert message will be displayed. function addTab(title, url){ var tabs=$(".tabs"), tab ...

Several different forms are present on a single page, and the goal is to submit all of the data at

Looking for assistance with combining Twitter and Google data entry at once. Here's the code I've developed: Please guide me on how to submit Twitter and Google details together. <html> <head> <script type="text/javascript">< ...

jQuery width property does not seem to be functional on menus that do not contain any dropdown

I am currently working on creating a menu that displays arrows underneath the items when hovered over or when the .active class is added to the menu. Everything is working fine, except for the fact that it only works on menus with drop-downs and the child ...

Customize Vue Element UI table cell appearance depending on the data

I am utilizing Element UI for my project. How can I dynamically change the color of the rate cell value in the table? I want the color to be red when rate is less than 0, and green when it is greater than or equal to 0. I wonder if the table attribute cel ...

Is there a way to effectively rotate an image according to the position of my cursor, ensuring it functions correctly?

After an extensive search for similar questions, I have come across only one relevant resource which can be found here. While attempting to implement the code mentioned above, I encountered numerous failures in my individual efforts. I am pleased to prov ...