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>
Related
in my HTML code, I have some rows and div, but one div is shown before another, even if in the code is after. Div with class "contact" is shown before div with class "photos"
Photo: https://imgur.com/a/Y8BGQIM
<div class="photos">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8 section-heading">Galerie Foto</div>
</div>
<div class="gallery">
<img src="background1.jpeg" alt="Cinque Terre">
</div>
<div class="gallery">
<img src="galerie1.jfif" alt="Forest">
</div>
<div class="gallery">
<img src="galerie2.jfif" alt="Northern Lights">
</div>
<div class="gallery">
<img src="galerie3.jfif" alt="Mountains">
</div>
</div>
<div class="contact">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8 section-heading">Contact</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-6 section-subheading">
<h1><br>
<br>
</h1>
</div>
</div>
</div>
And the css code that I applied to the divs:
.photos{
width: 100%;
position: absolute;
background-color: black;
}
div.gallery {
border: 1px solid #ccc;
float: left;
}
.section-subheading:hover {
border: 5px solid #d3ae87;
}
div.gallery img {
width: 400px;
height: 400px;}
.contact{
width: 100%;
position: absolute;
background-color: black;
}
Hope deleting or commenting position: absolute in both the places will give you expected result.
Give a try. to below CSS
.photos{
width: 100%;
background-color: black;
}
div.gallery {
border: 1px solid #ccc;
float: left;
}
.section-subheading:hover {
border: 5px solid #d3ae87;
}
div.gallery img {
width: 400px;
height: 400px;}
.contact{
width: 100%;
background-color: black;
}
Position absolute will position both divs on top of one another at the top of the page if no other styling positions then differently. Remove the position absolute it is not needed here and add a float left to your photos class and your contact class so that the divs fall in order under one another because your gallery has a float left set.
.photos{
width: 100%;
float:left;
background-color: green;
}
div.gallery {
border: 1px solid #ccc;
float: left;
}
.section-subheading:hover {
border: 5px solid #d3ae87;
}
div.gallery img {
width: 400px;
height: 400px;}
.contact{
width: 100%;
background-color: black;
float:left;
}
I am trying to make a layout where #txt-bar and #main-content-area will overlap on #image. ( #txt-bar is overlapping on #image with following CSS ) but to achieve overlapping of #main-content-area on #image if I use top:-60px at #main-content-area then it will leave a gap between #main-content-area and #footer. I don't know how to solve this issue. Please help me.
/* CSS */
body {
position: absolute;
}
#top-bar {
background-color: black;
color: white;
}
#txt-bar {
height: 40px;
background-color: pink;
position: relative;
z-index: 4;
}
#link-bar {
background-color: red;
height: 40px;
z-index: 4;
}
#image {
position: relative;
z-index: 3;
}
.line {
width: 100%;
position: relative;
border-bottom: 4px solid black;
}
#main-content-area {
position: relative;
background-color: red;
top: -60px;
z-index: 4;
}
#footer {
background-color: green;
position: relative;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6" id="txt-bar">
<h1>Greetings</h1>
</div>
<div class="col-sm-6" id="link-bar">
<h1>Link bar </h1>
</div>
</div>
<div class="row">
<div class="col-sm-12" id="image">
<img src="https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300" class="img-responsive" />
</div>
</div>
<div class="line"></div>
<div class="row">
<div class="col-sm-2">
</div>
<div class="col-sm-8" id="main-content-area">
<h1>Main content area </h1>
</div>
<div class="col-sm-2">
</div>
</div>
<div class="row" id="footer">
<div class="col-sm-12">
<h1>Footer Element </h1>
</div>
</div>
</div>
Wrap all divs (#txt-bar #main-content-area and #image) in a parent div with position:relative then use position:absolute for #main-content-area and #txt-bar, this will solve your issues.
.wrap{position:relative;max-width:300px;}
#txt-bar {
height: 40px;
background-color: pink;
position: absolute;
top:10px;
width:100%;
}
#main-content-area {
position: absolute;
bottom:10px;
width:100%;
background-color: red;
}
<div class=wrap>
<div id=txt-bar>txt-bar</div>
<div id=image><img src=https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300></div>
<div id=main-content-area>main-content-area</div>
</div>
More Info
How do i place the image perfectly like this in various screen sizes?
.background-login {
background: url(../img/login.png) no-repeat;
background-size: 100%;
z-index: -2;
position: absolute;
top: 8%;
min-height: 400px;
right: 2%;
height: 100%;
}
.background-login-create {
background: url(../img/login.png) no-repeat;
background-size: 100%;
z-index: -2;
position: absolute;
top: 17%;
min-height: 400px;
right: 2%;
height: 100%;
}
.background-login-create-profile {
background: url(../img/login.png) no-repeat;
background-size: 100%;
z-index: -2;
position: absolute;
top: 13%;
min-height: 400px;
right: 2%;
height: 100%;
}
.sellfie-start-text {
font-size: 15px;
padding: 145px;
text-align: center;
font-weight: 200;
position: relative;
top: 8%;
vertical-align: middle;
color: #FFF;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container div-login">
<div class="row">
<div class="col-sm-5 col-md-offset-1">
<div class="center">
<h2 class="login-title"></h2>
<h4></h4>
<p class=""></p>
</div>
<div class="account-wall">
<p class="profile-name">Hello!<span style="color:red">:)</span></p>
<p class="profile-desc">We require only your mobile number for both login and signup</p>
<br>
<div class="form-signin">
<div class="md-form">
<input type="text" placeholder="Enter Mobile Number" value="" name="mobile_number" id="mobile_number" class="mobile_number form-control">
</div>
<button class="btn btn-main btn-continue" id="continue">
CONTINUE</button>
<div class="form-signin-bottom">By clicking on Continue, you agree to our Privacy Policy
& Terms
</div>
</div>
</div>
</div>
<div class="col-sm-6 background-login">
<div class="sellfie-logo">
<img src="img/sellfie_white.png"/>
</div>
<div class="sellfie-start-text">
Sellfie is the easiest way to sell online and collect payments for your products & services on social networks
and online channels.
</div>
</div>
</div>
</div>
What if the left container is larger i want my right image to be the same height as the left container?
.background-login {
background: url(../img/login.png) no-repeat;
background-size: cover;
z-index: -2;
position: absolute;
margin-top: 50px;
right: 2%;
min-height:400px;
height: 100%;
}
I have added wrapper inside background-login element and some CSS to make it center aligned.
In .background-login CSS, set background-size: cover (this will make image cover the whole element)
I also removed top and right values, don't set position values on Bootstrap columns because they will break the layout.
body {
background-color: #ddd !important;
}
.form-left,
.background-login {
height: 400px;
}
.form-left {
background-color: white;
}
.background-login {
position: relative;
background: url(https://unsplash.it/600/400) no-repeat;
background-position: center center;
background-size: cover;
}
.background-login .wrapper {
position: absolute;
top: 50%;
transform: translateY(-50%);
padding: 30px;
text-align: center;
}
.sellfie-start-text {
font-size: 15px;
text-align: center;
font-weight: 200;
position: relative;
top: 8%;
vertical-align: middle;
color: #FFF;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container div-login">
<div class="row">
<div class="col-sm-5 col-md-offset-1 form-left">
<div class="center">
<h2 class="login-title"></h2>
<h4></h4>
<p class=""></p>
</div>
<div class="account-wall">
<p class="profile-name">Hello!<span style="color:red">:)</span></p>
<p class="profile-desc">We require only your mobile number for both login and signup</p>
<br>
<div class="form-signin">
<div class="md-form">
<input type="text" placeholder="Enter Mobile Number" value="" name="mobile_number" id="mobile_number" class="mobile_number form-control">
</div>
<button class="btn btn-main btn-continue" id="continue">
CONTINUE</button>
<div class="form-signin-bottom">By clicking on Continue, you agree to our Privacy Policy
& Terms
</div>
</div>
</div>
</div>
<div class="col-sm-6 background-login">
<div class="wrapper">
<div class="sellfie-logo">
<img src="img/sellfie_white.png"/>
</div>
<div class="sellfie-start-text">
Sellfie is the easiest way to sell online and collect payments for your products & services on social networks
and online channels.
</div>
</div>
</div>
</div>
</div>
#details {
display: inline-block;
vertical-align:middle;
border:solid black 1px;
width: 300px;
}
.photo {
display: inline-block;
vertical-align:middle;
width: 300px;
height: 300px;
border: 1px solid #d1c7ac;
}
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>
So I have several div containers for my website, and they stack vertically as follows:
and I want it to look more like this:
My HTML looks like this:
<div id="main">
<div id="header">
</div>
<div id="content">
<div id="game" class="box">
<canvas data-processing-sources="hello-web.pde"></canvas>
</div>
<div id="desc_down"> <!-- Description and Downloads -->
<div id="desc" class="box"> <!-- Description -->
</div>
<div id="down"> <!-- Downloads -->
<div id="windows" class="box">
</div>
<div id="mac" class="box">
</div>
<div id="linux" class="box">
</div>
<div id="code" class="box">
</div>
<div id="info" class="box">
</div>
</div>
</div>
<div id="screenshots" class="box">
</div>
<div id="tech_about">
<div id="tech" class="box">
</div>
<div id="about" class="box">
</div>
</div>
</div>
</div>
<div>
and my CSS like this:
#main {
max-width: 1280px;
width: 90%;
margin: 0 auto;
background-color: #b0e0e6; /* all colours temp */
}
#header, #content, #game, #desc_down, #screenshots, #tech_about, #info {
width: 100%;
}
#desc {
width: 60%;
}
#down {
width: 40%;
}
#windows, #mac, #linux, #code {
width: 50%;
}
#about {
width: 45%;
}
#tech {
width: 50%;
}
.box {
background-color: #FFFFFF;
border: 5px solid;
border-color: #000000;
height: 200px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
The heights of these boxes can and will change. I want to know how to make my website look like how want it to. Thank you.
Make them all float:left or display:inline-block.
Or better use sth like Bootstrap Grid system
There are endless ways to position your content. Here is an example of what can be achieved using floats.
Have an example!
HTML
<div id="wrap">
<div id="header"></div>
<div id="paneOne"></div>
<div class="minPane"></div>
<div class="minPane"></div>
<div class="minPane"></div>
<div class="minPane"></div>
<div id="wideMinPane"></div>
<div id="afterMini"></div>
</div>
CSS
#wrap {
width: 800px;
margin: 0 auto;
}
#header {
height: 200px;
background: #F00;
}
#paneOne {
width: 400px;
height: 500px;
background: #000;
float: left;
}
.minPane {
float: left;
width: 198px;
height: 200px;
background: #FF0;
border: solid 1px #000;
}
#wideMinPane {
float: left;
background: #F00;
border: solid 1px #000;
height: 90px;
background: #FF0;
width: 398px;
}
#afterMini {
height: 300px;
background: #F00;
clear: left;
}
Its simple. Set the width of the container div (which encloses all these div blocks)to some value.
Then give float:left to all the inner divs.