Position Element in front of another object Using CSS - css

I'm new in CSS and this time I want to position my object in front of slider, So I read about that and I know Slider should have position: relative and my other object with position: absolute
Desire result:
So I do it, but it does not work, also the object is not responsive, how can I fix that? I prepare an example of how it works.
#main-slider {
width: 100%;
height: 528px;
/* border-radius: 0% 0% 50% 50% / 0% 0% 20% 20%; */
border-bottom-right-radius: 50% 25%;
border-bottom-left-radius: 50% 25%;
position: relative;
}
.badge {
background-color: #fff;
border-radius: 30px;
box-shadow: 0 15px 35px 0 rgba(42,51,83,.12), 0 5px 15px rgba(0,0,0,.06);
width: 17%;
position: absolute;
}
.text {
padding: 0.5rem 0.25rem 0.5rem 1rem;
}
.link {
border-radius: inherit;
display: inline-block;
background-color: red;
padding: 0.5rem 1rem;
color: #F9F9EC;
width: 57%;
}
<section>
<div>
<img id="main-slider" src="https://via.placeholder.com/1365x528?text=Slider">
<div class="badge">
<span class="text">Contact us</span>
<a class="link">
(555) <strong>123 4567</strong>
</a>
</div>
</div>
</section>
Regards

You can do this adding a class called .wrapper to this and using display: flex and justify content center. Also need a margin top: 0.5em to your .badge
Read more about flex boxes here
Run snippet below.
#main-slider {
width: 100%;
height: 528px;
/* border-radius: 0% 0% 50% 50% / 0% 0% 20% 20%; */
border-bottom-right-radius: 50% 25%;
border-bottom-left-radius: 50% 25%;
position: relative;
}
.badge {
background-color: #fff;
border-radius: 30px;
box-shadow: 0 15px 35px 0 rgba(42, 51, 83, .12), 0 5px 15px rgba(0, 0, 0, .06);
position: absolute;
margin-top: 0.5em;
}
.text {}
.link {
border-radius: inherit;
display: inline-block;
background-color: red;
padding: 0.5rem 1rem;
color: #F9F9EC;
}
.wrapper {
display: flex;
justify-content: center;
align-items: flex-end;
}
<section>
<div class="wrapper">
<img id="main-slider" src="https://via.placeholder.com/1365x528?text=Slider">
<div class="badge">
<span class="text">Contact us</span>
<a class="link">(555) <strong>123 4567</strong></a>
</div>
</div>
</section>

Related

Loop through HTML elements in CSS and apply style

I have 4 cards (extendible to N cards) in a stack that I want to show in a stacked effect using HTML and CSS.
Desired Output:
I have the following code so far, but need some help tweaking the CSS to show the stacked effect for all 4 cards instead of 2 cards.
body {
background-color: #e8eaed;
}
.stack {
width: 500px;
height: 500px;
position: absolute;
}
.card {
width: 80%;
min-height: 40%;
background-color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: grid;
justify-content: center;
align-items: center;
border-radius: 5px;
font-family: sans-serif;
font-size: 10rem;
color: #00000080;
box-shadow: 0 5px 15px 0 #00000040, 0 5px 5px 0#00000020;
transition: transform 200ms;
}
.card:nth-last-child(1) {
--y: calc(-50% + 15px);
transform: translate(-50%, var(--y)) scale(1.05);
}
<div class="stack">
<div class="card" style="--i:1">1</div>
<div class="card" style="--i:2">2</div>
<div class="card" style="--i:3">3</div>
<div class="card" style="--i:4">4</div>
</div>
You are using the CSS Custom Property --y in your styles and the custom property --i in your markup.
I've made some edits to your styles, to demonstrate how you can achieve the effect you describe.
Working Example:
body {
background-color: #e8eaed;
}
.stack {
width: 500px;
height: 500px;
position: absolute;
}
.card {
width: 80%;
min-height: 40%;
background-color: white;
position: absolute;
top: 100px;
left: 100px;
transform: translate(-50%, -50%);
display: grid;
justify-content: center;
align-items: center;
border-radius: 5px;
font-family: sans-serif;
font-size: 10rem;
color: #00000080;
box-shadow: 0 5px 15px 0 #00000040, 0 5px 5px 0#00000020;
transition: transform 200ms;
}
.card {
transform: translateY(calc((var(--y) * 20px) - 50%)) scale(calc(1.0 + var(--y) * 0.05));
}
<div class="stack">
<div class="card" style="--y:1">1</div>
<div class="card" style="--y:2">2</div>
<div class="card" style="--y:3">3</div>
<div class="card" style="--y:4">4</div>
</div>

How to make an image show over an element's padding region in CSS?

