PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 29, 2022

[FIXED] How to display an image in a block?

 July 29, 2022     css, html, image, position     No comments   

Issue

I want to display an image in the background in a block. My problem is that this image is distorted (stretched across the width).

I don't need to display the whole image, I want it to take the full width of the block, but it must be centered in height even if the height is hidden.

For example, I want it to look like this :

https://cdn.pixabay.com/photo/2016/11/21/03/56/landscape-1844226_960_720.png

element.style {
    background: url(https://cdn.pixabay.com/photo/2016/11/21/03/56/landscape-1844226_960_720.png);
    background-position: center;
    background-size: cover;
}

I don't know how to apply the same style on an img element. Here is my code :

.node--view-mode-similar .layout {
    position: relative;
    margin-bottom: 0;
    padding: 1rem 1rem 0.2rem 1rem;
    border: 2px solid #ced8dd;
}

enter image description here

.node--view-mode-similar .block-field-blocknodearticlefield-article-image img {
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
    height: 100%;
}

enter image description here


Solution

try using this:

object-fit: cover;


Answered By - Ali Navidi
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing