So I would like to cover the whole thumbnail when hovering over, so that the overlay content fills the whole image, 100% by 100%. So the overlay should cover only image(whole size of it), not more than that.
Here's the pen to demonstrate the current state: http://codepen.io/anon/pen/JbJgoe
.about__images {
max-width: 800px;
margin: 0 auto;
}
.about__inner {
margin-top: 60px;
}
.about__inner img {
max-width: 100%;
margin-right: 20px;
}
.about .about__inner {
position: relative;
overflow: hidden;
}
.about .about__inner .about__inner--overlay {
background: rgba(0, 0, 0, .75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
transition: opacity .25s ease;
}
.about .about__inner:hover .about__inner--overlay {
opacity: 1;
}
<div class="container about">
<div class="about__images">
<div class="row">
<div class="about__inner col-md-4">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="" class="hideonhover">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
<div class="about__inner col-md-4">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
<div class="about__inner col-md-4">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
</div>
</div>
</div>
You are close to it. Just a small modification in structure and a few lines in css:
HTML:
<div class="col-md-4">
<div class="about__inner">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="" class="hideonhover">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
CSS:
.about .about__inner .about__inner--overlay {
background: rgba(0, 0, 0, .75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
transition: opacity .25s ease;
position: absolute;
top:0;
width:100%;
height:100%;
}
.about__inner{
position:relative;
}
.about__inner--overlay{
color:#fff;
}
Codepen: http://codepen.io/swapnaranjitanayak/pen/oYwKLO
You need to use absolute positionning and size the box. You may use coordonates to size the box so it fits any size since you already set the parent in relative positionning..
.about .about__inner .about__inner--overlay {
background: rgba(0, 0, 0, .75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
transition: opacity .25s ease;
top:0;
left:15px;
right:15px;
bottom:0;
color:white;
position:absolute
}
.about__images {
max-width: 800px;
margin: 0 auto;
}
.about__inner {
margin-top: 60px;
}
.about__inner img {
max-width: 100%;
padding-right: 20px;
}
.about .about__inner {
position: relative;
overflow: hidden;
}
.about .about__inner .about__inner--overlay {
background: rgba(0, 0, 0, .75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
transition: opacity .25s ease;
top:0;
left:15px;
right:35px;
bottom:0;
color:white;
position:absolute
}
.about .about__inner:hover .about__inner--overlay {
opacity: 1;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="container about">
<div class="about__images">
<div class="row">
<div class="about__inner col-md-4">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="" class="hideonhover">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
<div class="about__inner col-md-4">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
<div class="about__inner col-md-4">
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97300&w=400&h=300" alt="">
<div class="about__inner--overlay">
<i class="fa fa-user" aria-hidden="true"></i>
<p>lorem</p>
</div>
</div>
</div>
</div>
</div>
Try this:
.about__inner {
padding: 0px; //for full frame image
}
.about__inner img {
max-width: 100%;
max-height: 100%;
object-fit: cover; //force image display as cover, no scale
}
.about .about__inner .about__inner--overlay {
position: absolute; //You need it to arrange the div.
top: 0px;
left:0px;
width: 100%;
height: 100%;
}
Try this:
.about__images {
max-width: 800px;
margin: 0 auto;
}
.about__inner {
margin-top: 60px;
}
.about__inner img {
max-width: 100%;
margin-right: 20px;
}
.about .about__inner {
position: relative;
overflow: hidden;
}
.about .about__inner .about__inner--overlay {
background: rgba(0, 0, 0, .75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
transition: opacity .25s ease;
}
.about .about__inner:hover .about__inner--overlay {
opacity: 1;
position: relative;
height: 185px;
top: -185px;
}
Related
.img-wrap {
position: relative;
display: inline-block;
}
.img-wrap .close {
position: absolute;
top: 2px;
right: 2px;
z-index: 5;
transition: opacity 0.15s ease-in;
padding: 5px 2px 2px;
color: #000;
font-weight: bold;
cursor: pointer;
opacity: 0;
text-align: center;
font-size: 22px;
line-height: 10px;
border-radius: 50%;
}
.img-wrap:hover .close {
z-index: 10;
background-color: rgb(5 0 0 / 75%);
opacity: 1;
}
<div class="img-wrap">
<i class="fas fa-trash-alt fa-lg text-white"></i>
<div class="media">
<i class="fal fa-file fa-4x icon-pdf d-flex mr-3"></i>
<div class="media-body">
<h6 class="mt-0 mb-0 grey-text font-weight-bold">This is an existing File</h6>
<div><small><b class="mr-2">File Name</b>
${filename}
</small>
</div>
</div>
</div>
</div>
☝️This is what I want to display, but ended up like this👇
This works for the image but not for div with text
Just need to mask the background on hover. Got stuck over this.
If i understand your problem you can use a div (i called it layer) absolute positioned above the card and show it when you hover the card.
.img-wrap {
position: relative;
display: inline-block;
width:200px;/* not important */
height:200px;/* not important */
background:#aeaeae;/* not important */
}
.img-wrap .close {
position: absolute;
top: 2px;
right: 2px;
z-index: 5;
transition: opacity 0.15s ease-in;
padding: 5px 2px 2px;
color: #000;
font-weight: bold;
cursor: pointer;
opacity: 0;
text-align: center;
font-size: 22px;
line-height: 10px;
border-radius: 50%;
}
.img-wrap:hover .close {
z-index: 10;
background-color: rgb(5 0 0 / 75%);
opacity: 1;
}
/* add this */
.layer{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
z-index:2;
background:rgba(255,255,255,0.9);
display:none;
}
.img-wrap:hover .layer{
display:block;
}
<div class="img-wrap">
<i class="fas fa-trash-alt fa-lg text-white"> x </i>
<div class="layer"> </div>
<div class="media">
<i class="fal fa-file fa-4x icon-pdf d-flex mr-3"></i>
<div class="media-body">
<h6 class="mt-0 mb-0 grey-text font-weight-bold">This is an existing File</h6>
<div><small><b class="mr-2">File Name</b>
${filename}
</small>
</div>
</div>
</div>
</div>
i have a card that no matter what i did to it i could not make it a perfect responsive for smaller screens some of the images will cut off i need to make it very small for that then the medum screen will be ruined i dont know what to do here is my codes
and here is some images of how it looks like and what will happen when it is on small screen
big screen small screen like you see in both sides the it cuts the image can anyone help me with this ?
*{
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
h1{
font-size: 2.5rem;
font-family: 'Montserrat';
font-weight: normal;
color: #444;
text-align: center;
margin: 2rem 0;
}
.wrapper{
width: 100%;
margin: 0 auto;
max-width: max-width: 80rem;;
}
.cols{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.col{
width: calc(25% - 2rem);
margin: 1rem;
cursor: pointer;
}
.container{
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-perspective: 1000px;
perspective: 1000px;
}
.front,
.back{
word-wrap: break-word;
white-space: -moz-pre-wrap; /* Firefox */
white-space: -pre-wrap; /* Opera <7 */
white-space: -o-pre-wrap; /* Opera 7 */
background-size: 400px 400px;
background-position: center;
background-repeat: no-repeat;
-webkit-transition: -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
-o-transition: transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: transform .7s cubic-bezier(0.4, 0.2, 0.2, 1), -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
text-align: center;
min-height: 400px;
min-width: 200px;
height: auto;
border-radius: 10px;
color: #fff;
font-size: 0.8rem;
text-overflow: ellipsis;
}
.back{
background-color: #000;
background: -webkit-linear-gradient(45deg, #cedce7 0%,#596a72 100%);
background: -o-linear-gradient(45deg, #cedce7 0%,#596a72 100%);
background: linear-gradient(45deg, #cedce7 0%,#596a72 100%);
}
.front:after{
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
content: '';
display: block;
opacity: .3;
background-color: #000;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-radius: 10px;
}
.container:hover .front,
.container:hover .back{
-webkit-transition: -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
-o-transition: transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: transform .7s cubic-bezier(0.4, 0.2, 0.2, 1), -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.back{
position: absolute;
top: 0;
left: 0;
width: 100%;
}
.inner{
-webkit-transform: translateY(-50%) translateZ(60px) scale(0.94);
transform: translateY(-50%) translateZ(60px) scale(0.94);
top: 50%;
position: absolute;
left: 0;
width: 100%;
padding: 2rem;
-webkit-box-sizing: border-box;
box-sizing: border-box;
outline: 1px solid transparent;
-webkit-perspective: inherit;
perspective: inherit;
z-index: 2;
}
.container .back{
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.container .front{
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.container:hover .back{
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.container:hover .front{
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.front .inner p{
font-size: 2rem;
margin-bottom: 2rem;
position: relative;
}
.front .inner p:after{
content: '';
width: 4rem;
height: 2px;
position: absolute;
background: #C6D4DF;
display: block;
left: 0;
right: 0;
margin: 0 auto;
bottom: -.75rem;
}
.front .inner span{
color: rgba(255,255,255,0.7);
font-family: 'Montserrat';
font-weight: 300;
}
#media screen and (max-width: 64rem){
.col{
width: calc(33.333333% - 2rem);
}
}
#media screen and (max-width: 48rem){
.col{
width: calc(50% - 2rem);
}
}
#media screen and (max-width: 32rem){
.col{
width: 100%;
margin: 0 0 2rem 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<div class="col-sm-6 col-md-3 col-lg-3 p-2 col-6" ontouchstart="this.classList.toggle('hover');">
<div class="container">
<a href="viewmovie.php?series=<?php echo $id; ?>&episode=<?php echo $id_ep ?>">
<div class="front" style="background-image: url(../../src/upload/posts/<?php echo $img; ?>)" >
<div class="inner">
<h5><?php echo "$name"; ?></h5>
<h6>خولهک <?php echo "$time"; ?> </h6>
<p></p>
<h6>IMDb: <?php echo $rate ?></h6>
<h6 class="fa fa-eye"> <?php echo "$views"; ?> </h6>
<span> </span>
</div>
</div>
<div class="back">
<div class="inner">
<p><?php echo "$description"; ?></p>
</div>
</div>
</a>
</div>
<center><a target="_blank" href= "<?php echo $trailer2 ?>"> <button type="button" class="btn btn-danger btn-sm m-2"><span class="fa fa-play">ترایلهر</button></span></a></center>
</div>
/* import font */
#import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');
*{
margin: 0;
padding: 0;
}
body{
margin: 0;
padding: 0;
background: #f1f1f1;
font-family: "Raleway", sans-serif;
text-align: center;
}
header{
margin: 0;
}
a, li{
list-style: none;
text-decoration: none;
}
nav{
text-align: center;
padding-top: 15px;
padding-bottom: 15px;
background: white;
width: 100%;
}
.nav-link + .nav-link{
margin-left: 30px;
}
nav ul li + nav ul li{
margin-right: 30px;
}
nav ul li{
display: inline-block;
}
.products{
padding: 30px 50px 100px 50px ;
}
.card{
max-width: 20%;
background: #ffffff;
padding: 10px;
border-radius: 5px;
text-align: right; display: inline-block;
margin-left: 20px;
margin-top: 30px;
animation: rotation 1s ease-in-out ;
}
#keyframes rotation {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(359deg);
}
}
.card-body div{
margin-top: 10px;
}
.card-footer button{
margin-top: 20px;
background: #fb727c;
border-radius: 5px;
outline: none;
border: none;
color: white;
margin-bottom: 5px;
}
.product-name{
text-align: left;
font-size: 18px;
font-family: "Raleway Medium", sans-serif;
}
.product-price{
text-align: left;
font-size: 22px;
font-family: "Raleway Medium", sans-serif;
}
button{
cursor: pointer;
font-family: "Raleway SemiBold", sans-serif;
font-size: 16px;
padding: 8px 25px 8px 25px;
transition: 0.2s ease-in-out;
}
button:hover{
box-shadow: 0 5px 10px rgba(239, 60, 73, 0.5);
transition: 0.2s ease-in-out;
background: rgb(239, 60, 73);
}
img{
max-width: 100%;
}
/* media queries */
#media (max-width: 768px) {
.products{
padding: 30px 20px 30px 20px;
}
.card{
max-width: 40%;
display: inline-block;
}
.card {
margin-left: 0;
margin-top: 30px;
}
}
<body>
<header>
<nav>
<ul>
<li class="nav-link"><a class="nav-item" href="">Home</a></li>
<li class="nav-link"><a class="nav-item" href="">About</a></li>
<li class="nav-link"><a class="nav-item" href="">Service</a></li>
<li class="nav-link"><a class="nav-item" href="">Contact</a></li>
</ul>
</nav>
</header>
<main>
<div class="products">
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="product-img">
<img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
</div>
</div>
<div class="card-body">
<div class="product-details">
<div class="product-name">Short denim dungarees</div>
</div>
<div class="product-price">
₹1,900
</div>
</div>
<div class="card-footer">
<button>Add to Cart</button>
</div>
</div>
</div>
</main>
</body>
So I got this code for a section in my page that uses a "!important" value on the css to make it work properly but I feel like it might be affecting the responsive side of it. I currently got the section to look properly on small devices but once I click(or hover) anywhere on the section, the section once again goes weird and I can't help but to think that the .projects-others:hover {width: 60% !important;} is behind it since it won't let me turn the transition off. How can I take it off for small devices but keep it on regular size? I've even tried putting the !important value on the transition queries but still no luck.
/*project section starts*/
.projects {
overflow: hidden;
height: 27em;
margin-top: 50px;
border: ;
}
.projects a {
cursor: default;
}
.box {
box-sizing: border-box;
box-shadow: 1.1px 1.2px #595959;
}
.projects h1 {
font-size: 4.40em;
text-align: center;
text-shadow: 0 3px 3px rgba(0, 0, 0, 0.9);
font-family: 'Dancing Script', cursive;
line-height: 80px;
padding-top: 2px;
}
.projects-others,
.projects-coding {
width: 50%;
-moz-transition: width .3s;
-webkit-transition: width .3s;
-o-transition: width .3s;
transition: width .3s;
height: 27em;
padding: 1em;
box-sizing: border-box;
}
.projects-others {
float: right;
background: #00004d;
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
.projects-coding {
background: white;
border-right: ;
}
.projects:hover .projects-others {
width: 40%;
}
.projects-coding:hover {
width: 60%;
}
/*the code that I think is causing the problem*/
.projects-others:hover {
width: 60% !important;
}
.projects-others:hover~.projects-coding {
width: 40%;
}
/*courosel section starts*/
.slideshow-container {
max-width: 1000px;
height: 7.5em;
position: relative;
margin: 7.5px auto;
}
.mySlides,
.mySlides2 {
display: none;
}
.project-text {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
font-family: 'Inknut Antiqua', serif;
}
.slideshow-img {
width: 17.4rem;
height: 10.5rem;
border-radius: 5px;
box-shadow: 2.5px 2.5px 2px rgba(0, 0, 0, 0.7);
-webkit-transition: display 1s;
transition: all 1s;
}
.slide-hover-p {
display: none;
}
.slideshow-img:hover+.slide-hover-p {
display: block;
}
.fade-car {
-moz-animation-name: fade-car;
-webkit-animation-name: fade-car;
-moz-animation-duration: 2.5s;
-webkit-animation-duration: 2.5s;
}
.previous,
.nexxt {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: ;
font-weight: bold;
font-size: 28px;
transition: 0.85s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.nexxt {
right: 0;
border-radius: 3px 0 0 3px;
}
.previous:hover,
.nexxt:hover {
cursor: pointer;
}
#p-others:hover,
#n-others:hover {
background-color: white;
color: #00004d;
}
#p-coding:hover,
#n-coding:hover {
background-color: #00004d;
color: white;
}
/*courosel media queries*/
#-webkit-keyframes fade-car {
from {
opacity: 0.4
}
to {
opacity: 1
}
}
#keyframes fade-car {
from {
opacity: 0.4
}
to {
opacity: 1
}
}
#media only screen and (max-width: 300px) {
.previous,
.nexxt,
.text {
font-size: 11px
}
}
#coding-github-btn {
font-size: 1.35em;
font-weight: 400;
background: #00004d;
border: 1px solid #00004d;
transition: all 0.9s;
cursor: pointer;
}
#coding-github-btn:hover,
#coding-github-btn:focus {
background: white;
border: 1px solid #00004d;
color: #00004d;
}
#others-etsy-btn {
font-size: 1.175em;
font-weight: 500;
background: #ffdb4d;
border: 1px solid #ffdb4d;
transition: all 0.6s;
color: #00004d;
cursor: pointer;
}
#others-etsy-btn:hover,
#others-etsy-btn:focus {
opacity: 0.7;
}
/*media queries for section*/
#media only screen and (max-width: 575px) {
.projects {
height: auto;
-moz-transition: none;
-webkit-transition: none;
-o-transition: none;
transition: none;
}
.projects a {
transition: none;
}
.projects-others, .projects-coding {
-moz-transition: none;
-webkit-transition: none;
-o-transition: none;
transition: none;
height: auto;
width: 100%;
max-width: 100%;
flex: 100%;
}
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans|Inknut+Antiqua|Dancing+Script|Courgette&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"><!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="profile-css/profile-stylesheet.css" type="text/css" />
<link rel="stylesheet" href="profile-css/mq-stylesheet.css" type="text/css" />
</head>
<body>
<!--project section headings-->
<div class="projects">
<a>
<div class="box projects-others" style="color: #ffdb4d;">
<h1 style="color: #ffdb4d;">Projects :<br> Others</h1>
<!--slider starts-->
<div class="slideshow-container">
<div class="mySlides fade-car">
<div class="project-text">
<img src="images/colorado_view2.jpg" class="slideshow-img img-fluid" alt="global6" />
<p class="slide-hover-p"><i>(My Profile Webpage)</i></p>
</div>
</div>
<div class="mySlides fade-car">
<div class="project-text">
<img src="images/global (35).jpg" class="slideshow-img img-fluid" alt="global6" />
<p class="slide-hover-p"><i>(My Profile Webpage)</i></p>
</div>
</div>
<div class="mySlides fade-car">
<div class="project-text">
<img src="images/global (35).jpg" class="slideshow-img img-fluid" alt="global6" />
<p class="slide-hover-p"><i>(My Profile Webpage)</i></p>
</div>
</div>
<a id="p-others" class="previous" onclick="plusSlides(-1)">❮</a>
<a id="n-others" class="nexxt" onclick="plusSlides(1)">❯</a>
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<!--slideshow ends-->
<br><br>
<div class="w-100 text-center">
<a id="others-etsy-btn" href="#" class="btn" role="button">My Etsy Store <span class="fa fa-etsy"></span></a>
</div>
</div>
</a>
<a>
<div class="box projects-coding" style="color:#00004d;">
<h1 style="color:#00004d;">Projects :<br> Coding</h1>
<!--second slider starts-->
<div class="slideshow-container">
<div class="mySlides2 fade-car">
<div class="project-text">
<img src="images/global (35).jpg" class="slideshow-img img-fluid" alt="global6" />
<p class="slide-hover-p"><i>(My Profile Webpage)</i></p>
</div>
</div>
<div class="mySlides2 fade-car">
<div class="project-text">
<img src="images/global (35).jpg" class="slideshow-img img-fluid" alt="global6" />
<p class="slide-hover-p"><i>(My Profile Webpage)</i></p>
</div>
</div>
<div class="mySlides2 fade-car">
<div class="project-text">
<img src="images/global (35).jpg" class="slideshow-img img-fluid" alt="global6" />
<p class="slide-hover-p"><i>(My Profile Webpage)</i></p>
</div>
</div>
<a id="p-coding" class="previous" onclick="plusSlides2(-1)">❮</a>
<a id="n-coding" class="nexxt" onclick="plusSlides2(1)">❯</a>
<span class="dot2" onclick="currentSlide2(1)"></span>
<span class="dot2" onclick="currentSlide2(2)"></span>
<span class="dot2" onclick="currentSlide2(3)"></span>
</div>
<!--slider ends-->
<br><br>
<div class="w-100 text-center">
<a id="coding-github-btn" href="#" class="btn" role="button">My Repositories <span class="fa fa-github"></span></a>
</div>
</div>
</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script><!-- Popper JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script><!-- Latest compiled bootstrap JavaScript -->
</body>
</html>
Placing a media query at the bottom of your css file with the same class and using important as well would definitely fix this.
I have an absolute slider div including images and some arrows, When I add another div, I expect it appear after last div (that is absolute), but it places behind absolute div, I know it's because absolute position is beyond box flow, and I just want to know how to put new div after last absolute div, widout giving margin-top?
HTML code:
<div id="next">
<i class="fa fa-5x fa-angle-right" aria-hidden="true"></i>
</div>
<div id="slider">
<div class="slide">
<img src="images/1.jpg" alt="">
</div>
<div class="slide">
<img src="images/2.jpg" alt="">
</div>
<div class="slide">
<img src="images/3.jpg" alt="">
</div>
</div>
<div id="prev">
<i class="fa fa-5x fa-angle-left" aria-hidden="true"></i>
</div>
<div id="advertises">
</div>
Css code:
#slider{
position: relative;
margin-top: -17px;
}
.slide{
position: absolute;
width: 100%;
height: 400px;
}
.slide img{
width: 100%;
height: 400px;
}
#next, #prev{
width: 70px;
margin-top: 150px;
cursor: pointer;
position: relative;
z-index: 100;
background-color: rgba(255, 255, 255, .5);
display: flex;
justify-content: center;
border-radius: 50%;
}
#next{
margin-right: 25px;
float: right;
}
#prev{
margin-left: 25px;
float: left;
}
#advertises{
width: 50%;
height: 300px;
border: 1px solid #101010;
display: flex;
}
Jsfiddle
When you use absolute positioning you lose the ability to relate that to other elements. That is, you can place a element relatively to other when the other is absolute.
You should try to look for another solution that fits your intention. I don't see the reason to not use a "normal" positioning.
One way is to wrap the slider, then add overflow:auto and height:400px
.wrapper {
overflow: auto;
height: 400px;
}
#slider {
position: relative;
margin-top: -17px;
}
.slide {
position: absolute;
width: 100%;
height: 400px;
}
.slide img {
width: 100%;
height: 400px;
}
#next,
#prev {
width: 70px;
margin-top: 150px;
cursor: pointer;
position: relative;
z-index: 100;
background-color: rgba(255, 255, 255, .5);
display: flex;
justify-content: center;
border-radius: 50%;
}
#next {
margin-right: 25px;
float: right;
}
#prev {
margin-left: 25px;
float: left;
}
#advertises {
clear: both;
width: 50%;
height: 300px;
border: 1px solid #101010;
display: flex;
}
<div class="wrapper">
<div id="next">
<i class="fa fa-5x fa-angle-right" aria-hidden="true"></i>
</div>
<div id="slider">
<div class="slide">
<img src="images/1.jpg" alt="">
</div>
<div class="slide">
<img src="images/2.jpg" alt="">
</div>
<div class="slide">
<img src="images/3.jpg" alt="">
</div>
</div>
<div id="prev">
<i class="fa fa-5x fa-angle-left" aria-hidden="true"></i>
</div>
</div>
<div id="advertises">
</div>
Currently I'm working on a website which contains four rows. I'd like to center the container horizontally and vertically where horizontally centering is already done.
Can anyone help me, please? I already tried with "display: flex" but it still doesn't work.
I'm working with Twitter Bootstrap and Font Awesome.
https://jsfiddle.net/L9dbzgpr/
Code:
<div class="container text-center">
<div class="row">
<div class="col-sm-3"> <i class="fa fa-5x fa-desktop"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-music"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cloud"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cog"></i>
</div>
</div>
<div class="row margin-top">
<div class="col-sm-3"> <i class="fa fa-5x fa-youtube-play"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-facebook"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-soundcloud"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-google"></i>
</div>
</div>
<div class="row margin-top">
<div class="col-sm-3"> <i class="fa fa-5x fa-instagram"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-dropbox"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-twitter"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cog"></i>
</div>
</div>
<div class="row margin-top">
<div class="col-sm-3"> <i class="fa fa-5x fa-cog"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-desktop"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-music"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cloud"></i>
</div>
</div>
</div>
CSS:
#charset "UTF-8";
/********** General styles **********/
body {
font-size: 16px;
background: url('../media/images/banner.jpg') no-repeat center center fixed;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width: 100%;
height: 100%;
position: relative;
}
a, a:focus, a:active {
text-decoration: none;
color: #F9F9F9;
opacity: 0.7;
}
a>.fa:hover, a:hover {
-webkit-transition: all .5s ease;
transition: all .5s ease;
transform: scale(1.2);
opacity: 1;
}
.container {
margin: 0 auto; /* horizontally centered */
}
.margin-top {
margin-top: 3em;
}
Update of my solution:
HTML:
#charset "UTF-8";
/********** General styles **********/
html, body {
height: 100%;
margin: 0;
}
body {
font-size: 16px;
background: url('../media/images/banner.jpg') no-repeat center center fixed;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
a, a:focus, a:active {
text-decoration: none;
color: #F9F9F9;
opacity: 0.7;
}
a>.fa:hover, a:hover {
-webkit-transition: all .5s ease;
transition: all .5s ease;
transform: scale(1.2);
opacity: 1;
}
.wrapper {
display: table;
height: 100%;
margin: 0 auto;
}
.wrapper-inner {
display: table-cell;
vertical-align: middle;
}
.margin-top {
margin-top: 3em;
}
.col-sm-3 {
padding-right: 4em;
padding-left: 4em;
}
CSS:
#charset "UTF-8";
/********** General styles **********/
html, body {
height: 100%;
margin: 0;
}
body {
font-size: 16px;
background-color: blue;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
a, a:focus, a:active {
text-decoration: none;
color: #F9F9F9;
opacity: 0.7;
}
a>.fa:hover, a:hover {
-webkit-transition: all .5s ease;
transition: all .5s ease;
transform: scale(1.2);
opacity: 1;
}
.wrapper {
display: table;
height: 100%;
margin: 0 auto;
}
.wrapper-inner {
display: table-cell;
vertical-align: middle;
}
.margin-top {
margin-top: 3em;
}
.col-sm-3 {
padding-right: 4em;
padding-left: 4em;
}
Patrick F, Hi there.
Have a look at just using this to center both ways.
.center {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
In your code you use col-sm-3 I changed this to col-xs-3 to stop all the display items going 1 row vertical in small screens. Unless that is what you want to happen.
Resize the window and you will see what I mean.
Here is the Fiddle.
If you don't know the height and width of the container you could use this styling to center the element horizontally and vertically:
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
But I don't know if this has other unwanted effects.