How i can place my div with button, form and other content on an image like this picture. I have already placed the text on this image using this code:
.img-wrap {
position: relative;
}
.img-wrap h1 {
position: absolute;
left: 41.5%;
bottom: 45%;
background: rgba(255, 255, 255, 0.9);
height: 20%;
width: 17%;
padding: 3% 0px 0px 2.4%;
font-size: 2.3vw;
font-weight: bold;
color: rgba(0, 0, 0, 1);
font-family: Alegreya Sans black;
}
<div class="container-fluid">
<div class="row">
<div class="img-wrap">
<img src="...\images\main-foto.jpeg" class="img-responsive">
<h1>Funny Island</h1>
</div>
</div>
</div>
I tried to place my div on the same way, but it doesn't work.
.img-wrap {
position: relative;
}
.img-wrap div {
position: absolute;
width: 1000px;
height: 900px;
background-color: grey;
}
<div class="container-fluid">
<div class="row">
<div class="img-wrap">
<img src="...\images\main-foto.jpeg" class="img-responsive">
<h1>Funny Island</h1>
<div>
</div>
</div>
</div>
</div>
Thanks for the help
Add the image as a background image on .img-wrap. You can then add the buttons, text etc inside the div.
.img-wrap {
position: relative;
background-image: url( 'http://placekitten.com/500/300' );
background-size: cover;
text-align: center;
padding: 50px;
color: red;
}
<div class="container-fluid">
<div class="row">
<div class="img-wrap">
<h1>Funny Island</h1>
<div>
<p>Some text here</p>
<button>Button here</button>
</div>
</div>
</div>
</div>
You can use a negative on themargin-bottom of the element that you wish to contain the image. This will pull the element containing your form content up and above the element with the image inside it. See below for a demo:
.image-container {
height: 50vh;
background: red;
margin-bottom: -200px;
}
.content-container {
height: 150vh;
max-width: 960px;
margin: auto;
background: blue;
}
<div class="image-container"></div>
<div class="content-container"></div>
Another option is to add top or left properties to img-wrap div to position it where you want.
.img-wrap div{
position: absolute;
width:1000px;
height: 900px;
background-color: grey;
top:100px;
left:100px;
}
Related
This seems like a simple problem but I'm having a bit of trouble finding a solution. I have cards on my page and I simply want the image (in the img tag which is inside the div) to fill the background of the div. The way the page is set up I want the img tag inside the div to take up the whole background. I know I can use background img in the css file. but I want each image to be different and have them fit their divs. Trying to figure out how to style them to do this. This is what it looks like, hopefully my question is clear..
Here is the code for the card and image:
<div class="card">
<img src="https://images.unsplash.com/photo-1552465011" alt="">
<div class="card-description">
<h5>Title of Post</h5>
<img src="" alt="text">
<p> Some text here.</p>
</div>
</div>
img {
max-width: 100%;
max-height: 100%;
background-size: cover;
position: relative;
margin: 0;
padding: 0;
object-fit: cover;
}
.container .card{
background: lightgreen;
color: black;
display: flex;
justify-content: center;
align-items: flex-end;
width: 285px;
height: 145px;
margin: 15px;
padding: 0%;
border: 2px solid black;
background-size: cover;
position: relative;
}
You're almost there 👍
By using max-width: 100%; max-height: 100%
You are limiting your image to either take full width or height of the container.
Simply remove the max and just use width: 100% height: 100%
Then object-fit property will show it's effect.
You have two <img> tags in your markup. I assumed you want the first <img> tag to fill the containing <div>.
You can use object-fit: cover. There are other values available with object-fit but cover stretches the image so it covers the container, but without changing the aspect ratio of your image.
You can then limit the img to be 100% of the width and height of the container.
Note that since this may truncate part of your image if the image's aspect ratio is not the same as the container, you can also use object-position to adjust the alignment of the image with the container.
See these examples below.
h5 {
margin: 8px 0;
}
p {
font-size: 12px;
margin: 8px 0;
}
.container {
display: flex;
}
.card {
width: 285px;
height: 145px;
margin: 15px;
padding: 0%;
border: 2px solid black;
position: relative;
}
.card-image {
object-fit: cover;
object-position: bottom;
height: 100%;
width: 100%;
}
.card-description {
position: absolute;
width: 100%;
bottom: 0;
margin-bottom: 0;
text-align: center;
background-color: rgba(255, 255, 255, 0.2);
color: black;
}
<div class="container">
<div class="card">
<img class="card-image" src="http://cdn.wallpapername.com/1920x1080/20190806/5d498ca7ac412.jpg" alt="">
<div class="card-description">
<h5>Title of Post</h5>
<p> Some text here.</p>
</div>
</div>
<div class="card">
<img class="card-image" src="https://static.fanpage.it/wp-content/uploads/sites/22/2020/07/iStock-464788862.jpg" alt="">
<div class="card-description">
<h5>Title of Post</h5>
<p> Some text here.</p>
</div>
</div>
<div class="card">
<img class="card-image" src="https://media.istockphoto.com/photos/three-lovely-puffy-tit-sitting-on-a-branch-in-winter-sunny-park-picture-id865636134?k=6&m=865636134&s=612x612&w=0&h=dAqcmx8ETyzUOpk_g5-4uWLZeTDdt-6Qe9tENCAcj20=" alt="">
<div class="card-description">
<h5>Title of Post</h5>
<p> Some text here.</p>
</div>
</div>
</div>
Your code is somehow right but I have revamped your code. Check this.
img {
width: 100%;
height: 100%;
position: relative;
margin: 0;
padding: 0;
object-fit: cover;
object-position: center;
}
.container .card {
background: lightgreen;
color: black;
width: 285px;
height: 145px;
margin: 15px;
padding: 0%;
border: 2px solid black;
position: relative;
}
.card-description {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
text-align: center;
height: 50px;
background-color: rgba(0, 0, 0, .2);
display: flex;
align-content: center;
justify-content: center;
flex-wrap: wrap;
}
.card-heading, .card-content{
width: 100%;
}
.card-description h5,
.card-description p {
margin: 0;
color: #fff;
}
<div class="container">
<div class="card">
<img src="https://images.unsplash.com/photo-1651592753269-7d661e4a9899?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80"
alt="">
<div class="card-description">
<div class="card-heading">
<h5>Title of Post</h5>
</div>
<div class="card-content">
<p> Some text here.</p>
</div>
</div>
</div>
</div>
img{
display:block,
width:100%,
background-size:cover,
background-position:center center
}
or
.card img {
flex-shrink: 0;
min-width: 100%;
min-height: 100%
}
In my application I have a centered main div. Now I would like to get my logo halfway on top of the DIV. As shown in the picture:
I got this working, however, when my screensize changes, the image is located on the wrong place.
<div class="is-vertical-center">
<div class="box">
<div class="text-center">
<img class="img-on-top" src="assets/logo.png">
</div>
<div class="router-outlet">
<div class="pure-g">
<div class="pure-u-1-1">
<h5>Start</h5>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1-1">
<p>
Welcome Lorem ipsum
</p>
</div>
</div>
</div>
</div>
</div>
CSS:
.is-vertical-center {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.box {
background-color: $color-ts-main-flat;
border: 1px solid $color-ts-main-border;
border-radius: 4px;
max-width: 30%;
padding: 20px;
}
.text-center {
text-align: center !important;
}
.img-on-top {
top:0;
margin-top:5%;
position:absolute;
right: 50%;
}
.router-outlet {
flex: 1 0 100px;
background-color:blue;
/* stretch element immediately following the router-outlet element within the same parent element.
* This is the element injected by angular (Assumption)
*/
router-outlet + * {
height: 100%;
width: 100%;
}
}
I made a fiddle, can someone point me in the right direction?
https://jsfiddle.net/x78a3oyj/
Thanks in advance.
add transform3d the the child element
.img-on-top {
top: 0;
transform: translate3d(-50%, -50%, 0);
position: absolute;
left: 50%;/*change to left*/
width: 60px; /*set a width*/
background: hsl(106, 100%, 34%);
}
then on the parent element, set position relative
.box {
background-color: $color-ts-main-flat;
border: 1px solid $color-ts-main-border;
border-radius: 4px;
max-width: 30%;
padding: 20px;
position: relative;/*add this*/
background: hsl(0, 100%, 50%);
margin-top: 3rem;
}
you here is the final code:
.is-vertical-center {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.box {
background-color: $color-ts-main-flat;
border: 1px solid $color-ts-main-border;
border-radius: 4px;
max-width: 30%;
padding: 20px;
position: relative;
background: hsl(0, 100%, 50%);
margin-top: 3rem;
}
.text-center {
text-align: center !important;
}
.img-on-top {
top: 0;
transform: translate3d(-50%, -50%, 0);
position: absolute;
left: 50%;
width: 60px;
height: 60px;
background: hsl(106, 100%, 34%);
}
.router-outlet {
flex: 1 0 100px;
background-color:blue;
/* stretch element immediately following the router-outlet element within the same parent element.
* This is the element injected by angular (Assumption)
*/
router-outlet + * {
height: 100%;
width: 100%;
}
}
<div class="is-vertical-center">
<div class="box">
<div class="text-center">
<img class="img-on-top" src="assets/logo.png">
</div>
<div class="router-outlet">
<div class="pure-g">
<div class="pure-u-1-1">
<h5>Start</h5>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1-1">
<p>
Welcome Lorem ipsum
</p>
</div>
</div>
</div>
</div>
</div>
You can use this code - top image
body {
margin: 0;
}
.is-vertical-center {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.box {
background-color: $color-ts-main-flat;
border: 1px solid $color-ts-main-border;
border-radius: 4px;
max-width: 30%;
padding: 20px;
}
.text-center {
text-align: center !important;
}
.img-on-top {
top: 10px;
margin-top: 0;
position: absolute;
right: 50%;
}
.router-outlet {
flex: 1 0 100px;
background-color: blue;
/* stretch element immediately following the router-outlet element within the same parent element.
* This is the element injected by angular (Assumption)
*/
}
.router-outlet+* {
height: 100%;
width: 100%;
}
<div class="is-vertical-center">
<div class="box">
<div class="text-center">
<img class="img-on-top" src="assets/logo.png">
</div>
<div class="router-outlet">
<div class="pure-g">
<div class="pure-u-1-1">
<h5>Start</h5>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1-1">
<p>
Welcome Lorem ipsum
</p>
</div>
</div>
</div>
</div>
</div>
I have this flip box which looks like this
When I hover on it, it would turn around and would look like this.
I want to know, how do I move the text to the right only, I tried putting text-align: right; on my css but it didn't work. Am I doing it wrong?
Here's my CSS and HTML:
.box9 {
background-color: #4C586F;
width: 250px;
height: 150px;
margin: 0 auto;
padding: 45px;
}
.box10 {
background-image: url("../img/commended/erwin.png");
background-size: 50%;
background-repeat: no-repeat;
width: 250px;
height: 150px;
margin: 0 auto;
padding: 45px;
}
<div class="col_third">
<div class="hover panel">
<div class="front">
<div class="box9">
<p style="font-size:180%; color: white">Kudos!</p>
</div>
</div>
<div class="back">
<div class="box10">
<p style="font-size:180%; color: black">sdasdsadas</p>
</div>
</div>
</div>
</div>
I would do it like this, setting text-align: right in the back view and to center in the front view, vertical centering of the p tag and also changing some other settings (no padding [therefore changed width and height settings] and some other details):
.box9 {
background-color: #4C586F;
width: 340px;
height: 240px;
margin: 0 auto;
text-align: center;
}
.box10 {
background-image: url(http://placehold.it/150x250/);
background-size: auto 100%;
background-repeat: no-repeat;
width: 340px;
height: 240px;
margin: 0 auto;
text-align: right;
}
.box9 p,
.box10 p {
margin: 0;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.box10 p {
padding-right: 20px;
}
<div class="col_third">
<div class="hover panel">
<div class="front">
<div class="box9">
<p style="font-size:180%; color: white">Kudos!</p>
</div>
</div>
<div class="back">
<div class="box10">
<p style="font-size:180%; color: black">sdasdsadas</p>
</div>
</div>
</div>
</div>
I have a question about floating 2 divs inside of a position relative div. They should float left, but it does not work. I tryed it a few times by rewriting the CSS in developer tools. I hope someone can help me. I use the MDL (Material Design Lite) responsive framework from Google Inc. The result should look like in the screenshot. Thanks in advance for your help.
Final result
.card-wasserlabor {
min-height: 0;
width: 100%;
min-height: 110px;
height: auto;
box-shadow: 0 1px 1px 0 rgba(0,0,0,.015),0 3px 1px -2px rgba(0,0,0,.15),0 1px 5px 0 rgba(0,0,0,.015);
h4 {
font-size: $card-title;
color: $dark-text;
margin-left: 12px;
margin-top: 3px;
}
.img {
background: $grey;
display: inline-block;
height: 100%;
position: absolute;
width: 117px;
img {
height: 100%;
position: absolute;
width: 100%;
}
.circle-check {
background: rgba($black, 0.4);
height: 56px;
width: 56px;
border-radius: 100%;
position: absolute;
left: calc(50% - 30px);
top: calc(50% - 25px);
&:hover {
background: rgba($red, 1);
}
}
<div class="mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--4-col-phone">
<div class="mdl-card card-wasserlabor">
<div class="img">
<img src="../assets/cards/card-img-10.png" alt="sera">
<div class="circle-check">
<i class="material-icons">check</i>
</div>
</div>
<div class="text">
<h4>Mittelamerika</h4>
</div>
<div class="info">
<div class="mdl-button mdl-js-button mdl-button--icon">
<i class="material-icons">info</i>
</div>
</div>
</div>
</div>
I couldn't really run your code, there are too many missing variables to be able to work off of that. So I redid the code. I hope this can help. You just need to manage your widths and float everything left:
Take a look at this jsFiddle.
EDIT: The jsFiddle link was incorrect at first. Reclick this link if code relates to something else entirely.
EDIT 2: Fixed padding error in code. And replaced jsfiddle link.
html:
<div class="header-area">
<div style="padding: 20px; ">
Yellow header
</div>
</div>
<div class="container">
<div class="element" style="background-color: green; ">
<img src="http://placehold.it/150x150" alt="">
<div class="description">
This is the description
</div>
</div>
<div class="element" style="background-color: red; ">
<img src="http://placehold.it/150x150" alt="">
<div class="description">
This is the description
</div>
</div>
<div class="element" style="background-color: orange; ">
<img src="http://placehold.it/150x150" alt="">
<div class="description">
<div class="text">
This is the description
</div>
</div>
</div>
</div>
css:
.header-area{
background-color: yellow;
height: 100px;
width: 100%;
}
.container{
height: 100%;
width: 100%;
float: left;
background-color: lightblue;
}
.element{
float: left;
width: 50%;
height: 150px;
}
img{
float: left;
}
.description{
text-align: center;
}
.text{
padding-top: 50px;
}
I've made some modifications in your code, hope it can help you to completely achieve your goal:
To position your text over the img, you need to relative position their parent, and absolute position the text. Then you can move it over the img.
To easily align the img with the other elements, I think is useful to wrap these elements and give them an inline-block display. Then you can adjust them at the position you want.
.card-wasserlabor {
min-height: 0;
width: 100%;
min-height: 110px;
height: auto;
box-shadow: 0 1px 1px 0 rgba(0,0,0,.015),0 3px 1px -2px rgba(0,0,0,.15),0 1px 5px 0 rgba(0,0,0,.015);
}
h4 {
font-size: $card-title;
color: $dark-text;
}
.img {
background: $grey;
display: inline-block;
height: 100%;
position: relative;
width: 117px;
}
.circle-check {
position: absolute;
top: 0;
left: 0;
background: rgba($black, 0.4);
height: 56px;
width: 56px;
border-radius: 100%;
position: absolute;
left: calc(50% - 30px);
top: calc(50% - 25px);
&:hover {
background: rgba($red, 1);
}
}
.info-wrapper{
display: inline-block;
vertical-align: top;
}
<div class="mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--4-col-phone">
<div class="mdl-card card-wasserlabor">
<div class="img">
<img src="http://sweetclipart.com/multisite/sweetclipart/files/ff0000%20Color%20Square%20RGB%20Red.png" alt="sera" width="100px">
<div class="circle-check">
<i class="material-icons">check</i>
</div>
</div>
<div class="info-wrapper">
<div class="text">
<h4>Mittelamerika</h4>
</div>
<div class="info">
<div class="mdl-button mdl-js-button mdl-button--icon">
<i class="material-icons">info</i>
</div>
</div>
</div>
</div>
</div>
I have a fixed header and a image below the header.
The image has a property position: fixed.
Now for some devices the image is not in the center as It should be.
Here's the fiddle for it.
The left side has more spaces than the right hand side.
Also above the image, I want to add a p tag which is not showing up for some reason.
Please let me know what's wrong here.
<div class="content-wrapper new-class">
<div class="container">
<div class="row">
<div class="col-xs-12 ">
<div class="center-logo description">
<img src="http://i.imgur.com/ECTLTbK.png" alt="" class="img-responsive">
<P class="step1description" See price</p>
</div>
</div>
</div>
</div>
</div>
Checkout this solution:
body, html {
margin:0;
padding:0;
}
.content-wrapper {
position: relative;
overflow: hidden;
width: 100%;
background-color: #333230;
}
.content-wrapper .center-logo {
position: fixed;
width: 100%;
top: 125px;
left:0;
text-align: center;
margin: 5px 0 15px;
z-index: 1001;
background-color: #333230;
}
.content-wrapper .center-logo img {
margin: 0 auto;
}
.center-logo p.step1description {
position: relative;
top: -30px;
width: 220px;
text-align: center;
color: #fff;
font-size: 12px;
margin: 0 auto;
}
.description {
margin:30px 0 30px 0 !important;
}
.content-wrapper .content {
text-align: center;
width: 100%;
}
.new-class{
padding-bottom: 134px;
top: 134px;
}
<div class="content-wrapper new-class">
<div class="container">
<div class="row">
<div class="col-xs-12 ">
<div class="center-logo description">
<img src="http://i.imgur.com/ECTLTbK.png" alt="" class="img-responsive">
<p class="step1description"> See price</p>
</div>
</div>
</div>
</div>
</div>
You have some typos on html and css! - Here you can find a working fiddle: http://jsfiddle.net/sebastianbrosch/cxumhp9k/1/
Add left:0 on .content-wrapper .center-logo
.content-wrapper .center-logo { left:0;}