A round-shaped image with a rectangular box containing text beneath it

Looking for ways to create a responsive design that adapts to different screen sizes? I need my layout to be 2 columns on tablet view and 1 column on mobile view. Here's the CSS code snippet for an image inside a circle: Image within a circle


CSS
    overflow: hidden;
    width: 150px;
    height: 150px;
    border-radius: 150px;
    -webkit-border-radius: 150px;
    -moz-border-radius: 150px;
    border: 5px solid #000;
    position: absolute;
    background-color: #fff;
    left: 65px;
}

.bo>img {
    position: absolute;
    top: 20px;
}

Here is some HTML content: How We Manage LOOPTEK is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

<div class="row">
      <div class="col-md-3 col-sm-6">
        <div class="bo">
            <img src="imgs/icons/web.png" class="rounded" alt="Events and Activities" onload='fixAspect(this);'>
        </div>
        <div class="bo1 text-center">
          <h5>Web Design</h5>
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been</p>
          <button class="btn">viewport</button>
        </div>
      </div>

      <div class="col-md-3 col-sm-6">
        <div class="bo">
            <img src="imgs/icons/web.png" class="rounded" alt="Events and Activities" onload='fixAspect(this);'>
        </div>
        <div class="bo1 text-center">
          <h5>Mobile App</h5>
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been</p>
          <button class="btn">viewport</button>
        </div>
      </div>

      <div class="col-md-3 col-sm-6">
        <div class="bo">
            <img src="imgs/icons/web.png" class="rounded" alt="Events and Activities" onload='fixAspect(this);'>
        </div>
        <div class="bo1 text-center">
          <h5>Desktop App</h5>
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been</p>
          <button class="btn">viewport</button>
        </div>
      </div>

      <div class="col-md-3 col-sm-6">
        <div class="bo">
           <img src="imgs/icons/web.png" class="rounded" alt="Events and Activities" onload='fixAspect(this);'>
        </div>
        <div class="bo1 text-center">
          <h5>Game App</h5>
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been</p>
          <button class="btn">viewport</button>
        </div>
      </div>
    </div>
  </div>

Answer №1

Feel free to customize this example to fit your needs.

CSS

.caption div {
    box-shadow: 0 0 5px #C8C8C8;
    transition: all 0.3s ease 0s;
}
.img-circle {
    border-radius: 50%;
}
.img-circle {
    border-radius: 0;
}

.ratio {
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;

    height: 0;
    padding-bottom: 100%;
    position: relative;
    width: 100%;
}
.img-circle {
    border-radius: 50%;
}
.img-responsive {
    display: block;
    height: auto;
    max-width: 100%;
}

HTML

<div class="container">
<div class="row">
<h2>Any image, size doesn´t matter, centered and respecting ratio</h2>
</div>
    <div class="row">
        <div class="col-sm-2 col-md-6">
            <p> Image in to circle</p>
            <div  class="ratio img-responsive img-circle" style="background-image: url(http://trovacamporella.com/img/trovacamporella-fiat500.png);"></div></div>
          <div class="col-sm-2 col-md-6">
            <p> Image in to circle with link</p>
            <a href="http://trovacamporall.com" class="ratio img-responsive img-circle" style="background-image: url(http://trovacamporella.com/img/trovacamporella-fiat500.png);"></a>
        </div>
     
    </div>
</div>

Answer №2

To achieve this layout, you can utilize the power of Bootstrap:

<div class="container">
    <div class="row">
        <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6">
           <div class="img1"><img src="" class="img-fluid"></div>
        </div>
        <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6">
            <div class="img1"><img src="" class="img-fluid"></div>
        </div>
    </div>
</div>
  • This method utilizes Bootstrap 4 - remember to include it in your project either via a CDN or by downloading and serving it locally.

  • col-sm-12 : Targets mobile devices (576px to 767px) -> 12, representing one column

  • col-md-6 : Targets tablet devices (768px to 992px) -> 6, representing two columns
  • You can learn more about Bootstrap's grid system from resources like the Bootstrap website and W3Schools. Additionally, here is an example CSS snippet:

    .img1, .img2 {
        border:2px solid #000;
        border-radius: 50%;
        padding:20px;
    }
    
  • If you desire circular images, ensure you specify the height and width for the image elements, such as:

    .img1 img, .img2 img {
        height:100px;
        width:100px;
        line-height: 100px;
        border-radius:50%;
    }
    

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

What is the best way to include 2 or more radio buttons in every row of data within a table?

Is it possible to have multiple radio buttons for each row of data in a table? The current code snippet is as follows: echo '<table> <tr> <td>Home</td> <td>Not Home</td> <td>Address</td> <td>Su ...

Retrieve the position of an element using Python and selenium

Currently, I am working on a project and need to extract the location and size of an element using the following xpath: "//div[@class='titlu']" https://i.sstatic.net/PI1QE.png Upon inspection, it appears that the element is visible with no dist ...

