Restrict the height of the image, title, and story within the cardview

I came across the template at . After making some modifications, I ended up with this:

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

Unfortunately, the images are sourced externally and I have no control over their sizes. My goal is to make all images take up 25% of the row height while maintaining their aspect ratio. This means adjusting the width of the image without changing the column width. Additionally, I want titles to occupy a maximum of 50% of the space (with text being trimmed if too long) and the rest filled with content text.

As a beginner in bootstrap, I attempted to adjust the image height by adding the following code:

.card-img-top {
  height: 25%; 
}

However, it doesn't seem to have any effect. Can anyone provide guidance on how to achieve this? Ideally, I would prefer not to delve into sass for now since I lack experience in that area.

Edit: You can find the complete code here: https://github.com/JefPatat/ProjectX

Answer №1

Creating a simple HTML structure:

<div class="row">
    <div class="image">
        <img src="">
    </div>
    <div class="title">
       this is the title short
    </div>
    <div class="txt">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi u
    </div>
</div>

Applying CSS styles to enhance the look and feel:

.row {
   height:600px;
   width:200px;
   border:1px solid black;
   float:left;
   margin-right:10px;
   overflow:hidden;
}
.image {
   height:25%;
   position:relative;  
}
.image img {
   position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;    
    margin:auto;
    max-width:100%;
    max-height:100%;
}
.title {
  font-size:16px;
  color:blue;
  max-height:25%;
  overflow:hidden;
}
.txt {
does not require anything special but styling. Will take the remaining height available.
}

An example of implementing the above code:

* {box-sizing:border-box;}
.row {
   height:600px;
   width:200px;
   border:1px solid black;
   float:left;
   margin-right:10px;
   overflow:hidden;
}
.image {
   height:25%;
   position:relative;   
}
.image img {
   position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;    
    margin:auto;
    max-width:100%;
    max-height:100%;
}
.title {
  font-size:16px;
  color:blue;
  max-height:25%;
  overflow:hidden;
}
.txt {

}
<div class="row">
    <div class="image">
        <img src="http://html.crunchpress.com/tulip/images/blog/blog-img-3.jpg" alt="">
    </div>
    <div class="title">
      this is the title short
    </div>
    <div class="txt">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi u
    </div>
</div>
<div class="row">
    <div class="image">
        <img src="http://www.imgworlds.com/wp-content/themes/IMG/img/phase3/welcome/hulk.png" alt="">
    </div>
    <div class="title">
      this is the title long this is the title long this is the title long this is the title longle lon gthis is the title long this is the title long this is the title long this is the title longle lon gthis is the title long this is the title long this is the title long this is the title longg
    </div>
    <div class="txt">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magnre magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laboruma aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
    </div>
</div>

UPDATED AFTER INITIAL COMMENT BELOW

To fit into your bootstrap project, simply place this code snippet inside the "portfolio-item" container:

<div class="image">
            <img src="">
        </div>
        <div class="title">
           this is the title short
        </div>
        <div class="txt">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi u
        </div>

Add these specific CSS properties at the end of your stylesheet:

.row {
   height:800px;
}
.portfolio-item {
  height:100%;
}
.image {
   height:25%;
   position:relative;   
}
.image img {
   position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;    
    margin:auto;
    max-width:100%;
    max-height:100%;
}
.title {
  font-size:16px;
  color:blue;
  max-height:25%;
  overflow:hidden;
}

Note that classes like ´row´ and ´portfolio-item´ are from bootstrap, so modify them according to your project for better customization.

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

Utilize React/webpack to import and extract the text content of a CSS file

