Dynamic Text Challenge

Below is the code snippet I am working with:

body{
    width:100%;
    font-family:sans-serif;
    background: transparent;  
}
.testimonials{
    margin:0;
    display:grid;
    grid-template-columns: repeat(auto-fit,minmax(350px, 1fr));
    grid-gap:20px;
}
.testimonials .card{
    position:relative;
    width:350px;
    margin:0 auto;
    background:#333;
    padding:20px;
    box-sizing: border-box;
    text-align:center;
    box-shadow: 10px 8px 20px rgba(0,0,0,.5);
    overflow: hidden;
}
.testimonials .card .layer{
    position: absolute;
    top: calc(100% - 3px);
    width:100%;
    height:100%;
    left:0;
    background:linear-gradient(#034e70, #390375);
    z-index:1;
    transition:0.5s;
}
.testimonials .card:hover .layer{
    top:0;
}
.testimonials .card .content{
    position:relative;
    z-index:2;
}
.testimonials .card .content p{
    font-size:18px;
    line-height:24px;
    color:#FFF;
}
@media all and (max-width: 500px) {
.testimonials .card .content p{
width: 100%;
}
}

.testimonials .card .content .image{
    width:100px;
    height:100px;
    margin: 0 auto;
    border-radius:50%;
    overflow:hidden;
  margin-bottom: 16px;
    box-shadow: 0 10px 20px rgba{0,0,0, .2};
}
.testimonials .card .content .details h2{
    font-size:15px;
    color:#fff;
}
.testimonials .card .content .details h2 span{
    color:#03a9f4;
    font-size:12px;
    transition:0.5s;
}
.testimonials .card:hover .content .details h2 span{
    color:#fff;
}
<section id="References">
      <div class="section-title">
        <h2>References</h2>
        </div>
    <div class="testimonials">
    
    <!-- CARD 1 START-->
    <div class="card">
      <div class="layer"></div>
      <div class="content"> 
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vulputate dui a eros pretium commodo sit amet quis tortor. Maecenas suscipit suscipit est non ullamcorper. Fusce tincidunt, eros non ornare mollis, enim erat placerat erat, dignissim egestas magna elit eget dolor. Nullam sed leo maximus, ullamcorper ante lacinia, semper augue. Etiam convallis tempus elit.</p>
        
        <div class="image">            
          <img src="https://static-exp1.licdn.com/sc/h/244xhbkr7g40x6bsu4gi6q4ry" alt="">
           
        </div>
        
        <div class="details">
          <h2> Sample Text <br>
           <span>Sample Text Goes Here Too</span>          
          </h2>
         </div>
         
       </div>
     </div>
     
     <!-- CARD 1 end-->

    <!-- Additional card examples can be added here -->
    
  </div>
</section>

Having integrated this code into a website, I'm encountering display issues on smaller screens as shown in the image below:

https://i.sstatic.net/4WDNI.png

The white text, image, and blue text elements are not responsive despite my efforts to implement media queries for responsiveness without success. The cards, however, are responsive. How can I resolve this issue? Any recommendations?

Desired Output

https://i.sstatic.net/Lv720.png

Upon inspection on a 414-pixel wide screen, the desired output displayed above is achieved, which is the desired outcome. However, below 414 pixels in width, the initial undesired output persists. What steps can I take to address this discrepancy?

Answer №1

Consider adjusting the grid-template-columns in your media query to optimize for responsive design on mobile screens.

body {
  width: 100%;
  font-family: sans-serif;
  background: transparent;
  margin: 0;
}

.testimonials {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  grid-gap: 20px;
  padding: 20px;
}

.testimonials .card {
  position: relative;
  max-width: 350px;
  margin: 0 auto;
  background: #333;
  padding: 20px;
  box-sizing: border-box;
  text-align: center;
  box-shadow: 10px 8px 20px rgba(0, 0, 0, .5);
  overflow: hidden;
}

.testimonials .card .layer {
  position: absolute;
  top: calc(100% - 3px);
  width: 100%;
  height: 100%;
  left: 0;
  background: linear-gradient(#034e70, #390375);
  z-index: 1;
  transition: 0.5s;
}

.testimonials .card:hover .layer {
  top: 0;
}

.testimonials .card .content {
  position: relative;
  z-index: 2;
}

.testimonials .card .content p {
  font-size: 18px;
  line-height: 24px;
  color: #FFF;
}

.testimonials .card .content .image {
  width: 100px;
  height: 100px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 10px 20px rgba(0,0,0,.2);
}

.testimonials .card .content .details h2 {
  font-size: 15px;
  color: #fff;
}

.testimonials .card .content .details h2 span {
  color: #03a9f4;
  font-size: 12px;
  transition: 0.5s;
}

.testimonials .card:hover .content .details h2 span {
  color: #fff;
}

@media all and (max-width: 500px) {
  .testimonials {
    grid-template-columns: repeat(auto-fit, minmax(100%, 1fr));
  }
  .testimonials .card .content p {
    width: 100%;
  }
}
<section id="References">
  <div class="section-title">
    <h2>References</h2>
  </div>
  <div class="testimonials">
    <!-- CARD 1 START-->
    <div class="card">
      <div class="layer"></div>
      <div class="content">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vulputate dui a eros pretium commodo...
etc.
...

Answer №2

The reason the element is not resizing properly is due to the fixed width of 350px that you have set. This prevents the element from adjusting when the window size goes below approximately 370px wide. Consider using relative units like % instead for more flexible sizing.

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

CSS Flexbox: Dealing with Overlapping Flex Items on Narrow Screens

Hey there! I've successfully created a custom timeline using flexbox, but I'm encountering an issue on smaller screens. As the window size decreases, the flex items start to overlap. Is there a way you can assist me in adding some space without d ...

"Troubleshooting ng-submit in AngularJS: How to Fix a Function That

I've encountered an issue with my angular-promise where a http method is not being called when a form is submitted using ng-submit. There are no errors, but it seems like the function is never executed. Here's the JavaScript code snippet: myapp. ...

Using deconstruction in exporting as default

As I was diving into a new codebase, I stumbled upon this interesting setup: //index.js export { default } from './Tabs' export { default as Tab } from './Tab' //Tab.js export default class Tab extends Component { render() => &ap ...

Implementing Canvas Offset in a jQuery Mobile Environment

I have positioned a pen ready for use at this location. http://codepen.io/prantikv/pen/LEbRKY Currently, I am utilizing a canvas to track mouse movements or touch input. It performs as expected when jQuery or jQuery mobile is not included. However, upon ...

Mastering the art of debugging a mongoose action in node.js

I am utilizing mongoose for connecting my node.js app with mongoDB. However, I am facing an issue where the database does not get updated when I create or update a model instance. How can I effectively debug and identify what goes wrong in the create or up ...

Hero Sticky Transition with 100vhDivElement

My code is giving me some trouble. I want the div with text to stay at the bottom of the hero section with a transparent background. When that div reaches the top, it should stick with a black background. The issue is that I have set it in the javascript v ...

Exploring the varying behaviors of Javascript window.scrollTo across different browsers

I encountered a problem with the scrollTo function when the body has a dir=rtl attribute. Here's a jsfiddle showcasing my issue. HTML: window.scrollTo(-200, 0); <html> <head> </head> <body dir="rtl"> <div width="10 ...

Mastering ReactJS: Error Encountered - Unexpected import Token

Just getting started with ReactJS and trying out some code from egghead.io. Unfortunately, I keep running into this error: Uncaught SyntaxError: Unexpected token import I've tried loading babel again and making sure to follow the lesson step by step ...

Having difficulty formatting text alignment using CSS

Is there a way to maintain the alignment of text in the output of the 'About' section even when the content changes dynamically? I want the new line to appear just below 'Lorem', but currently, it shifts below the colon(:). Since the le ...

Retrieve a specific quantity of items from an array

I recently started using Postman to develop some test cases. Many of the responses I receive with the get method contain large arrays with numerous objects (I have simplified them here for readability, but each object actually has over 20 properties). Cu ...

Transferring a PHP session variable to JavaScript in a separate file

I successfully imported data from a CSV file into PHP and organized it into a nested array. To ensure the data is easily accessible across different files, I stored the array as a session variable. Now, the challenge lies in accessing this session variable ...

JavaScript believes that the function is not defined, despite its clear existence

This question pertains to an issue regarding the recognition of Bookshelf.js model function as a function. The error message "Function is undefined, Bookshelf.js model function is not being recognized as a function" arises when trying to POST to the login ...

Incorporate React JS seamlessly into your current webpage

As I delve into learning React and considering migrating existing applications to React, my goal is to incorporate a React component within an established page that already contains its own HTML and JavaScript - similar to how KnockoutJS's `applyBindi ...

What is the most optimal jQuery code to use?

Just wondering, which of the following code snippets is more efficient (or if neither, what would be the best way to approach this)? Background - I am working on creating a small image carousel and the code in question pertains to the controls (previous, ...

Issue with spacing in 3x3 photo rollover grid

I am currently working on a 3x3 grid layout featuring image roll overs. Within this layout, the three images on the second row are linked to pages on the website. My goal is to incorporate a 4px padding around all columns and rows, centered at 1024x600 on ...

My image is being cropped on larger screens due to the background-size: cover property

I am currently in the process of designing a website with a layout consisting of a Header, Content, and Footer all set at 100% width. To achieve a background image that fills the screen in the content section, I utilized CSS3 with background-size:cover pr ...

What is the best way to alternate $httpBackend when[method] declarations in unit tests to handle multiple requests?

When conducting my testing, I set up the model data and mock the response: beforeEach(function(){ var re = new RegExp(/^http\:\/\/.+?\/users-online\/(.+)$/); $httpBackend.whenGET(re).respond({id:12345, usersOnline:5000}); }) ...

How can you write a parameterless function in Ramda using a point-free style?

Take a look at this functioning code snippet: var randNum = x => () => Math.floor(x*Math.random()); var random10 = randNum(10) times(random10, 10) // => [6, 3, 7, 0, 9, 1, 7, 2, 6, 0] The function randNum creates a random number generator that wi ...

How to create select options in Angular.js without using the ng-option directive

I receive a JSON object from a service and I am using some of its fields to populate my select option list. However, when I try to print the selected value in my controller, the output response is "undefined". Can someone help me figure out what I'm ...

Learn the secret to displaying and concealing images with jquery!

I'm working on enhancing a question I recently published. After scrolling down the page 200px, the image changes its size. I'm also looking to implement additional functions that I'm struggling to make work. Specifically, I want to achiev ...