Boxes cant resize after the most biggest one - html

I want to set all of these boxes width and height after the most biggest one.. display: flex destroy whole card.
Can someone tell me what change, what add or what to do, to let that code still working?
CSS
.profile {
font-family: 'Nunito', sans-serif;
text-align: center;
max-width: 200px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
padding: 20px;
margin: 20px 10px 20px 10px;
float: left;
transition: all .3s ease
}
.profile:hover {
transform: scale(1.2);
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
}
.profile a {
color: #000000;
text-decoration: none;
}
.profile_image {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin: 0 auto 20px auto;
display: block;
}
.profile_name {
font-size: 1.2em;
font-weight: bold;
}
.profile_info {
margin-bottom: 20px;
}
.profile_verifed {
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9em;
color:rgb(5, 148, 0);
}
HTML
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Name</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Administrator Adminovsky</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>

You need to add a little bit of JS, in this snippet I used two forEach cycles for the profiles, the first is used to detect the maximum width and height of each profile, and the second is applying it to all profile elements. So all the profile elements have the maximum width and height.
let profiles = document.querySelectorAll(".profile"),
profileWidth = 0,
profileHeight = 0;
profiles.forEach(function(profile){
if(profile.offsetHeight > profileHeight){
profileHeight = profile.offsetHeight;
}
if(profile.offsetWidth > profileWidth){
profileWidth = profile.offsetWidth;
}
});
profiles.forEach(function(profile){
profile.style.height = profileHeight + "px";
profile.style.width = profileWidth + "px";
});
.profile {
font-family: 'Nunito', sans-serif;
text-align: center;
max-width: 200px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
padding: 20px;
margin: 20px 10px 20px 10px;
float: left;
transition: all .3s ease
}
.profile:hover {
transform: scale(1.2);
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
}
.profile a {
color: #000000;
text-decoration: none;
}
.profile_image {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin: 0 auto 20px auto;
display: block;
}
.profile_name {
font-size: 1.2em;
font-weight: bold;
}
.profile_info {
margin-bottom: 20px;
}
.profile_verifed {
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9em;
color:rgb(5, 148, 0);
}
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Name</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Administrator Adminovsky</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>

I hope I understand correctly what your actual problem is. But I'll try anyway...
How about including all .profile elements in a container div and replace max-width with just width? Also .profile:hover will be best to scale to 1.05.
.profiles-container {
widht: 100%;
height: 100%;
display: flex;
flex-wrap: wrap;
}
.profile {
font-family: 'Nunito', sans-serif;
text-align: center;
width: 200px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
padding: 20px;
margin: 20px 10px 20px 10px;
float: left;
transition: all .3s ease
}
.profile:hover {
cursor: pointer;
transform: scale(1.05);
-webkit-transform: scale(1.05);
-ms-transform: scale(1.05);
}
.profile a {
color: #000000;
text-decoration: none;
}
.profile_image {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin: 0 auto 20px auto;
display: block;
}
.profile_name {
font-size: 1.2em;
font-weight: bold;
}
.profile_info {
margin-bottom: 20px;
}
.profile_verifed {
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9em;
color:rgb(5, 148, 0);
}
<div class="profiles-container">
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Name</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Administrator Adminovsky</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>
</div>
I think you are mistaken to consider finding the bigger one. You just have to decide on a size that fits what you want to do and going with it. You can then adjust the child elements of profile.