Current Situation Image
Here is what I have got. But I want that rectangle facebook image behind the red region (currently it is just behind the text 'Please')
#mlnk{
text-decoration:none;
position:relative;
top:40%;
left:0%;
color: #b5c5d6;
}
.container-corner-img{ /* **THIS IS TO BE PUSHED BACK** */
height: 40%; width: 70%;
position: absolute;
top: 5px; left:-75px;
}
.container{
width:50%;
height:30%;
background: linear-gradient(#8B9DC1, #3b5998);
padding:100px;
border-radius:12px;
position: relative;
font-family: sans-serif;
}
h1{ /* **THIS NEEDS TO BE BROUGHT TO FRONT** */
margin-left: auto;
margin-right: auto;
padding: 8px;
border-radius: 4px;
box-shadow: 0 4px 6px 0 rgba(0,0,0,0.2);
transition: 0.4s ease;
background-color: red;
margin-top: 0;
}
img{
height: 80%;
width: 50%;
}
<div class="container">
<div class="container-corner-img">
<img src="fbminimal.png">
</div>
<h1>
<a id="mlnk" href = "#link"> Please login to your facebook account first</a>
</h1>
</div>
I have commented the css definitions in CAPS that needs to be focused according to me.
To bring the heading to the front, you have to set z-index to a larger value. To be able to use z-index on an element it needs to have a different position than static. So use relative. Moreover, do not use the center-tag since it is deprecated. The layout should be controlled by CSS only.
#mlnk {
text-decoration: none;
position: relative;
top: 40%;
left: 0%;
color: #b5c5d6;
}
h3 {
color: midnightblue;
padding: 4px;
box-shadow: 0 2px 4px 0 #38434e;
background: #3c64ad;
}
.container-corner-img {
/* **THIS IS TO BE PUSHED BACK** */
height: 40%;
width: 70%;
position: absolute;
top: 5px;
left: -75px;
/* opacity: 0.4; */
}
.container {
width: 50%;
height: 30%;
background: linear-gradient(#8B9DC1, #3b5998);
padding: 100px;
border-radius: 12px;
position: relative;
font-family: sans-serif;
/* z-index: 1; */
margin: 0 auto;
}
h1 {
/* **THIS NEEDS TO BE BROUGHT TO FRONT** */
margin-left: auto;
margin-right: auto;
padding: 8px;
border-radius: 4px;
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2);
transition: 0.4s ease;
background-color: red;
/* rgba(0,0,80,0.2); */
margin-top: 0;
/* Add this */
position: relative;
z-index: 1000;
}
h1:hover {
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2), 0 6px 8px 0 rgba(0, 0, 0, 0.19);
transition: 0.4s ease;
}
img {
height: 80%;
width: 50%;
/* z-index: 0; */
}
.center {
text-align: center;
margin: 0 auto;
}
<div class="center">
<div class="container">
<div class="container-corner-img">
<img src="https://stocknews.com/wp-content/uploads/2017/07/facebook-fb-alternate.jpg">
</div>
<h1>
<a id="mlnk" href="#link"> Please login to your facebook account first</a>
</h1>
<h3>You need to Log In</h3>
</div>
</div>

Sideway rotate text with background

