Adjusting HTML/CSS for various screen sizes and devices

I have designed a website, but when it is viewed on devices like iPad or iPhone, the layout does not adjust to fit the screen properly. The text box containing my name and social media buttons appears on the left side, while the background image is positioned on the right side with whitespace in between these elements. I want the website to be responsive and work seamlessly in both portrait and landscape modes on mobile devices as well as desktop browsers, resizing accordingly.

How can I integrate this functionality into my code?

HTML:

 <head>
   <meta charset="UTF-8">
   <title>My site!</title>
   <link href="background.css" rel="stylesheet" type="text/css">
 </head>

 <body>
   <section class="background">
    <div class="foreground">
     <div class="name-tag">MY SITE!
     </div>
      <ul class="social-media-list">
        <li class="social-media-link">
          <a href="https://twitter.com/" target=_blank"><img src="https://cdn3.iconfinder.com/data/icons/capsocial-round/500/twitter-128.png"></a>
    </li>
    <li class="social-media-link">
      <a href="https://www.youtube.com/"><img src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/youtube_circle-128.png"></a>
    </li>
    <li class="social-media-link">
      <a href="https://www.linkedin.com/in/" target=_blank"><img src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/linkedin_circle_color-512.png"></a>
    </li>
    <li class="social-media-link">
      <a href="https://www.instagram.com/" target=_blank"><img src="https://cdn2.iconfinder.com/data/icons/black-white-social-media/32/instagram_online_social_media-128.png"></a>
    </li>
  </ul>
</div>
  </section>
 </body>

 </html>

CSS:

   /* Body Margin*/

body {
  margin: 0;
 }


 /*  Font family avenir-light*/

 @font-face {
   font-family: 'avenir-light';
  src: url('fonts/avenir-light.eot') format('eot'), url('fonts/avenir-light.woff') format('woff'), url('fonts/avenir-light.ttf') format('ttf');
}


 /* Background Div*/

.background {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
}


 /* Background Div: after*/

.background:after {
   position: absolute;
   width: 100vw;
   height: 100vh;
   content: '';
   background-image: url("bkgd.jpg");
   background-repeat: no-repeat;
   background-size: cover;
   -webkit-animation: fadein 3s;
   /* Safari, Chrome and Opera > 12.1 */
    -moz-animation: fadein 3s;
    /* Firefox < 16 */
    -ms-animation: fadein 3s;
   /* Internet Explorer */
   -o-animation: fadein 3s;
   /* Opera < 12.1 */
   animation: fadein 3s;
   /*Fade In Animation*/
 }


 /* Fade in animations */

 @keyframes fadein {
   from {
     opacity: 0.2;
   }
   to {
     opacity: 1;
   }
}


 /* Firefox < 16 */

 @-moz-keyframes fadein {
   from {
    opacity: 0.2;
   }
   to {
     opacity: 1;
   }
 }


  /* Safari, Chrome and Opera > 12.1 */

  @-webkit-keyframes fadein {
    from {
     opacity: 0.2;
       }
    to {
     opacity: 1;
   }
 }


 /* Internet Explorer */

 @-ms-keyframes fadein {
   from {
     opacity: 0.2;
   }
   to {
     opacity: 1;
   }
 }


 /* Opera < 12.1 */

 @-o-keyframes fadein {
   opacity: 0.2;
 }

 to {
   opacity: 1;
 }


 /* Foreground div */

 .foreground {
   margin-top: 20px;
   position: relative;
   width: 400px;
   height: 100px;
    background-color: #eaeaea;
    padding: 20px;
    border: 1px solid #555;
     border-radius: 10px;
   /*Fade In Animation*/
   -webkit-animation: fadein 5s;
   /* Safari, Chrome and Opera > 12.1 */
  -moz-animation: fadein 5s;
   /* Firefox < 16 */
   -ms-animation: fadein 5s;
   /* Internet Explorer */
   -o-animation: fadein 5s;
   /* Opera < 12.1 */
   animation: fadein 5s;
    z-index: 1;
   }


 /* Name Tag */

  .name-tag {
   font-family: 'avenir-light';
   text-align: center;
    font-size: 24px;
  }


 /* Social Media List*/

 .social-media-list {
   list-style: none;
    display: flex;
    justify-content: space-around;
     padding: 0;
    }


  /* Social Media Item*/

  .social-media-link img {
   height: 50px;
   width: 50px;
  transition:all 0.5s ease;
  }

 .social-media-link img:hover {
  -ms-transform: scale(1.2);
  /* IE 9 */
  -webkit-transform: scale(1.2);
   /* Safari */
   transform: scale(1.2);
  /* Standard syntax */
 }

Answer №1

To achieve this goal, consider utilizing Bootstrap. Bootstrap organizes the screen into a grid system with 12 columns, allowing for various layout options. Depending on the device size, classes such as col-md-3 for medium screens or col-sm-3 for small screens can be used to customize your design accordingly.

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

Pattern matching to remove HTML tags