I am working on a task to import a CSS file, extract its contents, and then generate an array of class names. Unfortunately, the code snippet below only returns an empty object in the log. import Stylesheet from './styles.css' console.log(Style ...

I'm struggling to understand how to upload pictures from my files onto my website

Adding images to my website has been more challenging than I expected. For example, if I have a folder named "images" on my computer's desktop with an image called "eye," will the following code display the image correctly? <img src="Desktop ...

:last-child is effective, but :first-child is inefficient

I'm having trouble using CSS to hide the first .sku element within an aside that contains two of these elements. Strangely, the :last-child selector works just fine. Can anyone explain why this might be happening? Here's a link to the JSFiddle fo ...

Can an advertisement's appearance be altered to include custom content using only CSS?

Dealing with SAP for our ticket system has been quite a challenge due to the design that is causing some frustration. In an attempt to make it more tolerable, I used CSS to make some adjustments. However, my problem now lies in the fact that they keep maki ...

Instructions for converting a MySQL select statement within a foreach() loop into an HTML form

I'm in the process of developing a course registration system for a small project. Currently, I have a table named 20182019carryovertbl from which I successfully select students who are carrying over their courses. Now, I need to transform this select ...

Is there a way to keep the background image stationary as I scroll?

As someone who is new to html and CSS, I recently tried to enhance my previous project by incorporating a background image that spans the entire screen size and remains fixed while scrolling up or down. Here is the code snippet: ''' body { ...

Changed static divs into flexible divs

I am currently working on designing a webpage layout where the header occupies 100% of the width and 20% of the height in conjunction with a left navbar (20% width) and a main body adjacent to it (80% width). Additionally, I want the page to be responsive ...

Choose a specific row from a table using an action button in PHP

I am currently working on a table that is being auto-populated from my database. Each row in the table has three action buttons - edit, delete, and view. I am using sessions to send the key value to the next page so that I can load the data of the select ...

Ensure that the anchor element's height fills the entire div when using the display:block property

My HTML code is very simple: <div class='mydiv'> <a href='#'>Link</a> <div> As for the CSS: div.mydiv { height: 200px; width: 200px; background-color:red; } div.mydiv a { display:block; color:yellow; b ...

Stop iframe from altering the parent's location

Imagine has an embedded <iframe src="http://y.com/qux"> Occasionally y.com/qux will break free from its frame: the main window will suddenly navigate away from x.com/baz to y.com/qux. The method used by y.com to achieve this remains a mystery to me ...

Modify only unprocessed text within the HTML content

Consider the following string: html_string = '<span><span class=\"ip\"></span> Do not stare <span class=\"img\"></span> at the monitor continuously </span>\r\n' I am looking to ...

When the previous textbox is filled, the cursor will automatically move to the button

Utilizing an RFID reader where students tap their ID to display basic info, a hidden button on the form opens a modal with various purposes for selection. The challenge is shifting focus of cursor to the button and automatically clicking it when the last ...

Ever since implementing a new section class, the CSS first-of-type selector has ceased to function

After referencing a previous response, I utilized first-of-type to specifically target the initial menuSection with this code snippet... .menuSection:first-of-type { background: red; } <div id="container"> <section class="menuSection"> ...

Tips for including a line within a circular canvas

My progress bar crafted with css, javascript and html looks great (left image). However, I'm facing a challenge in adding white color dividers to enhance the appearance of the progress bar as shown in the image on the right. Despite my various attemp ...

The dimensions of the bottom border on left floating divs are inconsistent

One of my designers frequently uses a particular technique in various designs, and I'm struggling to determine the most effective way to style it with CSS so that it fluidly adapts (as it will be incorporated into a CMS). Essentially, when implementi ...

Can someone help clear up this confusion with CSS?

Why is image 6.png selected, when all the images are direct descendants of the div shape? Thank you for your assistance, it's greatly appreciated. As far as I know, it should select all the divs because they are all direct descendants of the div #shap ...

Ways to display calendar exclusively when the icon is clicked?

In my application, I am using bootstrap-datepicker-1.9.0. A recent request from the customer is to only display the calendar when the user clicks on the calendar icon, rather than for the entire input group. Below is an example of my current code: $(doc ...

What is the best way to add a substantial amount of HTML content to a div element in a dynamic manner

I am a beginner in the world of web development and still trying to grasp all the different languages and markups. Currently, I am working on a website with a blog that retrieves JSON data from the Tumblr v2 API. My goal is to extract specific information ...

Is there a way to initiate a background fade-in once an animation has finished?

I have customized the background of the parent element called "banner". Is there a way to smoothly fade in this background after the child elements "block" and "block2" finish animating and reveal the underlying text? <section id="banner"> &l ...

Disabling animations in Bootstrap 3 Carousel is caused by including Stripe javascript

After successfully implementing Stripe for payments in my system, I encountered an issue where the carousel animations stopped working. Instead of sliding smoothly between pictures, it now immediately changes them. The javascript file related to my use of ...