elevate the font size specifically for the descendants of a particular element

Currently, I am using rems to define the font sizes in my project. However, I have encountered a situation where I need to scale the font sizes at specific breakpoints without affecting the entire page, but just the text within a certain container. I understand that changing the font-size of html will impact all elements on the page. Is there a way to only adjust the size of child elements within a specific container such as .container, rather than specifying individual sizes for each child element? I want to scale the entire container and not assign a size to each individual child.:

CSS

html{
    font-size: 13px;
  }

  p{
    font-size:1rem;
    }

h1{
font-size:2rem;
}

.container{
   font-size:3rem;
}

HTML

<h1>Main title</h1>
<p>Main text</p>

<div class="container">
  <h1>Title</h1>
  <p>Text</p>
</div>

Answer №1

Utilize the selector * to target all descendants:

html {
  font-size: 13px;
}
p {
  font-size: 1rem;
}
h1 {
  font-size: 2rem;
}
.container * {
  font-size: 12px;
  color: red;
}
<h1>Main title</h1>
<p>Main text</p>

<div class="container">
  <h1>Title</h1>
  <p>Text</p>
</div>

Answer №2

To specify different font sizes for <p> elements within specific containers, you can use the following CSS:

.container p {
    font-size: 12px;
}

.container2 p {
    font-size: 16px;
}

The font size of <p> elements will vary between each container.

Answer №3

Give this a shot: Live Demo

.main-heading{
     font-size:2.5rem;
     color:blue;
}

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

Unable to retrieve HTML element using Python's Selenium

Whenever I try to access a specific website using Selenium, a pesky pop-up appears and I can't seem to locate the close button to dismiss it. from selenium import webdriver from time import sleep from selenium.webdriver.common.keys import Keys import ...

The appearance of the mock button varies between the development and production environments due to CSS styling

I'm currently using CSS to style a hyperlink in order to give it the appearance of a button. This is for a .NET website. a.pretend { display:inline-block; border-top:1px solid #CCCCCC; border-left:1px solid #CCCCCC; border-bottom:1px solid #999999; b ...

What is the best way to ensure my hover caption spans the entire size of the image?

I'm currently working on creating a hover caption that adjusts itself to fit the full width and height of an image even when it is resized. I attempted to implement a jQuery solution that I came across, but unfortunately, I am struggling to get it to ...

Retrieving list item contents using PHP DOM scraping

Is it possible to use PHP DOM screen scraping to extract the content from an HTML tag named <li style="margin-top:10px"> that appears on one of my web pages? I am looking to retrieve all the data within the <li> tag and present it as HTML co ...

The event listener function is not functioning properly on images generated by JavaScript

I'm currently working on placing multiple images on a grid in the center of the page and would like to include a function that triggers when each individual image is clicked. The images are dynamically created using JavaScript and inserted into the do ...

Selenium Alert: Inaccessible Element Encounter (cookie and other pop-up)

I'm attempting to click a button using Selenium so that I can inspect the full HTML of a website. Here's the code I've written: driver = webdriver.Chrome() driver.get('https://www.quattroruote.it/listino/audi/a4-allroad') time.slee ...

All you need to know about the properties of CSS ul

When I specify .a ul{} .a ul li{} as well as .b ul{} .b ul li{} will the properties of ul in .b be completely isolated from the properties of ul in .a? Or will they have some commonalities? I am looking to ensure that the styles for ul remain entirely ...

Bug allows unauthorized access to password in Bootstrap Password Revealer

Whenever I try to reveal a Bootstrap password using the eye button, my PC freezes. Strangely, an input is automatically added even though there are no codes for it. This auto-increasing input causes my browser to hang and eventually crashes my entire PC. C ...

"What is the process for creating a single line border around a pandas DataFrame using df.to_html method

After exporting a pandas dataframe as an HTML table to Outlook, I noticed that the double cell borders are not aesthetically pleasing. I am seeking assistance in changing them to a single line border. Please refer to the attached screenshot and code snip ...

Div vanishes once SVG Gaussian blur is applied

I'm attempting to add a Gaussian blur effect to an element that contains some child nodes with content. In Chrome, I successfully applied the blur using the following style: -webkit-filter: blur(2px); Unfortunately, Firefox does not support thi ...

Is it possible to generate an HTML element by utilizing an array of coordinates?

I have a set of 4 x/y coordinates that looks like this: [{x: 10, y: 5}, {x:10, y:15}, {x:20, y:10}, {x:20, y:20}] Is there a way to create an HTML element where each corner matches one of the coordinates in the array? I am aware that this can be done usi ...

Hover over CSS sprite

My anchor tag looks like this: <a href="#"> <i class="ico01"></i> <span>Text</span> </a> The ico01 class applies an image using CSS sprite. I want to change the background color of the entire content inside the a ...

Adjusting the repeating-linear-gradient CSS background

My goal is to make adjustments to a specific CSS code, in this case it is the repeating-linear-gradient. Take a look at my current implementation: input[type="range"]::-moz-range-track { background: repeating-linear-gradient(to right, #ccc, # ...

Incorporate user input into Alert Dialog Boxes

Would you be able to assist me in displaying the input value from the "email" field in my alert box? The code seems to be working fine, but I'm having trouble getting the alert box to show the email form value. I decided to use Bootstrap for som ...

What's the best way to layer a fixed div over an absolutely positioned div?

I am in the process of developing a small web application. In this project, I have two div elements - one is set to absolute positioning and the other to static positioning. My goal is to position the static div on top of the absolute div, ensuring that it ...

What steps can you take to ensure that a pre-loaded swf file occupies the entire browser

Allow me to elaborate on my query. I am currently designing a flash website and utilizing a small external preloader swf to load the main swf. I have successfully configured the preloader swf to occupy the entire browser window, however, once it loads in ...

Load and execute a dynamically created script in JavaScript at the same time

I am exploring the option to load and evaluate a script from a third-party synchronously. Here is an example that currently works well: <head> <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfe ...

I am currently working on a project using ar.js

I came across a glitch code that triggers a video when scanning the marker. However, I encountered an issue where it only works on desktop. On Chrome for Android, the video does not appear, only the sound can be heard. I need assistance as my coding knowle ...

Why are there no borders around the rows and columns of my table?

I'm just starting to learn HTML so I appreciate your patience with what may be a basic question for some. After creating a table using , I've noticed that there are no visible lines separating the cells. Is there a way to add lines around the ce ...

Scroll sideways with AJAX content replacement

I've successfully discovered various methods for loading and replacing content with ajax, as well as ways to hide/show with effects. However, I'm now seeking a technique that allows the new content to slide into a div while the old content slide ...