Styling CSS: Create circular images with dynamic text positioning or resizing on screens larger than 768px

I'm struggling to figure out how to create a circular profile picture on a background image that remains responsive and maintains its position across different screen sizes.

Currently, I've been using fixed margin values to adjust the position, but I don't think it's the best approach. The alignment in the code snippet below is off. I'm unsure of how to code the width and height so that the profile pic stays in an ideal position on all screens. How should I set the margins or padding correctly? I've tried using col-sm and col-md with various parameters, but only col-md seems to work.

My desired output looks like this: https://i.stack.imgur.com/BX0ME.png

On iPhone X, the positioning of the profile pic and text is fine with the current code. https://i.stack.imgur.com/vMXZU.png

However, on iPad, the positioning is incorrect. https://i.stack.imgur.com/i7Dly.png

The position is also off on iPhone 5/SE.

https://i.stack.imgur.com/XDfWw.png

I've included a link to the JSFiddle for reference. Please provide assistance.

  <style>
    
    #sfitness{
        position:relative;
    }

    * {
        box-sizing: border-box;
        font-family:Arial;
        font-size:12px;
    }

    img {
        width: 100%;
    }

    .prof{
        width:90%; 
        position:absolute;
        top:150px;
        left:4%;
    }

    .user{
        border-radius:75%; width:80px; height:80px;
    }
    
    .name, .pic{
        float:left;
    }

    .name{
        margin-left:-25px;
        margin-top:20px;
    }
    
    .name span{
        display:block; 
        text-transform:none; 
        font-size:8px;
    }
    
    .name p{
        text-transform:uppercase; 
        font-size:10px;
        line-height:10px;
    }

    .credit{
        float:right; 
        margin-top:48px
    }
    
    .credit-pic{
        width:10px;
        height:10px;
    }

</style>

</head>

<body id="sfitness">
<img src="https://image.ibb.co/byLwy9/profilepic.png" alt="profilepic" border="0">

<div class="container-fluid" style="">
    <div class="row">
        <div class="prof">
            <div class="col-4 pic">
                <img class="user" src="https://image.ibb.co/gGYzJ9/312eaeaba498116ab7c4cfb6ec22a049.jpg" border="0">
            </div>
            <div class="col-4 name">
                <p>Jane Wong <span>Kuala Lampur</span></p>
            </div>
            <div class="col-4 credit">
                <img class="credit-pic" src="https://image.ibb.co/e7UQRU/Asset_19_4x_8.png" /><span style="font-size:8px">  0 credit</span>
            </div>
        </div>
    </div>
</div>

</body>

Answer №1

One helpful tip is to utilize media queries for a more responsive design.

To create rounded images, you can use border-radius:50%; and specify the image's width and height.

.user{border-radius:75%; width:100px; height:100px;}
.name, .pic{float:left;}
.prof{width:300px; position:absolute; bottom:-35px; left:4%;}
.name{padding:25px 10px;}
#sfitness{position:relative;}
.name span{display:block; text-transform:none; font-size:16px;}
.name p{text-transform:uppercase; font-size:18px;}
<body id="sfitness">
  <img src="https://image.ibb.co/byLwy9/profilepic.png" alt="profilepic" border="0">

  <div class="container-fluid" style="">
    <div class="row">
    <div class="prof">
      <div class="col-4 pic">
      <img class="user" src="https://image.ibb.co/gGYzJ9/312eaeaba498116ab7c4cfb6ec22a049.jpg" border="0">
      </div>
      <div class="col-8 name">
        <p>Jane Wong <span>Kuala Lampur</span></p>
      </div>
      </div></div>



</body>

Answer №2

After making the updates, the code is now responsive. It appears that you are utilizing Bootstrap as well. I made adjustments to the classes and CSS accordingly.

If you inspect the elements .user, .information, .information p, you will notice that 'information' is a new class.

* {
  box-sizing: border-box;
  font-family: Arial;
  font-size: 12px;
}

img {
  width: 100%;
  
}

.profile-name {
  text-align: left;
  font-size: 12px;
  font-weight: bold;
  margin-top: 5%
}

.user {
  display: inline-block;
  width: 80px;
  height: 80px;
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
  object-fit: cover;
float: right;
}

p {
  display: flex;
  flex-direction: column;
}

