Floating 2 divs inside of a position relative div - html

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>

Related

I am trying to create an Image Slider, but when I set the position of the angle left icon to ABSOLUTE, it disappears from the screen

The angle left icon basically disappears when I set its position to absolute, but it remains otherwise.
Here the angle left icon is not visible due its position property. How can it appear on the screen so that I can position it on the top left part of the image, so as to make an image slider.
This is my html code:
<section>
<div class="team">
<div>
<h1 id="teamtext">Our Team and Contributers</h1>
</div>
<div class="content">
<div class="imageslider">
<img src="assets/photo1.jpg">
<img src="assets/photo2.jpg">
<img src="assets/photo3.jpg">
<img src="assets/photo4.jpg">
<img src="assets/photo5.jpg">
</div>
</div>
<div class="slideleft">
<i class="uil uil-angle-left"></i>
</div>
<div class="slideright">
<i class="uil uil-angle-right"></i>
</div>
</div>
</section>
and this is my CSS code:
.content{
height: 400px;
width: 750px;
overflow: hidden;
}
.imageslider{
height: 100%;
width: 100%;
}
.imageslider img{
width: 100%;
height: 100%;
object-fit: cover;
}
.slideleft{
color: red;
font-size: 100px;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.slideright{
color: red;
font-size: 100px;
}
I searched similar questions in the internet but they aren't working.
It appears while having position: absolute;. Please see my codesnippet:
<style type="text/css">.content {
height: 400px;
width: 750px;
overflow: hidden;
border: solid;
}
.imageslider {
height: 100%;
width: 100%;
border: solid;
display: flex;
flex-wrap: wrap;
}
.imageslider img {
width: 50%;
height: calc(400px / 3);
object-fit: cover;
}
.slideleft {
color: red;
font-size: 100px;
position: absolute;
top: 15%;
}
.slideright {
color: red;
font-size: 100px;
}
<section>
<div class="team">
<div>
<h1 id="teamtext">Our Team and Contributers</h1>
</div>
<div class="content">
<div class="imageslider">
<img src="https://s4.uupload.ir/files/1-6-5_ssnb.jpg">
<img src="https://s4.uupload.ir/files/1-6-5_ssnb.jpg">
<img src="https://s4.uupload.ir/files/1-6-5_ssnb.jpg">
<img src="https://s4.uupload.ir/files/1-6-5_ssnb.jpg">
<img src="https://s4.uupload.ir/files/1-6-5_ssnb.jpg">
</div>
</div>
<div class="slideleft">
<i class="uil uil-angle-left">slideleft</i>
</div>
<div class="slideright">
<i class="uil uil-angle-right">slideright</i>
</div>
</div>
</section>

Placing div on image

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;
}

How to add a cicle in front of an image

I'm trying to add a circle (the circle will contains an icon) in front of an image. My code works fine, but only in big display; 1,224 and up..However, this is not the case for tablet and mobile...So, my question is: How can I fix my code and make it works for all devices, without using #media. If #media is the only solution, then I will go for it..
HTML
<div class="row">
<div class="col-md-3">
<div class="service-box">
<div class="service-circle" >
<!--Add icon inside circle -->
</div>
<div class="service-bg" style="background-color: black;">
<!-- Insert img-->
</div>
<div class="service-text">
<h3>
ENTER TITLE
</h3>
</div>
</div>
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
</div>
CSS/LESS
.service-box {
.service-circle{
width: 120px;
height: 120px;
border-radius: 50%;
display: table-cell;
vertical-align: middle;
color: #000;
line-height: 500px;
text-align: center;
background: #fff;
position: absolute;
left: 30%;
margin-top: 65%;
border: 5px solid #e6ab43;
}
.service-bg {
height: 250px;
border:1px solid black;
img{
height: 100%;
}
}
.service-text {
text-align: center;
margin-top: 30%;
}
}
UPDATE:
This is what I'm trying to do:
Therefore, I'm using col-sm-3.
If you move your service-circle element inside your service-bg, you can then align it using transform: translate
.service-box {
background: red;
}
.service-bg {
position: relative; /* added */
height: 250px;
border:1px solid black;
}
img{
height: 100%;
}
.service-circle{
width: 120px;
height: 120px;
border-radius: 50%;
color: #000;
background: #fff;
position: absolute;
left: 50%; /* added */
top: 100%; /* added */
transform: translate(-50%,-50%); /* added */
border: 5px solid #e6ab43;
}
.service-text {
text-align: center;
margin-top: 80px; /* changed */
}
<div class="row">
<div class="col-md-3">
<div class="service-box">
<div class="service-bg" style="background-color: black;">
<!-- Insert img-->
<div class="service-circle">
<!--Add icon inside circle -->
</div>
</div>
<div class="service-text">
<h3>
ENTER TITLE
</h3>
</div>
</div>
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
</div>

How To place Both Logo and text in the Same Line?

what is the HTML with CSS Code to align have logo and text in the same line...that it must look as shown in the below pattern..
HTML:
<div class="top_left">
<div class="header">
<img src="https://b.fastcompany.net/multisite_files/fastcompany/imagecache/inline-small/inline/2015/09/3050613-inline-i-2-googles-new-logo-copy.png" alt="logo"/> <br/>
</div>
<h2 id="site-title"><a>GOOGLE</a>
<div id="site-description">SEARCH ENGINE </div>
</h2>
</div>
You can use the following html/css combo:
/* CSS */
.container-div {
position: fixed;
top: 0px;
left: 0px;
width: 250px;
height: 150px;
}
.img-div {
display: inline-block;
position: relative;
width: 45%;
height: 100%;
overflow: hidden;
}
.img-div img {
position: absolute;
top: 0px;
left: 5%;
width: 90%;
height: 50%;
border: 1px solid red;
}
.img-placeholder {
position: absolute;
top: 7.5%;
left: 15%;
}
.text-div {
display: inline-block;
position: relative;
width: 50%;
height: 100%;
border: 1px solid green;
overflow: auto;
}
<!-- HTML -->
<div class="container-div">
<div class="img-div">
<img />
<p class="img-placeholder">
Image Goes Here
</p>
</div>
<div class="text-div">
<h2>
Texty-text
</h2>
<p>
Sub-texty-text
</p>
</div>
</div>
Use this code
<p><img src="https://cdn.pixabay.com/photo/2016/12/27/21/03/lone-tree-1934897_960_720.jpg" alt="imag" style="height: 50px;width: 50px;"><span>kiran</span></p>
hello try to make a container for the logo and the text and a few div with a float that would do the job if i am right
like this
<div class="name of class you made" //give jut a with>
<div class="logo" //put float in this with a with>logo</div><div class="tekst" //put float in this with a with>tekst</div>
</div>
i am not sure but this would help
You can either use (on the h4 elements, as they are block by default)
display: inline-block;
Or you can float the elements to the left/rght
float: left;
Just don't forget to clear the floats after
clear: left;
Try something like this
<div class="container">
<div id="logo">
<img src="http://placehold.it/150x100">
</div>
<div id="text">
<h2>Hello</h2>
<h3>World</h3>
</div>
</div>
CSS:
.container > div {
display: inline-block;
padding: 5px;
}
#logo, #text {
float: left;
}
Here's the fiddle

align the fixed position image on center for all devices

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;}