you can use flex attribute but is not related to your question
in my opinion you must use JavaScript or other scripts to do that
in JavaScript:
1-get All boxes
2-find the biggest
3-set Other boxes with and height
but its will be nice by using :
css:
body {
display: flex;
}
.profile {
flex: 1;
font-family: 'Nunito', sans-serif;
text-align: center;
max-width: 200px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
padding: 20px;
margin: 20px 10px 20px 10px;
float: left;
transition: all .3s ease
}
.profile:hover {
transform: scale(1.2);
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
}
.profile a {
color: #000000;
text-decoration: none;
}
.profile_image {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin: 0 auto 20px auto;
display: block;
}
.profile_name {
font-size: 1.2em;
font-weight: bold;
}
.profile_info {
margin-bottom: 20px;
}
.profile_verifed {
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9em;
color:rgb(5, 148, 0);
}
html:
<div className="profile">
<img src="default.jpg" alt="Profile photo" className="profile_image">
<div className="profile_name">Name</div>
<div className="profile_info">Men (12 years)</div>
<div className="profile_verifed"><i className="material-icons">check</i>Verifed</div>
</div>
<div className="profile">
<img src="default.jpg" alt="Profile photo" className="profile_image">
<div className="profile_name">Administrator Adminovsky</div>
<div className="profile_info">Men (12 years)</div>
<div className="profile_verifed"><i className="material-icons">check</i>Verifed</div>
</div>
or use JavaScript :
var boxes = $(".profile");
var maxWidth = 0;
boxes.each((index,data)=>{
if(maxWidth<$(data).width())
maxWidth = $(data).width()
});
boxes.each((index,data)=>{
console.log(maxWidth);
$(data).width(maxWidth);
});
.profile {
font-family: 'Nunito', sans-serif;
text-align: center;
max-width: 200px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
padding: 20px;
margin: 20px 10px 20px 10px;
float: left;
transition: all .3s ease
}
.profile:hover {
transform: scale(1.2);
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
}
.profile a {
color: #000000;
text-decoration: none;
}
.profile_image {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin: 0 auto 20px auto;
display: block;
}
.profile_name {
font-size: 1.2em;
font-weight: bold;
}
.profile_info {
margin-bottom: 20px;
}
.profile_verifed {
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9em;
color:rgb(5, 148, 0);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Name</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>
<div class="profile">
<img src="default.jpg" alt="Profile photo" class="profile_image">
<div class="profile_name">Administrator Adminovsky</div>
<div class="profile_info">Men (12 years)</div>
<div class="profile_verifed"><i class="material-icons">check</i>Verifed</div>
</div>

Related

Row of <div> elements will not align to the center [duplicate]

This question already has answers here:
How do I center floated elements?
(12 answers)
Closed last year.
I've read a hundred posts about how to center a row of divs, but I can't seem to get this to work. I want these elements to align to the center of their container, while maintaining a gap between each of them. No matter what I seem to do, they hug the left.
Do I need to change the CSS on the container element, or the individual div items themselves?
Help!
.news_section {
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
.news_container {
border: 1px red solid;
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.news_item { position: relative; float: left; font-family: graphik-light; font-size: 1.1em; margin: 25px 25px 25px 0px; width: 220px; height: 400px; cursor: pointer; transition: all 0.2s ease-out;
-webkit-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
-moz-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
box-shadow: 0px 3px 10px 1px rgba(204, 204, 204, 1);
}
.news_item:hover { background: #efefef; transform: scale(1.04); transition: all 0.2s ease-in; cursor: pointer; }
.news_img {
width: 100%;
height: 100%;
object-fit: contain;
}
.news_header { font-family: 'Oswald', sans-serif; font-size: 22px; line-height: 1.4em; text-align: left; margin-top: 18px; margin-left: 14px; margin-right: 14px; }
.news_outlet { font-size: 13px; text-align: left; margin-top: 7px; margin-left: 14px; color: #c1c1c1; font-family: graphik-regular; text-transform: uppercase; }
.news_subtext { font-size: 14px; text-align: left; margin-top: 20px; margin-left: 14px; margin-right: 14px; color: #4d5051; font-family: graphik-regular; }
.news_more { position: absolute; bottom: 10px; font-size: 16px; margin-left: 14px; color: #000; font-family: 'Oswald', sans-serif; }
<section class="news_section">
<div class="news_container">
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
</div>
</section>
On the news_item ... Change that
float: left;
to
display: inline-block;
.news_section {
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
.news_container {
border: 1px red solid;
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.news_item { position: relative; display: inline-block; font-family: graphik-light; font-size: 1.1em; margin: 25px 25px 25px 0px; width: 220px; height: 400px; cursor: pointer; transition: all 0.2s ease-out;
-webkit-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
-moz-box-shadow: 0px 3px 10px 1px rgba(204, 204, 204 0, 1);
box-shadow: 0px 3px 10px 1px rgba(204, 204, 204, 1);
}
.news_item:hover { background: #efefef; transform: scale(1.04); transition: all 0.2s ease-in; cursor: pointer; }
.news_img {
width: 100%;
height: 100%;
object-fit: contain;
}
.news_header { font-family: 'Oswald', sans-serif; font-size: 22px; line-height: 1.4em; text-align: left; margin-top: 18px; margin-left: 14px; margin-right: 14px; }
.news_outlet { font-size: 13px; text-align: left; margin-top: 7px; margin-left: 14px; color: #c1c1c1; font-family: graphik-regular; text-transform: uppercase; }
.news_subtext { font-size: 14px; text-align: left; margin-top: 20px; margin-left: 14px; margin-right: 14px; color: #4d5051; font-family: graphik-regular; }
.news_more { position: absolute; bottom: 10px; font-size: 16px; margin-left: 14px; color: #000; font-family: 'Oswald', sans-serif; }
<section class="news_section">
<div class="news_container">
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
<div class="news_item">
<div><img src="https://thruline.com/prototype/images/news/news.jpeg" class="news_img"/></div>
<div class="news_header">News title Here</div>
<div class="news_outlet">MAGAZINE OUTLET</div>
<div class="news_subtext">Description of articles goes here....</div>
<div class="news_more">Click Here to Read More...</div>
</div>
</div>
</section>
Better still, take a look at flex-box: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
If you want to align all items to the center, you need to use Flexbox. Basically, you gotta add this code to align everything of your container in center:
CSS:
.container: {
display: flex; /* flexbox */
justify-content: center; /* horizontal center */
align-items: center; /* vertical center */
}
This is an excelent article about Flexbox, made by W3School:
W3School - CSS Flexbox

CSS scale and transform shows lines in my Chrome browser

I want to create for my <a> section nice looking smooth zoom-in effect when user points his mouse on it.
It works,but for some reason I have lines between my <div> sections inside the <a> section.
Here is my example:
http://jsfiddle.net/p1g0Lzu3/23/
So, on hover, there are two gray lines, which I don't want to be there.
I tried various things, but still I can't find the way to fix that.
The easiest fix is to give the wrapper the same background color as the divs inside
.wrapper {
background-color: #243964;
}
There is something with not setting a height to .main class that puts those lines in there. With static position by default, it will try to fill any unfilled space. It's kind of a weird concept but I was able to fix it by adding:
/* additions */
.main {
height: 80%;
}
Also, I assume you have the scroll there for a reason so I didn't change that around at all. I added the media queries simply for snippet viewing sake. I suggest clicking full-page
.container-box {
transform: translateX(70%);
display: flex;
width: 40%;
flex-direction: row;
justify-content: space-between;
padding-top: 40px;
padding-bottom: 40px;
}
.shadow-bottom {
-webkit-box-shadow: 0 12px 0px 6px #6076a7;
-moz-box-shadow: 0 12px 0px -6px #6076a7;
box-shadow: 0 12px 0px -6px #6076a7;
}
.wrapper {
backface-visibility: hidden;
-webkit-transform: translateZ(0);
display: flex;
flex-flow: row wrap;
flex: 100px;
margin: 20px;
text-align: center;
}
.wrapper:hover {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
-o-transform: scale(1.2);
transform: scale(1.2);
}
.wrapper > * {
flex: 1 100%;
}
.header {
background: #243964;
text-align: left;
color: #dbd6d6;
padding: 20px;
font-size: 12px;
}
.hr1 {
border: 0;
border-top: 1px solid #4990e2;
}
.footer {
background: #243964;
text-align: left;
color: white;
padding: 20px;
font-size: 14px;
}
.main {
text-align: left;
background: #243964;
color: #fefefe;
padding: 20px;
padding-top: 35px;
padding-bottom: 20px;
height: 200px;
}
.box-title {
font-weight: 600;
font-size: 20px;
padding-bottom: 10px;
color: white;
}
.box-content {
line-height: 1.9;
font-size: 12px;
color: #dbd6d6;
}
.box-paragraph {
word-spacing: 4px;
}
.main .footer {
height: fit-content;
overflow: hidden;
}
/* additions */
.main {
height: 80%;
}
#media only screen and (max-width: 1400px) {
.container-box {
width: 100%;
height: 100%;
}
.header {
height: 40px;
}
}
<div class="container-box">
<a href="#" class="wrapper shadow-bottom">
<header class="header">Header 0</header>
<article class="main">
<div class="box-title">Title 0</div>
<p class="box-content">Some long text here hehehe jsdshsjhdshdsjhd</p>
</article>
<footer class="footer">
<hr class="hr1">
<div class="learn-more">
Learn more
</div>
</footer>
</a>
<a href="#" class="wrapper shadow-bottom">
<header class="header">Header 1</header>
<article class="main">
<div class="box-title">Title 1</div>
<p class="box-content">sdsdsdsd</p>
</article>
<footer class="footer">
<hr class="hr1">
<div class="learn-more">
Learn more
</div>
</footer>
</a>
</div>
OR check out my fiddle
so, I got another approach for your question, in which you have to change your "height:200px" to "min-height:200px" in 'main' class.
.container-box {
transform: translateX(70%);
display: flex;
width: 40%;
flex-direction: row;
justify-content: space-between;
padding-top: 40px;
padding-bottom: 40px;
}
.shadow-bottom {
-webkit-box-shadow: 0 12px 0px 6px #6076a7;
-moz-box-shadow: 0 12px 0px -6px #6076a7;
box-shadow: 0 12px 0px -6px #6076a7;
}
.wrapper {
backface-visibility: hidden;
-webkit-transform: translateZ(0);
display: flex;
flex-flow: row wrap;
flex: 100px;
margin: 20px;
text-align: center;
}
.wrapper:hover {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
-o-transform: scale(1.2);
transform: scale(1.2);
}
.wrapper > * {
flex: 1 100%;
}
.header {
background: #243964;
text-align: left;
color: #dbd6d6;
padding: 20px;
font-size: 12px;
}
.hr1 {
border: 0;
border-top: 1px solid #4990e2;
}
.footer {
background: #243964;
text-align: left;
color: white;
padding: 20px;
font-size: 14px;
}
.main {
text-align: left;
background: #243964;
color: #fefefe;
padding: 20px;
padding-top: 35px;
padding-bottom: 20px;
min-height: 200px;
}
.box-title {
font-weight: 600;
font-size: 20px;
padding-bottom: 10px;
color: white;
}
.box-content {
line-height: 1.9;
font-size: 12px;
color: #dbd6d6;
}
.box-paragraph {
word-spacing: 4px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="custom.css">
</head>
<body>
<div class="container-box">
<a href="#" class="wrapper shadow-bottom">
<header class="header">Header 0</header>
<article class="main">
<div class="box-title">Title 0</div>
<p class="box-content">
Some long text here hehehe jsdshsjhdshdsjhd
</p>
</article>
<footer class="footer">
<hr class="hr1">
<div class="learn-more">
Learn more
</div>
</footer>
</a>
<a href="#" class="wrapper shadow-bottom">
<header class="header">Header 1</header>
<article class="main">
<div class="box-title">Title 1</div>
<p class="box-content">
sdsdsdsd
</p>
</article>
<footer class="footer">
<hr class="hr1">
<div class="learn-more">
Learn more
</div>
</footer>
</a>
</div>
</body>
</html>

Image Dimensions Issue in HTML, CSS

I have the following code:
#import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans');
.container1{
display: flex;
justify-content: center;
padding: 20px;
overflow: hidden;
}
.square:hover {
-webkit-transform: translate(20px, -10px);
-ms-transform: translate(10px, -10px);
transform: translate(10px, -10px);
-webkit-box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
}
.square{
height: 430px;
background: white;
border-radius: 4px;
box-shadow: 0px 5px 20px #D9DBDF;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.mask{
clip: rect(0px, 460px, 220px, 0px);
position: absolute;
border: 5px solid #555;
}
.h11{
margin: auto;
text-align: left;
margin-top: 240px;
padding-left: 30px;
padding-right: 30px;
font-family: 'Merriweather', serif;
font-size: 24px;
}
p9 {
text-align: justify;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
color: #C8C8C8;
line-height: 18px;
padding-left: 30px;
padding-right: 30px;
display: block;
}
.button56 {
background-color: #3EDD84;
color: white;
width: 100px;
padding: 10px 18px;
border-radius: 3px;
text-align: center;
text-decoration: none;
display: block;
margin-top: 15px;
margin-left: 30px;
margin-right: 70px;
font-size: 12px;
cursor: pointer;
font-family: 'merriweather';
}
<section>
<div class="section-title">
<h2>Featured Blogs Of The Day</h2>
</div>
<div class="parent-div">
<div class="child-div">
<div class="blogmaster">
<div class="column1">
<div class="row1">
<div class="container1">
<div class="square">
<img src="https://images.unsplash.com/photo-1504610926078-a1611febcad3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e1c8fe0c9197d66232511525bfd1cc82&auto=format&fit=crop&w=1100&q=80" class="mask" style="border: 5px solid #555">
<div class="h11">β€œChances Of My Uni/College Admission?”</div>
<p9>It is that time of the year again (yay!πŸ™‚) where we β€” high school students β€” are supposed to fill out the applications and land in our dream Universities/Colleges!</p9>
<div>Read More</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- new start of blog -->
<div class="parent-div">
<div class="child-div">
<div class="blogmaster">
<div class="column1">
<div class="row1">
<div class="container1">
<div class="square">
<img src="https://www.isfasports.gr/image/cache/data/products/pr_3-1100x1100.jpg" class="mask" style="border: 5px solid #555">
<div class="h11">My Career Advice To You: Take These Steps...</div>
<p9>Humans tend to make mistakes β€” and its completely normal as it results in the growth and development of an individual β€” either psychologically or physically.</p9>
<div>Read More</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section><!-- End blogs Section -->
How would I modify the .mask class which controls the image, so that whatever device you use to view the two cards, the width of the image always fits the card?
For example, I have the above code embedded in a website, and so when I use a smaller device to view the website, the width of the image changes.
This is my output on a smaller device:
I could not show the second card but it is the exact same as this card above. See how the image's width is not fitted on the card?
However, on a large screen, this is my output:
Now, the image is fitted perfectly, and this is what I want on smaller devices too.
Is there a way to modify the .mask class so that whatever device the user is on, the image is always fitted on the box like shown in the output right above? Any suggestions?
How about the following. Adding width: 100%; height: auto to images should make them scale better.
#import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans');
.container1 {
display: flex;
justify-content: center;
padding: 20px;
overflow: hidden;
}
.square:hover {
-webkit-transform: translate(20px, -10px);
-ms-transform: translate(10px, -10px);
transform: translate(10px, -10px);
-webkit-box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
}
.square {
width: 100%;
/**/
min-height: 430px;
/**/
background: white;
border-radius: 4px;
box-shadow: 0px 5px 20px #D9DBDF;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.mask {
clip: rect(0px, 460px, 220px, 0px);
border: 5px solid #555;
width: calc(100% - (2 * 5px));
/**/
height: auto;
/**/
}
.h11 {
margin: auto;
text-align: left;
margin-top: 24px;
padding-left: 30px;
padding-right: 30px;
font-family: 'Merriweather', serif;
font-size: 24px;
}
p9 {
text-align: justify;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
color: #C8C8C8;
line-height: 18px;
padding-left: 30px;
padding-right: 30px;
display: block;
}
.button56 {
background-color: #3EDD84;
color: white;
width: 100px;
padding: 10px 18px;
border-radius: 3px;
text-align: center;
text-decoration: none;
display: block;
margin-top: 15px;
margin-left: 30px;
margin-right: 70px;
margin-bottom: 15px;
/**/
//*or margin: 15px 70px 15px 30px;*/
font-size: 12px;
cursor: pointer;
font-family: 'merriweather';
}
<section>
<div class="section-title">
<h2>Featured Blogs Of The Day</h2>
</div>
<div class="parent-div">
<div class="child-div">
<div class="blogmaster">
<div class="column1">
<div class="row1">
<div class="container1">
<div class="square">
<img src="https://images.unsplash.com/photo-1504610926078-a1611febcad3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e1c8fe0c9197d66232511525bfd1cc82&auto=format&fit=crop&w=1100&q=80" class="mask" style="border: 5px solid #555">
<div class="h11">β€œChances Of My Uni/College Admission?”</div>
<p9>It is that time of the year again (yay!πŸ™‚) where we β€” high school students β€” are supposed to fill out the applications and land in our dream Universities/Colleges!</p9>
<div>Read More</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- new start of blog -->
<div class="parent-div">
<div class="child-div">
<div class="blogmaster">
<div class="column1">
<div class="row1">
<div class="container1">
<div class="square">
<img src="https://www.isfasports.gr/image/cache/data/products/pr_3-1100x1100.jpg" class="mask" style="border: 5px solid #555">
<div class="h11">My Career Advice To You: Take These Steps...</div>
<p9>Humans tend to make mistakes β€” and its completely normal as it results in the growth and development of an individual β€” either psychologically or physically.</p9>
<div>Read More</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- End blogs Section -->

Why can't i align the div that contains text next to the div that contains the image

i'm currently working on a webpage for my design class and i have a problem. This is the browser view:
I am kinda new with html and css but i have tried display in-line block, flex... Nothing worked, and i dont know what else i could do
So the problem is that the text "aaaaa" must be next to image. Here is my html code:
.caixa {
word-wrap: break-word;
width: 70%;
box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
margin: 25px;
margin-left: 0px;
border-radius: 10px;
}
.caixa-img {
display: inline-block;
margin: 15px;
width: 15%;
position: relative;
}
.caixa-img img {
margin-right: 120px;
border-radius: 10px;
width: 100%;
height: 100%;
}
.info {
width: 100%;
padding: 10px 20px;
}
.tipo {}
.descripcio {
display: block;
background-color: chartreuse;
}
.tipo a {
color: #222222;
margin: 5px 0px;
font-weight: 700;
letter-spacing: 0.5px;
padding-right: 8px;
}
.tipo span {
color: rgba(26, 26, 26, 0.5);
}
.preu {
color: #333333;
font-weight: 600;
font-size: 1.1rem;
font-family: poppins;
letter-spacing: 0.5px;
}
.overlay {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
background-color: rgba(226, 197, 88, 0.6);
display: flex;
justify-content: center;
align-items: center;
}
.comprar {
width: 160px;
height: 40px;
display: flex;
justify-content: center;
align-items: center;
background-color: #FFFFFF;
color: #252525;
font-weight: 700;
letter-spacing: 1px;
font-family: calibri;
border-radius: 20px;
box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
}
.comprar:hover {
color: #FFFFFF;
background-color: rgb(248, 171, 55);
transition: all ease 0.3s;
}
.overlay {
visibility: hidden;
}
.caixa-img:hover .overlay {
visibility: visible;
animation: fade 0.5s;
}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="col-12 productes">
<div class="producte1">
<div class="caixa">
<div class="caixa-img">
<img alt="" src="imgExplora/imgCarrousel/herbicida.jpg">
<div class="overlay">
Comprar
</div>
<div class="tipo">
<a href="#">
<h3>HERBICIDA</h3>
</a>
<!--
<div class="rating">
<span>β˜†</span><span>β˜†</span><span>β˜†</span><span>β˜†</span><span>β˜†</span>
</div>-->
</div>
55€
</div>
<div class="info">
<span class="descripcio">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
</div>
</div>
</div>
</div>
Below an example using flexbox (see .caixa).
.caixa {
width: 70%;
box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
margin: 25px 25px 25px 0;
/* margin-left: 0px; */
border-radius: 10px;
display: flex; /* Added */
}
.caixa-img {
margin: 15px;
width: 30%;
}
.caixa-img img {
border-radius: 10px;
width: 125px; /* For demo */
height: 125px; /* For demo */
}
.info {
width: 100%;
padding: 10px 20px;
}
.tipo {}
.descripcio {
display: block;
background-color: chartreuse;
word-break: break-all; /* Essential to break large words */
}
.tipo a {
color: #222222;
margin: 5px 0px;
font-weight: 700;
letter-spacing: 0.5px;
padding-right: 8px;
}
.tipo span {
color: rgba(26, 26, 26, 0.5);
}
.preu {
color: #333333;
font-weight: 600;
font-size: 1.1rem;
font-family: poppins;
letter-spacing: 0.5px;
}
.overlay {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
background-color: rgba(226, 197, 88, 0.6);
display: flex;
justify-content: center;
align-items: center;
}
.comprar {
width: 160px;
height: 40px;
display: flex;
justify-content: center;
align-items: center;
background-color: #FFFFFF;
color: #252525;
font-weight: 700;
letter-spacing: 1px;
font-family: calibri;
border-radius: 20px;
box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
}
.comprar:hover {
color: #FFFFFF;
background-color: rgb(248, 171, 55);
transition: all ease 0.3s;
}
.overlay {
visibility: hidden;
}
.caixa-img:hover .overlay {
visibility: visible;
animation: fade 0.5s;
}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="col-12 productes">
<div class="producte1">
<div class="caixa">
<div class="caixa-img">
<img alt="" src="imgExplora/imgCarrousel/herbicida.jpg">
<div class="overlay">
Comprar
</div>
<div class="tipo">
<a href="#">
<h3>HERBICIDA</h3>
</a>
</div>
55€
</div>
<div class="info">
<span class="descripcio">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
</div>
</div>
</div>
</div>
if you use boostrap framework
you can use the bootstrap column and row.
<!-- language: lang-html -->
<div class="row">
<div class="col-6 productes">
<div class="producte1">
<div class="caixa">
<div class="caixa-img">
<img alt="" src="imgExplora/imgCarrousel/herbicida.jpg">
<div class="overlay">
Comprar
</div>
</div>
<div class="col-6">
<div class="tipo">
<a href="#">
<h3>HERBICIDA</h3>
</a>
<!--
<div class="rating">
<span>β˜†</span><span>β˜†</span><span>β˜†</span><span>β˜†</span><span>β˜†</span>
</div>-->
</div>
55€
</div>
<div class="info">
<span class="descripcio">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
</div>
</div>
</div>
</div>
</div>
<!-- end snippet -->
You have too much nested divs that dont need to be there, just making it more complex.
Also, your text is going outside your div borders, this is not a good thing.
You can move your text next to the image by using flex.
You always apply flex on a parent of the element that you want to move around (in this case, div with a picture, and div with a text).
So you are going to apply flex to a div that holds both of those divs (div with image, and div with text).
Here is my solution to this problem on a simple example, it should help you :
https://codepen.io/Juka99/pen/YzGVQyv

bootstrap card overlaps on top of each other on mobile screen

So i have one "flipping card" and another bootstrap 4 card side by side like this: (I have edited the image to hide text)
However when this is tested on target mobile screen using chrome's dev consolde, The 2nd Card overlaps the flipping card and completely covers it. like this:
I have put the code inside the container, row and col-md-* like this:
<div class="container">
<div class="row">
<div class="col-md-4">
</div>
....
<div class="col-md-8">
</div>
</div>
</div>
For full refrence, here is my full html and css code:
html:
<!-- start of third block -->
<div class="thirdblock">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card-container">
<div class="card">
<div class="front">
<div class="cover">
</div>
<div class="user">
<img class="img-circle" src="images/...jpg" />
</div>
<div class="content">
<div class="main">
<h3 class="name">.</h3>
<p class="profession">.</p>
<p class="">..
<div class="text-center">
<i class="fa fa-mail-forward"></i> Flip
</div>
</p>
</div>
</div>
</div> <!-- end front panel -->
<div class="back">
<div class="content">
<div class="main">
<p> </p>
<p class="lead">
.</p>
<p> </p>
<br>
<div class="stats-container">
<div class="stats">
<h4>100+</h4>
<p>
Followers
</p>
</div>
<div class="stats">
<h4>10+</h4>
<p>
Following
</p>
</div>
<div class="stats">
<h4>100+</h4>
<p>
Projects
</p>
</div>
</div>
</div>
</div>
</div> <!-- end back panel -->
</div> <!-- end card -->
</div> <!-- end card-container -->
</div> <!-- end col-md-4 -->
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h4> </h4>
<p class="lead">
</p>
<img class="rounded mx-auto d-block" src="images/....png" />
<br>
</div>
</div>
</div>
</div><!-- end row -->
</div> <!-- end container -->
</div>
<!-- end third block -->
And the huge css code:
.thirdblock {
padding-top: 50px;
padding-bottom: 50px;
height: 100%;
font-family: 'Arima Madurai', cursive;
background-image: url("../images/image.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.card {
font-family: 'Arima Madurai', Verdana;
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 4px;
color: #444444;
-webkit-box-shadow: 0px 0px 19px 0px rgba(0, 0, 0, 0.16);
-moz-box-shadow: 0px 0px 19px 0px rgba(0, 0, 0, 0.16);
box-shadow: 0px 0px 19px 0px rgba(0, 0, 0, 0.16);
}
/*Flipping Card Code*/
/*Flip Card Starts*/
.btn:hover,
.btn:focus,
.btn:active {
outline: 0 !important;
}
/* entire container, keeps perspective */
.card-container {
-webkit-perspective: 900px;
-moz-perspective: 900px;
-o-perspective: 900px;
perspective: 900px;
margin-bottom: 3px;
}
/* flip the pane when hovered */
.card-container:not(.manual-flip):hover .card,
.card-container.hover.manual-flip .card {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.card-container.static:hover .card,
.card-container.static.hover .card {
-webkit-transform: none;
-moz-transform: none;
-o-transform: none;
transform: none;
}
/* flip speed goes here */
.card {
-webkit-transition: -webkit-transform .5s;
-moz-transition: -moz-transform .5s;
-o-transition: -o-transform .5s;
transition: transform .5s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front,
.back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
background-color: #FFF;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.14);
}
/* front pane, placed above back */
.front {
z-index: 2;
}
/* back, initially hidden pane */
.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
z-index: 3;
}
.back .btn-simple {
position: absolute;
left: 0;
bottom: 4px;
}
/* Style */
.card-container,
.front,
.back {
width: 100%;
border-radius: 4px;
-webkit-box-shadow: 0px 0px 19px 0px rgba(0, 0, 0, 0.16);
-moz-box-shadow: 0px 0px 19px 0px rgba(0, 0, 0, 0.16);
box-shadow: 0px 0px 19px 0px rgba(0, 0, 0, 0.16);
margin-bottom: 50px;
}
.card .cover {
height: 105px;
overflow: hidden;
border-radius: 4px 4px 0 0;
}
.card .cover img {
width: 100%;
}
.card .user {
border-radius: 50%;
display: block;
height: 120px;
margin: -55px auto 0;
overflow: hidden;
width: 120px;
}
.card .user img {
width: 100%;
}
.card .content {
background-color: rgba(0, 0, 0, 0);
box-shadow: none;
padding: 10px 20px 20px;
}
.card .content .main {
min-height: 100%;
}
.card .back .content .main {
height: 100%;
}
.card .name {
font-family: 'Arima Madurai', cursive;
font-size: 22px;
line-height: 28px;
margin: 10px 0 0;
text-align: center;
text-transform: capitalize;
}
.card h5 {
margin: 5px 0;
font-weight: 400;
line-height: 20px;
}
.card .profession {
color: #999999;
text-align: center;
margin-bottom: 20px;
}
.card .fofooter-toter {
border-top: 1px solid #EEEEEE;
color: #999999;
margin: 30px 0 0;
padding: 10px 0 0;
text-align: center;
}
.card .footer-t .social-links {
font-size: 18px;
}
.card .footer-t .social-links a {
margin: 0 7px;
}
.card .footer-t .btn-simple {
margin-top: -6px;
}
.card .header {
padding: 15px 20px;
height: 90px;
}
.card .motto {
font-family: 'Arima Madurai', cursive;
border-bottom: 1px solid #EEEEEE;
color: #999999;
font-size: 14px;
font-weight: 400;
padding-bottom: 10px;
text-align: center;
}
.card .stats-container {
width: 100%;
margin-top: 50px;
}
.card .stats {
display: block;
float: left;
width: 33.333333%;
text-align: center;
}
.card .stats:first-child {
border-right: 1px solid #EEEEEE;
}
.card .stats:last-child {
border-left: 1px solid #EEEEEE;
}
.card .stats h4 {
font-family: 'Arima Madurai', cursive;
font-weight: 300;
margin-bottom: 5px;
}
.card .stats p {
color: #777777;
}
Can someone please help me as in what am i messing up?
just add fixed height for your .card class, because of position absolute on .front and .back classes, card class won't take any height.
.card{
height:362px;
}
Remove the CSS for class
.front,.back
/* position: absolute; */
/* top: 0; */