.information {
    line-height: 16px;
    margin-top: 20px;
}
.information p {
    font-size: 152%;
    font-weight: bold;
    line-height: 19px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<body id="sfitness">
  <img src="https://image.ibb.co/byLwy9/profilepic.png" alt="profilepic" border="0">
  <div class="container-fluid" style="">
    <div class="row" style="margin-top:-60px">
      <div class="col-xs-4 col-sm-6 col-lg-1">
      <img class="user" src="https://image.ibb.co/gGYzJ9/312eaeaba498116ab7c4cfb6ec22a049.jpg" border="0">
      </div>
      <div class="col-xs-6 col-sm-8 col-lg-10 information">
        <div class="row">
        <p>Jane Worng<span>How are you</span></p>
      </div>
        </div>
    </div>



</body>

https://i.stack.imgur.com/log8Q.png

Answer №3

Utilize Media Queries to make your design responsive. It's much simpler than using javaScript:

body{
    background-color: white;
}    

@media only screen and (max-width: 750px) {
        body {
            background-color: black;
        }
    }

In this instance, the background-color of the body remains white as long as the screen width is 750px or greater.

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

Excessive content - letter "y" disrupts the row layout on mobile devices

I have created a custom CSS class called "custom-class" and applied it to the col div. This column contains dynamic images, so I have added a vertical scrollbar property to handle the overflow. While everything looks fine on a desktop, the layout breaks o ...

What is the best way to include a text input as the last option in a Select input form field?

I would like to implement a select input feature where users can choose from predefined options, with the added functionality of including a text input field as the last option for users who prefer to enter their own category. How can I achieve this? Curr ...

The transition effect of changing opacity from 0 to 1 is not functioning properly in Firefox

Having some trouble with this animation not working in Firefox. I'm triggering the animation using JavaScript after a delay like so: document.getElementById('my_id').style.webkitAnimationPlayState = "running"; I've also attempted: s ...

"Utilizing AngulaJS to apply a class to the parent element when a radio button is

I'm wondering how I can assign a class to the parent div of each radio button in a group? You can find the code below and view the corresponding JSFiddle here. Here is the HTML: <div class="bd"> <input type="radio" ng-model="value" val ...

"Utilizing a media query to display an anchor link at the top based

How can I create a "Back to Top" link that automatically scrolls mobile and tablets to the top of the page? Usually, I would achieve this using JavaScript by detecting the window and body height. Is it possible to accomplish this using a media query? @me ...

What is the best way to make a div that maintains its size even when the content inside is modified?

My goal is to develop a media feed that includes various types of content such as text, images, and videos. To ensure user safety, I want to conceal any explicit posts with a warning that requires the user to click in order to view the content. Although I ...

When you hover over the Dropdown Menu, the Hoverable Dropdown Menu will automatically close

I am currently working on creating a dropdown menu that pops up when hovering over an item. However, I am facing two challenges: Once my mouse moves away from the item, the dropdown disappears. Therefore, I would like the dropdown to remain visible as lo ...

The positioning of drawings on canvas is not centered

I'm facing an issue while attempting to center a bar within a canvas. Despite expecting it to be perfectly centered horizontally, it seems to be slightly off to the left. What could possibly be causing this discrepancy? CSS: #my-canvas { border: ...

Is there a way to remove background-color for a:focus?

When working with Twitter Bootstrap, I encountered a challenge. The background-color properties set for navigation items on the :focus state were causing an issue for a specific navigation element that needed have its own styling. Imagine a scenario where ...

AngularJS seems to be ignoring CSS styles when displaying list items in the ng-repeat loop

After coming across a tutorial on creating round circles connected by a line in CSS, I decided to implement it myself. Interestingly, everything worked perfectly fine when I tested it with static HTML. However, when I tried to make it dynamic using Angular ...

Proper HTML style linking with CSS

Describing the file structure within my project: app html index.html css style.css The problem arises when trying to link style.css as follows: <link rel="stylesheet" type="text/css" href="css/style.css"/> S ...

Having trouble identifying the specific CSS property that is being used or inherited

I have incorporated components from Twitter Bootstrap CSS into a custom CSS file, focusing mainly on toolbar components. Specifically, I have set up a toolbar with various features. However, when applying additional CSS to the .signinbox_left:hover select ...

Background color set for only half of the div

Is it possible to achieve a design similar to this using CSS, with a Half-background color for a div? ...

Preventing ReactJS tooltips from exceeding the boundaries of the screen

Here is a simple demo showcasing blocks with tooltips that appear when hovered over. However, there seems to be an issue with the functionality. The tooltip should ideally be displayed either from the left or right side of the block. To determine the size ...

Tips for eliminating default classes from Mui Typography styling

I’ve been working on creating a Typography element and noticed some default MUI CSS classes added when debugging in the browser. I attempted to disable them by using empty arrays at the end of the sx prop, but it did not work as expected. In the image p ...

Troubleshooting the problem of divs overlapping when scrolling in JavaScript

I am experiencing some issues with full screen divs that overlay each other on scroll and a background image. When scrolling back to the top in Chrome, the background shifts down slightly, and in Safari, the same issue occurs when scrolling down. I have cr ...

Customize the yellow background color of Safari's autofill feature by following these simple

When I open this image in Safari, this is what I see: https://i.stack.imgur.com/KbyGP.png However, this is the code I have: https://i.stack.imgur.com/4wEf0.png References: How to Remove WebKit's Banana-Yellow Autofill Background Remove forced ye ...

The value entered is displaying as not defined

As a newcomer to the world of javascript, I am diving into creating a simple To Do list. The basic functionality is there, but I'm scratching my head trying to figure out why the input value in my code keeps returning undefined. The remove button is ...

Tips for adjusting the item count in mat-autocomplete

For quite some time now, I've been attempting to adjust the number of items in a mat-autocomplete without any luck. My project involves using material.angular.io Below is a snippet of my code import { Component, OnInit } from '@angular/core&a ...

Adjust the column count in mat-grid-list upon the initial loading of the component

My goal is to implement a mat-grid-list of images with a dynamic number of columns based on the screen size. Everything works perfectly except for one small glitch – when the grid first loads, it defaults to 3 columns regardless of the screen size until ...