image doesnt fit parent element
here is the full code
https://jsfiddle.net/601q9j7c/1/
<section class="cards">
<div class="card">
<div class="img-data">
<div clas="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt=""> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
If you don't set any defined width in either the CSS or the <img> tag, the image will be displayed at full size regardless of its container. This is your issue. So you need to ensure the image is at maximum 100% of it's parent's width.
HTML only
<section class="cards">
<div class="card">
<div class="img-data">
<div clas="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt="" width="100%"> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
It is best practise to do this with CSS rather than directly into HTML, but you have not shown any CSS in your question.
A CSS example is below:
CSS example
.bgimg > img {
max-width: 100%;
width: 100%;
height:auto;
}
<section class="cards">
<div class="card">
<div class="img-data">
<div class="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt=""> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
First of all ! your spelling your class is wrong, that's why image is not fitting.
Make the width of the image to be 100% and its height is auto so that is don't stretch but then your image may be come out of parent container make there overflow:hidden
.cards {
display: flex;
justify-content: center;
}
.card {
width: 60%;
justify-content: center;
display: grid;
grid-template-columns: 50% 50%;
box-shadow: 10px 0px 20px rgba(0,0,0,0.08);
height: 25rem;
}
.img-data {
height: 100%;
z-index: 1;
background-color: salmon;
display: grid;
grid-template-rows: 50% 50%;
}
.bgimg {
overflow: hidden;
}
.bgimg img {
height: auto;
width: 100%;
}
<section class="cards">
<div class="card">
<div class="img-data">
<div class="bgimg"> <img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt=""> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
This should work and is dynamic:
This gives the image an inherited width and height, which means that it replicates the width of the previous object. It is given with the property style="width: inherit; height: inherit;"
.bgimg {
width: 500px; /*Or whatever you want...*/
}
/* this CSS can be directly inserted in a tag with style="width: 500px;"*/
<section class="cards">
<div class="card">
<div class="img-data">
<div class="bgimg"><!--*NOTE: you wrote <div clas="bgimg">(you missed an 's')--><img src="https://cdn.pixabay.com/photo/2015/01/10/16/45/home-office-595476_960_720.jpg" alt="" style="width: inherit; height: inherit;"> </div>
<div class="cardDetails">
<span class="date"><i class="fas fa-calendar-alt"></i> March 30, 2020 </span>
</div>
</div>
<div class="post-data">
<h1 class="title">Vuestic – Free Vue Admin Template</h1>
<p class="description">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium ullam ratione id nihil quis officia voluptas vitae molestiae provident natus exercitationem, praesentium maiores quo quas ducimus. Voluptatibus debitis ea perferendis?</p>
<div class="cta">
Read more →
</div>
</div>
</div>
</section>
Hope this helps!
Related
<section id="home">
<div class="container">
<div class="row align-items-center container-items">
<div class="col-md-6">
<div class="info">
<h1>Lorem ipsum dolor sit amet <u style="color: rgb(165, 177, 231);">consectetur.</u> </h1>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Fuga, pariatur corporis! Quaerat officiis sit rerum exercitationem
facilis quas ex veritatis quod dolores delectus reiciendis autem dignissimos doloremque consequuntur, ad eaque possimus corrupti.
Fugiat, non unde labore, cupiditate nobis quis maxime error, omnis rerum tenetur officiis ea doloremque qui nihil officia?</p>
</div>
<ul>
<li>
<img src="./image/freshfood.png" alt="">
<span><u>Fresh Foods</u> </span>
</li>
<li>
<img src="./image/restaurant.png" alt="">
<span> <u>Master Chefs</u> </span>
</li>
</ul>
</div>
<div class="col-md-6 food-img">
<div>
<img src="image/home.png" alt="">
</div>
</div>
</div>
</div>
</section>
I want the home.png image and h1,p elements in the html codes to be replaced under 575.98 px. When I bring the device to these dimensions, h1,p is on the top and home.png is on the bottom. For this reason;
#home .container-items {
display: flex;
}
#home .info{
max-width: 100%;
height: 15rem;
order: 1 ;
}
#home .food-img{
order: 2;
}
I wrote these codes. Could you please explain this to me; For the order element to work, don't I need to assign the order element in the css to the classes or ids I gave to these divs? Like the food-img and info classes in this code.
As Paulie_D points out, this only works on the direct children (identified by the class flex-item-1 and flex-item-2 in the code below). You can then specify the order for the child elements:
#home .container-items {
display: flex;
}
#home .info {
max-width: 100%;
height: 15rem;
}
#media only screen and (max-width: 575.98px) {
.container-items {
flex-direction: column;
}
.flex-item-1 {
order: 2;
}
.flex-item-2 {
order: 1;
}
}
<section id="home">
<div class="container">
<div class="row align-items-center container-items">
<div class="col-md-6 flex-item-1">
<div class="info">
<h1>
Lorem ipsum dolor sit amet
<u style="color: rgb(165, 177, 231)">consectetur.</u>
</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Fuga,
pariatur corporis! Quaerat officiis sit rerum exercitationem
facilis quas ex veritatis quod dolores delectus reiciendis autem
dignissimos doloremque consequuntur, ad eaque possimus corrupti.
Fugiat, non unde labore, cupiditate nobis quis maxime error,
omnis rerum tenetur officiis ea doloremque qui nihil officia?
</p>
</div>
<ul>
<li>
<img src="https://picsum.photos/60" alt="" />
<span><u>Fresh Foods</u> </span>
</li>
<li>
<img src="https://picsum.photos/60" alt="" />
<span> <u>Master Chefs</u> </span>
</li>
</ul>
</div>
<div class="col-md-6 food-img flex-item-2">
<div>
<img src="https://picsum.photos/300/200" alt="" />
</div>
</div>
</div>
</div>
</section>
In this case, you could just use flex-direction: column-reverse; though:
#home .container-items {
display: flex;
}
#home .info {
max-width: 100%;
height: 15rem;
}
#media only screen and (max-width: 575.98px) {
.container-items {
flex-direction: column-reverse;
}
}
<section id="home">
<div class="container">
<div class="row align-items-center container-items">
<div class="col-md-6 flex-item-1">
<div class="info">
<h1>
Lorem ipsum dolor sit amet
<u style="color: rgb(165, 177, 231)">consectetur.</u>
</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Fuga,
pariatur corporis! Quaerat officiis sit rerum exercitationem
facilis quas ex veritatis quod dolores delectus reiciendis autem
dignissimos doloremque consequuntur, ad eaque possimus corrupti.
Fugiat, non unde labore, cupiditate nobis quis maxime error,
omnis rerum tenetur officiis ea doloremque qui nihil officia?
</p>
</div>
<ul>
<li>
<img src="https://picsum.photos/60" alt="" />
<span><u>Fresh Foods</u> </span>
</li>
<li>
<img src="https://picsum.photos/60" alt="" />
<span> <u>Master Chefs</u> </span>
</li>
</ul>
</div>
<div class="col-md-6 food-img flex-item-2">
<div>
<img src="https://picsum.photos/300/200" alt="" />
</div>
</div>
</div>
</div>
</section>
This question already has answers here:
Floated elements of variable height push siblings down
(3 answers)
Closed 1 year ago.
JSFiddle
<div class="container">
<div class="row">
<div class="col-6">
<div class="card">
<!-- plane icon img -->
<img src="https://i.imgur.com/JhOKdVb.png" alt="plane" class="card__icon">
<div class="card__body">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dolore eaque veniam architecto. Impedit expedita facilis error nostrum harum cumque, iste aspernatur</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<!-- game-pad icon img -->
<img src="https://i.imgur.com/c5O6IOS.png" alt="plane" class="card__icon">
<div class="card__body">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dolore eaque veniam architecto. Impedit expedita facilis error nostrum harum cumque, iste aspernatur</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<!-- plane icon img -->
<img src="https://i.imgur.com/JhOKdVb.png" alt="plane" class="card__icon">
<div class="card__body">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dolore eaque veniam architecto. Impedit expedita facilis error nostrum harum cumque, iste aspernatur</p>
</div>
</div>
</div>
</div>
</div>
.container{
max-width: 1200px;
margin-right: auto;
margin-left: auto;
}
.row:before,.row:after{
content: '';
display: block;
clear: both;
display: table;
}
.col-6{
width: 50%;
float: left;
}
.card{
margin-bottom: 50px;
}
img{
max-width: 100%;
height: auto;
}
I created the columns using the CSS float property. No framework! Everything is working fine but the last column in the row isn't floating left. can anyone explain?
Interesting Fact:
I'm using only two icons called Plane and Gamepad. Interestingly when I changed the Gamepad icon with the 'Plane' icon, it fixes the problem! Still can't figure out why this is happening.
You need to use:
float: right;
That's what you need.
intro
I am creating a simple project in angular and using angular material with flexlayout
problem
the problem is that it doesn't wrap the text correctly on smaller screens, it either clips text or just make it larger than the container.
code
html
<div class="container">
<h2>Normal</h2>
<div class="flex-container" fxLayout="row" fxLayout.xs="column wrap">
<div class="child-1">1. One</div>
<div class="child-2">2. Two</div>
<div class="child-3">3. Three</div>
</div>
<h2>Default</h2>
<div class="flex-container" fxLayout="row" fxLayout.xs="column wrap">
<div class="child-1" fxFlex>
<p>1. One</p>
<p>166.67px</p>
</div>
<div class="child-2" fxFlex>
<p>1. Two</p>
<p>166.67px</p>
</div>
<div class="child-3" fxFlex>
<p>1. Three</p>
<p>166.67px</p>
</div>
</div>
<h2>fxFlex with grow shrink values</h2>
<div class="flex-container" fxLayout="row" fxLayout.xs="column wrap">
<div class="child-1" fxFlex="2 1 auto">
<p> Angular fxFlex flexgrow flexshrink flexbasis</p>
<p>250px</p>
</div>
<div class="child-2" fxFlex>
<p>Angular fxFlex flexgrow flexshrink flexbasis</p>
<p>125px</p>
</div>
<div class="child-3" fxFlex>
<p>125px</p>
</div>
</div>
</div>
<div class="container">
<mat-list>
<div class="flex-container" fxLayout="row wrap" fxLayout.xs="column wrap">
<mat-list-item fxFlex>
<div mat-line> <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Molestias qui assumenda perferendis atque ipsa ipsum enim voluptate voluptas mollitia autem minima deleniti quisquam iste alias, accusantium, eveniet ut, rerum totam.</p></div>
</mat-list-item>
<mat-list-item fxFlex>
<div mat-line>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos molestiae, sequi fugiat tempora dicta numquam ipsam dolorem natus ducimus et expedita cum quaerat porro, cumque necessitatibus odit. Omnis, fugiat officia?</div>
<div mat-line> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio voluptatibus, rem blanditiis nobis, nemo, soluta velit molestiae repudiandae vel non atque accusantium ipsum deleniti saepe natus quam quasi quae fuga.</div>
</mat-list-item>
</div>
</mat-list>
</div>
CSS
.child-1 {
background-color: orange;
}
.child-2 {
background-color: yellow;
}
.child-3 {
background-color: green;
}
.container {
margin: 15px;
height: auto;
width: 95%;
border: 2px solid red;
text-align: center;
}
what i want
I included another container in the next stack blitz that uses the same CSS and flexlayout that works just fine. I want the other container to be the same using mat-list
stackblitz
stackblitz
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
How can I make it so I have one image on the left, with a paragraph on the right. Then another image on the right, with a paragraph on the left.
Like this
I think it's simple but i can't get my head around how to do it
Most people use flex or grid to do this, some people use float too.
This is your answer via flex
img {max-width: 100%}
.blog-card {
width: 700px;
margin: 30px auto 0;
padding: 15px;
border-radius: 5px;
background: #f0f0f0;
display: flex;
}
.thumbnail {
-ms-flex: 0 0 300px;
flex: 0 0 300px;
max-width: 300px;
margin-right: 15px;
}
.blog-card:nth-child(even) .thumbnail {
order: 2;
margin: 0;
}
<div class="blog-card">
<div class="thumbnail">
<a href="#">
<img src="https://images.pexels.com/photos/2693529/pexels-photo-2693529.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Thumbnail">
</a>
</div>
<div class="blog-card-blody">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nostrum necessitatibus dolore doloremque laborum iste ad aspernatur praesentium quas magnam deserunt!</p>
</div>
</div>
<div class="blog-card">
<div class="thumbnail">
<a href="#">
<img src="https://images.pexels.com/photos/2693529/pexels-photo-2693529.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Thumbnail">
</a>
</div>
<div class="blog-card-blody">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nostrum necessitatibus dolore doloremque laborum iste ad aspernatur praesentium quas magnam deserunt!</p>
</div>
</div>
<div class="blog-card">
<div class="thumbnail">
<a href="#">
<img src="https://images.pexels.com/photos/2693529/pexels-photo-2693529.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Thumbnail">
</a>
</div>
<div class="blog-card-blody">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nostrum necessitatibus dolore doloremque laborum iste ad aspernatur praesentium quas magnam deserunt!</p>
</div>
</div>
<div class="blog-card">
<div class="thumbnail">
<a href="#">
<img src="https://images.pexels.com/photos/2693529/pexels-photo-2693529.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Thumbnail">
</a>
</div>
<div class="blog-card-blody">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nostrum necessitatibus dolore doloremque laborum iste ad aspernatur praesentium quas magnam deserunt!</p>
</div>
</div>
I am creating a website with materializecss and having some issue with FAB and responsive image. For FAB issue I already did a post here.
floating button issue in material css
But I need some help for responsive image. Its always coming in oval shape. Ii I use respoonsive image in collection it is working fine. Not sure how to get a prefect shape,
html :
<div class="user-feed-main-box box">
<ul class="collection">
<li class="collection-item avatar">
<img src="" alt="" class="circle">
<span class="title"><p>user Shared a post Art </p></span>
<p> <label for="icon_prefix"><i class="material-icons left">timer</i>a min ago.</label> <br>
</p>
</li>
</ul>
<div class="row">
<div class="col s2">
<div class="container">
<img src="" alt="" class="responsive-img circle">
</div>
</div>
<div class="col">
<p>User Shared a post Art </p>
<label for="icon_prefix"><i class="material-icons left">timer</i>a min ago.</label>
</div>
</div>
<div class="container">
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Magnam eos in ea dolor eligendi repudiandae
praesentium
modi. Consequuntur, accusantium culpa! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni
sapiente ipsa amet eos officiis aperiam atque. Nemo corporis quibusdam ipsa placeat voluptate fugiat fuga
veniam possimus maxime doloremque veritatis ullam quam odit eligendi, id, sequi quas consequuntur
perferendis accusamus, harum culpa quis animi. Minima, est minus? Optio dolor mollitia perspiciatis.</p>
<div class="carousel carousel-slider">
<a class="carousel-item" href="#one!"><img
src=""></a>
<a class="carousel-item" href="#two!"><img
src=""></a>
<a class="carousel-item" href="#three!"><img
src=""></a>
<a class="carousel-item" href="#four!"><img
src=""></a>
<a class="carousel-item" href="#five!"><img
src=""></a>
</div>
</div>
</d
There was a reported issue similar to this in the Materialize GitHub repo. It appears the solution for that was to not use materialize and instead implement the below.
.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%;
}
And then change the img html to
<div class="ratio img-responsive img-circle" style="background-image:url('somepicture.jpg');"></div>