Tips for converting all elements (divs) on a website from pixels to percentages

Recently, I received this website project from a friend for development. I haven't worked with CSS for a while, and I'm facing a few challenges. My main goal is to ensure that the website adjusts seamlessly to different browser sizes.

The issue seems to be caused by the use of pixel measurements instead of percentages in the classes, making the layout fixed. I need to figure out how to convert all these classes to percentages so that the webpage becomes fluid and responsive to varying window sizes. I assume this involves some mathematical calculations?

I don't believe @media queries will be useful in this scenario.

Here is a snippet of the HTML code:


   <!doctype html>
   <html>
   <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
   <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
   <title>Vivid Shop Display</title>
   <link rel="stylesheet" href='css/vivid-style.css'>
   <link rel='stylesheet' href='css/scroller.css'>
   <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
   </head>
   
   <body>
   <header>
   <div class="vd-navigation-wrapper">
     <div class="vd-settings-wrapper">
        <div class="vd-user-settings">
        </div>
        <div class="vd-currency-selector">
        </div>
        <div class="vd-language-selector">
        </div>
     </div>
     <div class="vd-nav-wrapper">
            <ul>
                <li>Shop</li>
                <li>About</li>
                <li class="vd-logo-img"><img src="img/vivid_logo.png"/></li>
                <li>Lookbook</li>
                <li>Contact</li>
            </ul>
     </div>
      <div class="vd-cart-wrapper">
       <div class="vd-cart-selector"></div>
      </div>
   </div>
   ...
   

And here is a snippet of the CSS code:


   @charset "UTF-8";
   /* CSS Document */

   html {}
   body {
       margin:0px;
       padding:0px;
   }
   h1,h2,h3,h4,h5,h6,p,ul,li,span {
       margin:0px;
       padding:0px;
   }
   ...
   

Answer №1

To customize the appearance of your website, you'll need to make adjustments to the CSS file.

Start by focusing on the outer DIVs and then move towards the inner elements. If you want an element to span the full width, you can apply CSS similar to the following:

.elementClassName{
   width: 100%
}

In HTML, we can use id="idnamehere" within a tag to identify it specifically for CSS targeting. Additionally, using class="classname" allows for more general CSS rules that can be applied to multiple elements.

Consider creating custom classes in your CSS file like:

.Fullwidth{
  width: 100%
}

.halfWidth{
  width: 50%
}

Once you've defined these classes, you can experiment by adding them to the outer DIV element. For example, adding class="halfWidth" to the outer DIV will cause the page to only fill half of the browser window when refreshed. Keep in mind that child divs inherit properties from their parent divs.

Research the Box Model concept in HTML for more insights.

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 Angular overlay is concealed beneath the pinned header

I am seeking a solution to have a mat-spinner displayed on top of my app while it is in the loading state. Currently, I am using an overlay component with Overlay from @angular/cdk/overlay. The issue arises when part of the spinner that should be overlai ...

Rebel Spirit on a Wordpress Platform

I've encountered a strange issue on my Wordpress blog. For some reason, the code "&nbsp" is being inserted right after the opening <body> tag. I have checked the header.php file and there is no instance of this code present there. It's ...

Styling for dropdown menu button

I'm encountering an issue with a button styled dropdown. Here is the code snippet: <template> <div class="datatable-wrapper"> <div class="table-container"> <table class="table datatable-table i ...

Turned off jquery on a specific div in order to resolve compatibility problems with Vue.js

Currently, I am working on a Drupal project which includes JQuery in all pages. We have recently introduced Vue.js for creating dynamic components directly in the HTML pages (not for building a single-page application). However, we are facing an issue whe ...

Is there a way to efficiently center an image within an HTML document using HtmlAgilityPack?

I recently created a basic HTML document using the HtmlAgilityPack, which includes an embedded image in base64 format. Dim myDocument As New HtmlDocument() Dim pageContent As String = "<!DOCTYPE html> <html> <body> <img src=""data:im ...

