Is there a way to simultaneously decrease or increase sizes in CSS?

I am currently developing a responsive website using basic CSS and HTML without the use of Bootstrap. I am looking to adjust the size of elements such as caption font and picture size to accommodate various devices. For example, my current code looks like this:

.footer-link{
font-size: 14px;
width: 80%;
padding-bottom: 20px;}

Now, I would like to decrease all sizes by 10% with just one line of code to achieve something like this:

.footer-link{
font-size: 12px;
width: 72%;
padding-bottom: 18px;}

I am aware of using media queries, but it requires me to rewrite each code and size for every media query. I am hoping to find a solution that allows me to reduce all sizes within the media query itself without having to duplicate code.

Unfortunately, I am unsure how to accomplish this. Does anyone have any recommendations?

Answer №1

To make your code responsive, you can use a @media query in CSS and specify the maximum width at which the inner code will be valid. For example:

@media  (max-width: 600px) {
 .footer-link{
    font-size: 12px;
    width: 72%;
    padding-bottom: 18px;}
}

This code will only be executed when the device has a maximum width of 600px.

You can also change the size to use em, rem, vw, vh, or % instead of the normal px property to add more dynamism to it.

If you want to learn more about creating responsive websites, check out this resource here.

Answer №2

Here is a sample CSS code snippet for adjusting the footer link style on a small device:

.footer-link{
  font-size: 14px;
  width: 80%;
  padding-bottom: 20px;
}

@media (min-width: 576px) {
  .footer-link{
  font-size: 12px;
  width: 72%;
  padding-bottom: 18px;}
}

If you need to customize the design for other screen sizes, simply create a new media query and update the styles accordingly. Bootstrap 4 defines the following breakpoints:

xs = Extra small <576px.
sm = Small ≥576px. 
md = Medium ≥768px.
lg = Large ≥992px. 
xl = Extra large ≥1200px.

Answer №3

Here are three effective methods to efficiently control font sizing in your CSS:

Method One:

1) Utilize the rem scaling measurement

Avoid using px, opt for the rem metric instead. The rem, or Root em, framework begins from a base value, set by the :root element, which is essential for the next step.

2) Employ @media queries to regulate the root-em size

After establishing the initial setting, customize it further using media queries to control the root-em (rem) value within each query.

Example:

:root {
    font-size: 16px; /* sets 1rem */ 
}
.footer-link{
    font-size: 0.9rem; /* 16 x 0.9 */
    width: 5rem;
    padding-bottom: calc(100% - 5rem);
}

@media screen and (max-width:500px){
    :root {
        font-size: 14px; 
    }
}

NOTE: Adjusting font-size: within html{ ... } might potentially conflict with browser settings (not confirmed by me).


Method Two:

Building upon Method One, incorporate CSS Variables for enhanced adaptability.

Example:

:root {
   --widthValue: 80%; 
   font-size: 16px; /* still necessary to establish 1rem */ 
}

.footer-link{
    font-size: 1rem;
    width: var(--widthValue);
    padding-bottom: calc(100% - var(--widthValue));
}

@media screen and (max-width:500px){
    :root {
        font-size: 15px;
        --widthValue: 76%; 
    }
}

CSS Variables allow fine-tuned adjustments not easily achievable with rem values. For more information, check out this resource.


Method Three:

Initially, I had a third method in mind, but the first two should sufficiently address your requirements.

I know about media queries, but I'm concerned about rewriting every section of code and adjusting sizes individually.

While modifications to your core CSS are inevitable, transitioning from static code to variable-based systems enables greater flexibility and ease of management.

The solution proposed emphasizes Don't Repeat Yourself principles--by altering a single value in a @media query, cascading style updates can be effortlessly propagated throughout your stylesheets.

Answer №4

The code snippet provided does not demonstrate a responsive website design. To achieve responsiveness, elements need to be redesigned and reordered accordingly. While images and backgrounds may require resizing, it is important to ensure that fonts, widths, and paddings do not become smaller on smaller screens. Otherwise, elements may appear disproportionately small.

One possible solution could involve implementing a zoom feature, particularly suitable for games or unique interfaces.

Without utilizing CSS media queries or modifying existing CSS rules, JavaScript can be used to achieve a uniform zoom effect relative to the window size. Below is a simple example demonstrating how this can be implemented:

Feel free to resize the window to observe the changes:

var myDesignWidth = 500; //initial width of the design