Invoke a TypeScript function from the HTML code embedded within a TypeScript component

In my pop-up window, there are 2 buttons: Update and Delete. I need to implement functionality so that when the Update button is clicked, the current pop-up should disappear and a new editable pop-up with the same fields should appear, along with two addit ...

Analyzing Date Strings Retrieved From a MySql Database

In my MySQL database, I have a relationship that stores dates as varchar along with other attributes. This is how it looks: Answers answerId answer questionId date I am working on a web application where the user can select a &apo ...

Utilize a DIV element to apply a class to CKEditor

Currently, I am utilizing CKEditor in DIV mode instead of an IFRAME and I am facing a challenge in assigning a class to the editor itself. While I have managed to add classes to elements within the editor, figuring out how to assign one to the editor itsel ...

Utilizing the content of an HTML element within Ruby embedded code - a comprehensive guide

Below is the code snippet in question: <% @groups.each do |group| %> <tr> <td id="groupid"><%= group.id %></td> <td><a href="#dialog" name="modal"><%= group.title %></a></td> </tr> &l ...

What's causing this javascript to malfunction on the browser?

I encountered a problem with the code in my .js file. Here is a snippet of the code: $.extend(KhanUtil, { // This function takes a number and returns its sign customSign: function(num){ num = parseFloat(num) if (num>=0){return 1} ...

Tips on accessing a particular value from an HTML header

My current task involves using selenium to extract request headers from a web page. However, I am facing an issue where all request headers are being printed out, whereas I only need one specific value from them. Despite searching online, I have been unabl ...

What is the best way to restrict the selection of specific days of the week on an HTML form date input using a combination of JavaScript, React, and HTML?

I need help customizing my Forms Date Input to only allow selection of Thursdays, Fridays, and Saturdays. I've searched for a solution but haven't been successful so far. Is there any JavaScript or HTML code that can help me achieve this? Below ...

Dynamic use of a mixin in LESS allows for greater flexibility in

Is it possible to dynamically call a mixin in Less CSS? An interesting use case could be creating a style guide: // Define the mixin that needs to be called .typography-xs(){ font-family: Arial; font-size: 16px; line-height: 22px; } // A mixin att ...

Mobile users are experiencing trouble viewing a non-responsive website on their devices in a responsive

I'm currently facing a perplexing problem that I've never encountered before. I'm developing an application with Rails and the Foundation by Zurb responsive framework. Strangely, the website is not responsive on mobile devices, even though i ...

Altering documents post Bower installation

I took the initiative to manually download the css and js files for an angular module (here). In order to make a small adjustment, I modified the css (specifically changing max-width in the media query): Original: @media only screen and (max-width: 800px ...

jQuery not loading SCRIPT src after appending to HTML

I'm in the process of developing an application that requires me to load new HTML content and append it into the current page's HTML. So far, I've been able to load the new HTML using jQuery ajax. However, within this newly loaded HTML, the ...

The email width is exceeding 600px in all Outlook email clients

Fellow developers, I need your expertise! I've spent hours testing this email and researching why it's not conforming to a width of 600. Below is my code snippet and screenshots from Email on Acid - everything looks great except in Outlooks (exce ...

Using JQuery to create animations with fadeIn and fadeOut effects is a great way to

As a complete newbie taking my first steps in front-end development, I spent most of my day trying to work out an animation function but couldn't quite get it right. Below are the snippets of HTML, CSS, and JavaScript codes: <!DOCTYPE html> < ...

The alignment feature in the center is malfunctioning

I'm currently utilizing jQuery Mobile and have the following HTML along with CSS: .ui-grid-a { padding: 0; margin: 0; margin-top: 15px; height: 380px; } .ui-block-a, .ui-block-b { padding: 0; margin: 0; height: 33.3%; } .ui-block-a a, .ui-block ...

Aligning two lines next to a radio button using HTML and CSS

I'm facing a challenge where I want to align two lines in the middle of a radio button. Despite my efforts, I am able to line up the top line but struggling with the bottom one. I prefer not floating the radio button as it's being styled using a ...

Issue with the width on Mobile Safari

Encountering a strange problem with mobile Safari on iPads and iPhones where the body and some divs are getting cut off in the middle. Despite trying various solutions, I can't seem to fix it. The website works perfectly fine on desktop but not on mob ...

IE9: Enforce the browser and document modes of IE9

Currently in IE9, my webpage is rendering with the Browser Mode set to 'IE9 Compat View' and Document Mode as 'IE standards', causing issues with all canvas elements on the page. I have already ensured that I have included '' ...

Converting a JSON file into an HTML table using PHP

I need help figuring out how to display JSON data in an HTML table. I have a script that successfully outputs my JSON content, but I'm struggling to format it into a table. Below is the code I have so far: <?php $dir = "/Apache24/htdocs/reservat ...