Hello I'm trying to make something like this with css Image Link.
I've tried transform: skew(0deg, -35deg); and transform: rotate(-45deg); but the background color isn't as the image.
you can try this
.container{
border: 1px solid black;
margin: 40px;
height: 400px;
position: relative;
overflow: hidden;
}
.rotated{
background: maroon;
color: white;
transform: rotate(45deg);
text-align: center;
width: 100px;
position: absolute;
right: -25px;
top: 15px;
}
<div class="container">
<div class="rotated">TEXT</div>
</div>
You can use this css approach for this
.card {
width:300px;
height: 300px;
position: relative;
background: #ddd;
overflow: hidden;
}
.tag {
position: absolute;
top:5px;
right:-24px;
background: #990000;
padding: 5px 30px;
text-align: center;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
color: #fff;
font-size: 14px;
}
<div class="card">
<div class="tag">New</div>
</div>
Well, I tested this only in chrome. I hope this can serve as a starting point for you.
https://jsfiddle.net/pablodarde/af5c9x78/
.container {
display: flex;
justify-content: center;
align-items: center;
width: 380px;
height: 380px;
background: linear-gradient(#D4EDFF, #fff);
}
.inner {
width: 300px;
height: 300px;
background: #fff;
box-shadow: 0 0 2px rgba(0,0,0,.1);
}
.holder-tag {
position: relative;
width: 0;
height: 0;
left: 300px;
}
.holder-tag .tag {
position: absolute;
right: -30px;
top: 20px;
border-bottom: 20px solid #900;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 10px;
width: 90px;
transform: rotate(45deg);
}
.holder-tag span {
position: absolute;
right: -18px;
top: 25px;
width: 110px;
line-height: 1px;
color: #fff;
font: normal 14px Arial, Verdana;
text-align: center;
padding: 5px 0 0 0;
box-sizing: border-box;
transform: rotate(45deg);
}
.content {
width: 80%;
padding: 10px;
}
<div class="container">
<div class="inner">
<div class="holder-tag">
<div class="tag"></div>
<span>new</span>
</div>
<div class="content">
<p>
You can write text here without worrying about space.
</p>
</div>
</div>
</div>

div height automatically changing causing error with styling

I'm having a problem with span where it is changing the height of my div, breaking the styling I have implemented.
I have four images stacked 2 by 2 and I want text to roll up when I hover over them.
However, when I hover over them and the text appears it changes the size of the div since I have translated the text up by a certain amount.
I have made the divs blue so you can better see what is happening.
The divs obtain their height automatically. There are no set pixel heights in my website; everything is made using percentages so it would seem I can't just hide overflow.
Any help would be much appreciated on how I can fix this.
/* CSS Document */
body {
padding-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
background-image: url("images/background/space2.jpg");
background-size: cover;
margin: 0px;
}
#navigation {
width: 17%;
height: 100%;
position: fixed;
z-index: 3;
margin-left: 8%;
background-color: black;
opacity: 0.8;
filter: alpha(opacity=80);
float: left;
}
.navigationbody {
width: 100%;
height: 50px;
border-bottom: 2px rgba(255, 255, 255, 0.1) solid;
text-align: center;
}
.navigationbody a {
text-decoration: none;
color: white;
font-size: 30px;
position: relative;
top: 15%;
}
.navigationbody a:hover {
opacity: 0.8;
filter: alpha(opacity=80);
}
#navcontent {
height: auto;
margin-top: 50%;
position: static;
background-color: ;
align-items: center;
align-content: center;
}
#icon {
width: 100%;
margin-bottom: 10px;
background-color: ;
margin-left: 15%;
}
#bodycontainer {
bottom: 200px;
}
#icon img {
width: 70%;
height: auto;
}
#container {
width: 100%;
position: fixed;
top: 0px;
bottom: 0px;
}
#contentcontainer {
width: 75%;
margin-left: 25%;
height: 100%;
z-index: 2;
float: left;
overflow-y: auto;
}
#contentcontainer:hover {
background-color: rgba(0, 0, 0, 0.3);
}
#content {
padding: 0px;
}
.about {
width: auto;
margin-top: 10%;
margin-bottom: 30%;
margin-left: 20%;
margin-right: 20%;
text-align: center;
padding-bottom: 20px;
border-bottom: dotted 2px rgba(255, 255, 255, 1.00);
}
.about a {
color: white;
font-size: 20px;
background-color: rgba(0, 0, 0, 0.20);
}
.about h1 {
color: white;
border-bottom: dotted 2px rgba(255, 255, 255, 1.00);
}
.about h2 {
color: white;
}
.abouthome {
width: auto;
margin-top: 10%;
margin-bottom: 30%;
margin-left: 20%;
margin-right: 20%;
text-align: center;
padding-bottom: 20px;
}
.abouthome h2 {
color: white;
border-bottom: dotted 2px rgba(255, 255, 255, 1.00);
}
.abouthome a {
color: white;
font-size: 20px;
background-color: rgba(0, 0, 0, 0.20);
}
.software {
width: 100%;
margin-top: 60px;
align-content: center;
background-color: ;
}
.software img {
width: 100px;
height: auto;
}
.software img:hover {
opacity: .5;
}
.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
.gallery:hover {
border: 1px solid #777;
}
.gallery img {
width: 100%;
height: auto;
}
.desc {
padding: 15px;
text-align: center;
}
#contentgames {
right: 0px;
padding-left: 10%;
padding-top: 20%;
}
.games {
width: 45%;
height: auto;
overflow: hidden;
margin-right: 20px;
float: left;
transition: 0.5s;
position: relative;
background-color: aqua;
word-break: keep-all;
}
.games:hover {}
.games span {
color: white;
position: relative;
left: 10px;
bottom: 20px;
margin: 10px;
padding: 5px;
font-size: 0px;
opacity: 0;
transition: 0.5s;
align-content: center;
}
.games:hover span {
color: white;
position: relative;
bottom: 200px;
margin: 10px;
font-size: 18px;
opacity: 1;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Steven game design</title>
<link rel="stylesheet" type="text/css" href="style3.css" />
</head>
<div id="navigation">
<div id="navcontent">
<div id="icon">
<img src="http://placehold.it/150x150">
</div>
<div id="bodycontainer">
<div class="navigationbody"></div>
<div class="navigationbody">
Home
</div>
<div class="navigationbody">
About
</div>
<div class="navigationbody">
Blog
</div>
<div class="navigationbody">
Videos
</div>
<div class="navigationbody">
Pictures
</div>
<div class="navigationbody">
Contact
</div>
</div>
</div>
</div>
<body>
<div id="container">
<div id="contentcontainer">
<div id="contentgames">
<div class="games">
<img src="http://placehold.it/350x150" width="100%" height="auto" />
<span> This is a simple game I started making in flash. All of the artwork was created in flash. Unfortunately I never completed the game many things don't work such as the score, taking damage, boss and many more
</span>
</div>
<div class="games">
<img src="http://placehold.it/350x150" width="100%" height="auto" />
<span> This is a simple game I made in flash it took less than a week to create.</span>
</div>
<div class="games">
<img src="http://placehold.it/350x150" width="100%" height="auto" />
<span> This is another simple game in flash I made over the course of a few days.</span>
</div>
<div class="games">
<img src="http://placehold.it/350x150" width="100%" height="auto" />
<span>This is the game I am currently working on. It is my first 3d game. I am making it in the unreal engine 4.</span>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
If the goal is for the image to be the deciding factor for the position and size of the div and the elements within it, this minimal, responsive example should provide some examples:
https://jsfiddle.net/d7aab2x7/2/
The critical code sets the text block to be positioned absolutely, allow the div to constrain it's size around the image:
div {
border: 1px solid red;
display: inline-block;
width: 40%;
position: relative;
overflow: hidden;
}
img {
display: block;
width: 100%;
}
span {
position: absolute;
bottom: -50px;
background: green;
height: 50px;
transition: bottom 200ms ease-out;
}
For this HTML:
<div>
<img src="http://placehold.it/300x300" />
<span>Some text that will appear on hover of the image</span>
</div>
Please note: I have re-created using the simplest example possible, and my fiddle uses only CSS for animation. Hopefully this provides you with an answer, while also providing general usefulness to the next person searching for something like this.

CSS arrow on tooltip DIV

I'm trying to add a centered arrow/triangle on each side of a rectangular tooltip div and I've tried applying some code from other questions and demos, but none look centered or the arrow's shadow overlaps the div. The arrow should be white with a shadow of 0 0 20px 0 rgba(0, 0, 0, 0.2);.
HTML:
<div class="tooltip cal-tooltip">
<div class="tooltip cal-tooltip">
<div class="cal-tooltip-cont">
<div class="cal-tooltip-img four-three-img">
<img src="http://placeholdit.imgix.net/~text?txtsize=75&txt=Event%20Photo&w=600&h=400" />
</div>
<div class="card-info">
<h2>Wrapping related content title</h2>
<h3>Event date</h3>
<h3>Event venue</h3>
</div>
</div>
</div>
CSS:
.tooltip {
position: absolute;
top: 0;
z-index: 1;
background-color: white;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2);
}
.tooltip > div {
padding: 15px;
}
.tooltip > div img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.cal-tooltip {
width: 20em;
cursor: auto;
}
.cal-tooltip .cal-tooltip-cont {
display: flex;
}
.cal-tooltip .cal-tooltip-cont > div {
flex-basis: 50%;
}
.cal-tooltip .cal-tooltip-cont > div:nth-child(1) {
padding-right: 5px;
}
.cal-tooltip .cal-tooltip-cont > div:nth-child(2) {
padding-left: 5px;
}
.cal-tooltip .cal-tooltip-cont > div h2 {
padding-bottom: 5px;
font-size: 1em;
}
.cal-tooltip .cal-tooltip-cont > div h3 {
font-size: .85em;
}
Demo: http://codepen.io/ourcore/pen/Lxeapj
Try something like this:
.tooltip {
position: absolute;
top: 20px;
left: 60px;
z-index: 1;
background-color: #fff;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, .2);
width: 17em;
padding: 15px;
}
.tooltip:after {
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -1em;
margin-top: -1em;
left: 100%; /* change to 0% for left arrow */
top: 50%;
box-sizing: border-box;
border: 1em solid black;
border-color: transparent transparent #fff #fff;
transform-origin: 50% 50%;
transform: rotate(-135deg); /* change to 45 deg for left arrow */
box-shadow: -5px 5px 10px 0 rgba(0, 0, 0, 0.1);
}
.card {
display: flex;
}
.card img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.card > div {
flex-basis: 50%;
}
.card-info {
padding-left: 15px;
}
<div class="tooltip">
<div class="card">
<div class="card-image">
<img src="http://placeholdit.imgix.net/~text?txtsize=75&txt=Event%20Photo&w=600&h=400" />
</div>
<div class="card-info">
<h2>Test title</h2>
<h3>Event date</h3>
<h3>Event venue</h3>
</div>
</div>
</div>
Inspired by this: https://codepen.io/ryanmcnz/pen/JDLhu
It's a start at least. Hope it helps!

Resources