$(window).on("load resize", function(){
   var newZoom = $(window).width() / myDesignWidth;
   $("body").css({"zoom": newZoom});
})
.footer-link{
font-size: 14px;
width: 80%;
padding-bottom: 20px;
display: inline-block;
background: url('https://d1o2pwfline4gu.cloudfront.net/m/t/13116/13106367/a-0270.jpg');
background-size: cover;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="footer-link">This is a footer link with background</a>

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

The video on my site is refusing to play

I'm having an issue with a 2-second video that is not playing, yet when I tried a 10-second video it worked perfectly. Why is this happening? Could it be that HTML does not support videos that are shorter than 1-2 seconds? It seems like it's onl ...

The Dreamweaver code is visible on the design page but does not appear in the live view on the browser

Experimenting with something and created the top section of the site (Logo and menu). However, when I tried to add a table with text, it doesn't appear in the browser preview even though I can see it in the CODE and DESIGN tabs of Dreamweaver. I susp ...

Ways to create the initial row text in jqgrid treegrid appear bold

Trying to make the text in the first row of a jqgrid treegrid bold? Here's what I attempted: #tree-grid .cell-wrapper { font-weight: bold; } However, this makes all nodes bold. How can I make only the first node (first row) bold? The treegrid i ...

Tips for enhancing webpage load times by optimizing CSS and jQuery file handling

As a beginner in HTML and CSS, I am facing slow loading times when testing my pages on a local server. This makes me concerned about the potential loading time on the internet. Currently, I have all the files included in the <head> tag at the top of ...

Having trouble finding an element within a span class with Python Selenium

I've been having trouble finding a specific element within a span class. The element in question is a radio-checkmark button. Here's the HTML snippet: <span class="radio-container" for="searchType_2"> <input class=&qu ...

Is it possible to modify a website's CSS permanently using just the browser?

Is there a way to make changes to CSS in a large project using Firefox's built-in developer tools and have them saved permanently? I've been trying to edit the style sheets, but couldn't locate the specific property I needed. Since I can&apo ...

Tips for organizing SQL queries in a grid layout

I have a database table called People in SQL and I am displaying the names of people from this table on my website. Each name is represented as a column in the People table. My goal is to arrange these names in a grid layout, similar to a table, but with ...

Tips for adjusting navbar background color according to screen size

When my navbar collapses on smaller screens, it becomes hard to read due to the expansion over my content. I want to change the background color of the navbar only on small and extra-small screens. How can I achieve this? This is my HTML code: <nav cla ...

adjust bootstrap column width to fill the container

https://i.stack.imgur.com/tCuL6.png I am hoping that this image will provide a visual aid for what I am trying to convey. My goal is to have the arrow and the boxes aligned in a row without any empty space on the right side. As you can see, the leftmost b ...

What is the best way to animate an element when it comes into the user's view

In order to activate the animation of the skill-bars when the element is displayed on the website, I am seeking a solution where scrolling down through the section triggers the animation. Although I have managed to conceptualize and implement the idea with ...

I am having trouble adding multiple items on different occasions - is it something to do with JQUERY

I have been working on a dynamic website that loads Firebase values into a table. However, I encountered an issue where the data does not appear when going back to the orders page after visiting another page. After some testing, I found that placing a but ...

The functionality of Small Caps is not supported by Twitter Bootstrap when using Chrome browser

I am working with a very basic markup <h1> <a href="#"> My Title </a> </h1> and I have this CSS applied h1 { font-variant: small-caps; } You can see the result on this jsfiddle link. The problem arises when u ...

Guide to concealing pop-up with animation when clicking outside

My question is: Clicking on OPEN should open the popup. Clicking on BACK should close the popup. Clicking outside the popup should also close it. Note: Clicking inside the popup when it is open should not close it. The popup should only close on an outs ...

Video on YouTube restarts upon hiding and revealing its container div

Is there a way to retain the progress and playback position of a YouTube video embedded within a div on a webpage? Currently, when I hide and then show the div using jQuery/CSS, the video reloads and starts from the beginning. Is there a solution to avoid ...

What is the best way to choose a disabled field using Watir?

Recently, I've encountered an issue with my webpage's popup functionality. It used to work smoothly, with fields that could be manipulated when the popup was visible. However, I've noticed that now, when I try to inspect these fields using f ...

Java web project experiencing issues with CSS style sheets not being applied

I am exploring Java Web development for the first time using Netbeans IDE 8.0.2. To style my pages, I have placed my CSS files in an assets folder located at the same level as WEB-INF under the Web Pages directory. I have added the CSS files using the foll ...

Manipulate the DOM to remove a checkbox using JavaScript

I'm brand new to exploring the world of Javascript and could use some guidance with this task. I have a collection of checkboxes that I'd like to manipulate so that when one is checked, it disappears from the list automatically. I've come ac ...

Modifying an image using JavaScript and CSS

I've been experimenting with adding an Adblock detector that will show one image when detecting Adblock and another when not detecting it. The challenge lies in the fact that CSS controls the display and formatting of the image. Is there a way to mani ...

Can anyone provide guidance on activating bootstrap tabs-left in bootstrap 3.3.x?

I've noticed that the style nav-tabs left isn't functioning in Bootstrap versions 3.3.0 and 3.3.2. I'm curious if anyone has found a way to re-enable this style so that tabs can run vertically with content displayed on the right. For those ...

Use Python to enter a value on a webpage coded in HTML

My current project involves automating the input of values into a webpage. However, I have encountered a significant hurdle with the Mechanize library as it does not recognize the forms on my page which are <input> elements, unlike the typical form.n ...