I'm attempting to remove a portion of a string that doesn't comply with my specified pattern. For instance, in the following code snippet: <SYNC Start=364><P Class=KRCC> <Font Color=lightpink>abcd I want to eliminate: <P C ...

I'm having trouble pinpointing the origin of the gap at the top of my website, even after thoroughly reviewing all my tags

After setting margins and padding of 0 for both html and body, all my top-level elements inherited the same styling. I'm hoping to avoid using a hacky solution like adjusting the positioning. Any tips on how to achieve this without resorting to hacks ...

Unusual shift in the modal's behavior occurs when the parent component's style.transform is applied

I have encountered an unusual issue with a modal's appearance and functionality. The modal is designed to enlarge images sent in a chat, with the chat upload preview div serving as the parent element and the modal as the child element. This strange be ...

Creating an interactive button using RichFaces and Bootstrap for seamless Ajax functionality

I have a challenge with making a fully clickable span or button that includes a Bootstrap refresh glyph-icon. The current code I have inherited only allows the icon itself to be clicked, leaving the area between the icon and button border unclickable. This ...

Guide on making a Vue.js show/hide button for each element on a webpage

There is a feature to toggle between displaying "more" or "less" text, but currently the @click event affects all elements causing them to show all the text at once. I realize that I need to pass a unique value to distinguish each element, but I am curren ...

Creating a Mobile-friendly Sidebar: A Guide to Angular 5

I've been seeing a lot of recommendations online about using Angular Material for creating a sidebar, but I'm hesitant to install an entire library just for one component. After following the instructions provided here, I managed to develop a si ...

Can MUI 5 replicate the Emotions 'css' function through analog?

From what I've learned, MUI 5 utilizes Emotion for its styling framework. Emotion offers a convenient helper function called css, which generates a string - a class name that can be used as a value for the className property or any other relevant prop ...

Layer one div background image over another div background image

My goal is to have the Mario image displayed on top of the background seen in the screenshot below. While I've managed to get it working, I'm struggling to center the Mario image properly over the background. Additionally, I would like to elimina ...

Sending a CSS class to an Angular library

In my development process, I am currently working on creating a library using Angular CDK specifically for custom modals. One feature I want to implement is the ability for applications using the library to pass a CSS class name along with other modal conf ...

Is it possible to distinguish CSS for varying input types?

Is it possible to style input type=text/radio/checkbox elements differently using CSS? I'm referring to ways other than just adding a class ...

Obtain the value of "data-something" attribute from an <option> element within a <select> element

Can anyone help me with this HTML snippet? <select id="something"> <option value="1" data-something="true">Something True</option> <option value="2" data-something-else="false">Something Else False</option> </selec ...

Adjust the size of a panel in Extjs when its parent div is resized

Within my div, I have included an Extjs panel using the renderTo configuration option. Can someone please advise on how to adjust the panel size dynamically when the div is resized? Appreciate any help! Thank you. ...

Ways to adjust the font size of mat-menu-item?

I came across a query regarding this matter on another platform: How can the font size of mat-menu-item be changed to small in Angular? Unfortunately, the solution provided did not work for me. I attempted to implement the suggested code in my Angular a ...

Are HTML files and PHP generated files cached differently by web browsers?

My current setup involves Nginx as a web server and Firefox to check response headers. I added two files on the server - test.html and test.php, both containing the same content. In the Nginx config file, I have set the expires directive to 30d in the serv ...

Are Bootstrap classes like "row row-md" or "row row-cols" compatible with images?

I'm having an issue where the images are not displaying properly. When I try replacing the image line with something like <h1></h1>, it works just fine. Why is this not working with images? I also attempted using div class="col col-lg ...

Using CSS background-image URL in .NET MVC tutorials

What is the correct way to route to an image in an MVC web application? MVC has default routes, meaning you can access the same page in multiple ways: 1. localhost 2. localhost/home/index However, you can also do it this way, changing the root directory. ...

Creating a flexible Tic Tac Toe board using only HTML and CSS without any JavaScript

I'm currently tackling an HTML layout challenge that involves creating a responsive Tic Tac Toe board using only HTML and CSS, without any JavaScript. This is how I have structured the layout of the board: <div class="board"> <div class= ...

What is the best way to determine if a date is empty using Vuetify?

Could someone help me with checking if a date was entered by the user? I want to display an error message if a date is not provided. I attempted to use a rule for this purpose, but unfortunately it's not showing any error message. Below is the code I ...

Inject a dynamic URL parameter into an iframe without the need for server-side scripting

I'm really stuck and could use some assistance with the following issue, as I am unable to solve it on my own :( When a user is redirected to a form (provided via an iframe), there is a dynamic URL involved: website.com/form?id=123 The code resp ...

Achieve a stunning visual effect by placing images behind the background using HTML and

I'm currently working on developing a webpage with a slideshow feature. I've decided that I want the transition between images in the slideshow to be a smooth fade effect, going from color to image to color. To achieve this, I have set up a backg ...