When using nextjs, there is an issue that arises when attempting to define the property 'id' using context.params.id. This results in

Attempting to retrieve data from a JSON file (response.json) hosted on localhost:8000/response.json. Below is the code snippet from pages/test.js: import React from "react"; import Link from "next/link"; import Image from "next/ima ...

Swapping out a <DIV> element following a specified duration

Looking to swap out DIV-A with DIV-B on a landing page after 10 seconds. After some research, it seems like JQUERY is the best option, but I'm unsure about how to proceed. Most solutions involve cycling through DIVs or replacing them on a button clic ...

"To ensure consistent alignment, position list items with varying heights at the bottom of the

Is there a way to align a series of li items to the bottom of their parent, the ul, without using any unconventional methods? The challenge lies in the fact that these li items need to have a float: left property and vary in height and width. Below is my ...

Break the line after every space in words within an element

I have a table/grid view with two words in the <td> like "C2 Sunday". I need a line break after C2 so that it appears as: C2 Sunday Is there a way to achieve this? Please assist me with this issue. Currently, it is showing as "C2 Sunday" and I wou ...

After the decimal point, there are two digits

My input field is disabled, where the result should be displayed as a product of "Quantity" and "Price" columns ("Quantity" * "Price" = "Total"). However, I am facing an issue where the result often displays more than 2 digits (for example: 3 * 2.93), desp ...

What is the best way to showcase my subscription form on a web browser?

I am encountering an issue with my code. My goal is to generate a subscribe form modal. Although I have incorporated the subscribe form in my HTML document, upon running the code in the browser, the subscribe section is not visible. Can anyone offer assist ...

The unusual behavior of a page refresh in jQuery when replacing content

My website features a flash player. This code references the flash player stored in player_codes.php: <script language="javascript" type="text/javascript" src="songs_related/flashmp3player/swfobject.js" ></script> <!-- Div that contains pl ...

What is the best way to use AngularJS to extract values from the first dropdown menu that are linked to the values selected in the second

How can I link values in two dropdowns using AngularJS? Hello everyone, I have set up two dropdown fields in MyPlunker and within the ng-option tag, I have applied a filter like filter:{roles: 'kp'} to only display users with the role of kp. T ...

why is it that I am not achieving the expected results in certain areas of my work?

I am facing issues with getting an alert response from certain buttons in the code. The AC button, EQUALS button, and the button labeled "11" are not behaving as expected. I have tried troubleshooting but cannot identify the problem. Can someone please ass ...

Incorporating the <sub> element while maintaining the line height

I am facing a challenge with formatting text that includes subscripts and superscripts tags. For example: <div>hello <sub>world</sub>, how are you? Translated as logical aggregates or associative compounds, these characters have been int ...

Leveraging multiple ">" CSS selectors

Here is the HTML code to style: <table id="my-table"> <tr> <td> I would like to customize this </td> <td> <table> <tr> <td> Not looking to customize t ...

Trouble aligning content in CSS? Try using justify-content center for perfect centering!

I am facing an issue with centralizing the content properly. Despite using justify-content:center, the layout breaks. https://i.sstatic.net/EMiw1.png When I apply justify-content:center, the layout appears like this: https://i.sstatic.net/lTJRi.png Her ...

Tips on utilizing the event.preventDefault() method within AngularJS?

Recently, I stumbled upon a technique to prevent page refreshing after submitting a form by using event.preventDefault();. As someone who is still learning Angular, I am unsure of how to incorporate this syntax into my Angular controller. Is "event" some s ...

How can we use withStyles to customize the styling of a selected ListItem in ReactJS and Material UI?

I am seeking assistance in changing the style of a specific ListItem, similar to what is demonstrated in this Codesandbox. In the Codesandbox example, a global CSS stylesheet is utilized, but I prefer to implement the changes using the withStyle techniqu ...

Leveraging node.js and express for incorporating custom stylesheets and scripts

I recently designed a webpage with the following elements at the beginning: <link href="./css/font-awesome.min.css" rel="stylesheet"> <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet ...