How to set the paragraph to bottom of the images? - html

This is my css :
div#outerdiv
{
/* padding:10px:*/
width:100%;
height:50%;
background-color:#eaa6a6;
position:absolute;
}
img#rcorners1
{
border-radius: 50%;
background: #5A0065;
margin:40% auto;
display:block;
width: 25%;
height: 25%;
}
p#unknown
{
margin:auto;
font-size:20px;
display:block;
text-align:center;
width: 100%;
position:absolute;
}
Inside the div i placed the image and trying to place the paragraph bottom to the image but it takes long space even if i gave margin 0% auto;
This is Html:
<div id="outerdiv">
<img id="rcorners1" src="img/man.png" alt="unknown number"> </img>
<p id="unknown">UNKNOWN NUMBER</p>
</div>
ScreenShot:

First fix you img tag, img does not have closing tag. It should be
<img id="rcorners1" src="img/man.png" alt="unknown number" />
div#outerdiv
{
/* padding:10px:*/
width:100%;
height:50%;
background-color:#eaa6a6;
position:absolute;
}
img#rcorners1
{
border-radius: 50%;
background: #5A0065;
margin:40% auto 0 auto;
display:block;
width: 25%;
height: 25%;
}
p#unknown
{
margin:auto;
font-size:20px;
display:block;
text-align:center;
width: 100%;
position:absolute;
}
/* if you want to have your bottom margin still 40%*/
/*p#unknown {
margin-bottom: 40%;
}*/
<div id="outerdiv">
<img id="rcorners1" src="img/man.png" alt="unknown number" />
<p id="unknown">UNKNOWN NUMBER</p>
</div>
Actually img tag is taking margin-bottom: 40% which you need to make 0.
img#rcorners1{
border-radius: 50%;
background: #5A0065;
margin:40% auto 0 auto; // margin-bottom: 0;
display:block;
width: 25%;
height: 25%;
}

Related

HTML CSS : unable to position div element

I'm working on a project where I have a picture on top of my website and with a small space under the picture I want to add a text between 2 horizontal lines . I have made the text and the 2 lines but I have trouble positioning it under my image . I have put the text and the 2 lines inside a div element and I try to position it .
My code :
* {box-sizing: border-box}
body{
font-family:Aleo;
}
.background-container{
position:fixed;
top :0px;
left:0px;
height:auto;
width:100%;
margin:0;
}
.background-container > img {
width:100%;
height:350px;
display:block;
}
.inside-pic{
position:absolute;
top: 8px;
left: 16px;
color:white;
font-size:45px;
}
.inside-pic>span{
color:orange;
}
#between{
position: relative;
font-size: 30px;
z-index: 1;
overflow: hidden;
text-align: center;
}
#between:before, #between:after {
position: absolute;
top: 51%;
overflow: hidden;
width: 50%;
height: 1px;
content: '\a0';
background-color: grey;
}
#between:before {
margin-left: -50%;
text-align: right;
}
<body>
<div class = "background-container">
<img src = "IMAGES/selfhelp.jpg">
<div class = "inside-pic" >Book<span >House</span> </div>
</div>
<br/>
<div id = "title"> <h1 id = "between"> List of self-help books </h1> </div>
<br/><br/>
</body>
How the webpage is actually displayed :
I would appreciate your help with guiding me to position the title with the lines under the image . Thank you in advance
https://jsfiddle.net/g62nx8ya/
remove this
.background-container{
position:fixed;
top :0px;
left:0px;
height:auto;
width:100%;
margin:0;
}
and add margin:0 to the body
body{
font-family:Aleo;
margin: 0;
}
* {box-sizing: border-box}
body{
font-family:Aleo;
}
.background-container{
/*position:fixed;*/
top :0px;
left:0px;
height:auto;
width:100%;
margin:0;
}
.background-container > img {
width:100%;
height:350px;
display:block;
}
.inside-pic{
position:absolute;
top: 8px;
left: 16px;
color:white;
font-size:45px;
}
.inside-pic>span{
color:orange;
}
#between{
position: relative;
font-size: 30px;
z-index: 1;
overflow: hidden;
text-align: center;
}
#between:before, #between:after {
position: absolute;
top: 51%;
overflow: hidden;
width: 50%;
height: 1px;
content: '\a0';
background-color: grey;
}
#between:before {
margin-left: -50%;
text-align: right;
}
<body>
<div class = "background-container">
<img src = "IMAGES/selfhelp.jpg">
<div class = "inside-pic" >Book<span >House</span> </div>
</div>
<br/>
<div id = "title"> <h1 id = "between"> List of self-help books </h1> </div>
<br/><br/>
</body>

Floated box with top-left margin with vertically aligned and font-size responsive text divs

I have a div with fixed height and another box which is set on the bottom right of the parent box. Its height is fixed.
What I am thinking is to make it responsive. The font size will be responsive but it will not exceed the margins of the box if the screen size goes really big. I also want to maintain the vertical alignment of the texts.
#import url(https://fonts.googleapis.com/css?family=Karla);body{overflow:hidden;margin:0;text-align:left;color:#0d3852;font-family:Karla}#container{width:100%;height:100px;background:#124;text-align:center}#right{float:right;margin-top:50px;width:33.33%;min-height:120px;background:#f1f1f1}.queries{text-align:left;margin-left:3%;margin-top:3%}.line2{font-size:1.1vw;}.line1{font-size: 2vw;}
<div id="container">
<div id="right">
<h1 class="queries line1">TEMPLATE<br>TEMPLATE</h1>
<h3 class="queries line2">Template, Template, Template, Template and Template Temp</h3>
<h3 class="queries line2">01 Jul 2018 - 21 Aug 2018</h3>
</div>
</div>
So, I was thinking whether it is easy to adjust the current code or try playing with the flexbox:
LINK
or try something like this:
.parent-box {
background:#124;
width: 100%;
height:200px;
}
.float-lower-left {
background:#ccc;
position: relative;
float: right;
right: 0;
top: -50px;
right: 0;
width: 33.33%;
height:100px;
}
#outer {
height:100%;
padding:10% 0;
box-sizing:border-box;
}
#inner1 {
font-size:3.5vw;
height:70%;;
display:flex;
justify-content:left;
align-items:center;
background-color: yellow;
}
#inner2 {
font-size:2vw;
height:50%;
display:flex;
justify-content:left;
align-items:center;
background-color: red;
}
<textarea class="parent-box">
</textarea>
<span class="float-lower-left" >
<div id="inner1">
Template<br>Template
</div>
<div id="inner2">
Template, Template, Template, Template Temp
</div>
</span>
I set a limit for over the 728px.
#import url(https://fonts.googleapis.com/css?family=Karla);
body{
overflow:hidden;
margin:0;
text-align:left;
color:#0d3852;
font-family:Karla;
}
#container{
width:100%;
height:100px;
background:#124;
text-align:center;
}
#right{
float:right;
margin-top:50px;
width:33.33%;
min-height:120px;
background:#f1f1f1;
}
.queries{
text-align:left;
margin-left:3%;
margin-top:3%
}
.line2{
font-size:1.1vw;
}
.line1{
font-size: 2vw;
}
.parent-box {
background:#124;
width: 100%;
height:200px;
}
.float-lower-left {
background:#ccc;
position: relative;
float: right;
right: 0;
top: -50px;
right: 0;
width: 33.33%;
height:100px;
}
#outer {
height:100%;
padding:10% 0;
box-sizing:border-box;
}
#inner1 {
font-size:3.5vw;
height:70%;;
display:flex;
justify-content:left;
align-items:center;
background-color: yellow;
}
#inner2 {
font-size:2vw;
height:50%;
display:flex;
justify-content:left;
align-items:center;
background-color: red;
}
#media screen and (min-width: 728px) {
#inner1 {
font-size: 26px;
}
#inner2 {
font-size: 18px;
}
}
<div id="container">
<div id="right">
<h1 class="queries line1">TEMPLATE<br>TEMPLATE</h1>
<h3 class="queries line2">Template, Template, Template, Template and Template Temp</h3>
<h3 class="queries line2">01 Jul 2018 - 21 Aug 2018</h3>
</div>
</div>
<textarea class="parent-box">
</textarea>
<span class="float-lower-left" >
<div id="inner1">
Template<br>Template
</div>
<div id="inner2">
Template, Template, Template, Template Temp
</div>
</span>

image not correctly resized in chrome, compared to Firefox

I have an html page displaying an image.
When the image is larger than the window of the browser, the image is resized (keeping the same ratio) to fit in the window with Firefox.
But with Chrome, the image is compressed
Here is the html code:
<div class="container">
<div class="auto">
<img class="full-width" src="http://laurent.delrocq.free.fr/test/img-1.jpg" />
<div class="absolute">
<img src="http://laurent.delrocq.free.fr/test/left.png" alt="#" class="left">
<img src="http://laurent.delrocq.free.fr/test/right.png" alt="#" class="right">
</div>
</div>
</div>
and the css:
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.container {
text-align: center;
}
.auto {
width:auto;
height:auto;
position:relative;
display:inline-block;
}
.absolute {
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
z-index:2;
}
.left {
position:absolute;
top:50%;
left:15px;
transform: translateY(-50%);
}
.right {
position:absolute;
top:50%;
right:15px;
transform: translateY(-50%);
}
.full-width {
width:auto;
max-width:100%;
max-height: 100vh;
height:100%;
}
How can I change the code so that it works (resize) both on Firefox and Chrome ?
Mate, here is solution you search for:
https://jsfiddle.net/d5z3fnjh/1/
Check '.container', '.auto' and '.full-width' width and height values:
.full-width {
width:100%;
}
.container {
text-align: center;
width: 100vw;
}
.auto {
width:100%;
position:relative;
display:inline-block;
}
UPD:
Here is a solution with JS:
https://jsfiddle.net/d5z3fnjh/4/
I finally used js to set the correct size of the div according to the size of the image.
html:
<div class='fill-screen'>
<img id="photo" class='make-it-fit' src='https://upload.wikimedia.org/wikipedia/commons/f/f2/Leaning_Tower_of_Pisa.jpg'>
<div id="over_image">
<div class="left">
<a href="https://en.wikipedia.org/wiki/Arrow_(symbol)#/media/File:U%2B2190.svg" style="outline:0">
<img src="http://laurent.delrocq.free.fr/test/left.png" alt="#">
</a>
</div>
<div class="right">
<a href="https://en.wikipedia.org/wiki/Arrow_(symbol)#/media/File:U%2B2192.svg">
<img src="http://laurent.delrocq.free.fr/test/right.png" alt="#">
</a>
</div></div>
</div>
css:
div.fill-screen {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
text-align: center;
}
img.make-it-fit {
max-width: 100%;
max-height: 100%;
}
#over_image {
margin:0px;
padding:0px;
display: inline-block;
text-align: center;
color: #fff;
position: absolute;
height:100%;
background: rgba(0,0,0,.5);
}
.left{
opacity:0;
position:absolute;
width:20%;
height:100%;
}
.left a, .right a{
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%, -50%);
}
.right{
opacity:0;
position:absolute;
margin-left: 80%;
width:20%;
height:100%;
}
.left:hover{
opacity:1;
}
.right:hover{
opacity:1;
}
js:
function resizeDiv()
{
var img = document.getElementById('photo');
var width = img.clientWidth;
var height = img.clientHeight;
var left = img.offsetLeft;
var top = img.offsetTop;
document.getElementById('over_image').style.width= width + 'px';
document.getElementById('over_image').style.height= height + 'px';
document.getElementById('over_image').style.top= top + 'px';
document.getElementById('over_image').style.left= left + 'px';
}
$(document).ready(function() {
resizeDiv();
})
$(window).resize(function() {
resizeDiv();
})
The corresponding jsfiddle is here: https://jsfiddle.net/4kxjt813/

Place image on top of element with css

How do I place an image on top of a button with html and css?
<div>
<img src="photo.jpg">
<button>Text</button>
</div>
I guess it should be something like
div {
position: relative;
}
img {
position: absolute;
top: 10px;
}
but it acts a bit weird.
Is it possible to just have a normal div and then set the img to float on top of everything else in the div element?
I don't know what's your purpose exactly, if you want the image to take the whole line, make the button lay beneath, why don't set the CSS display attribute of the image to display:block;?
hello see the below one its simple with a few line code
<div style="position:relative;" >
<img src="http://www.industrydynamics.ca/images/skype_icon.png" width="100" height="100" >
<input type="button" name="" value="Button" style="position:absolute;width:80px;left:10px;top:120px;" >
</div>
You can use position: absolute with transform: translate() on img.
This calc(-100% - 1px) means
-100% or - height of element (img in this case) that you are performing transform on, so it will translate for its own height up on Y axis
-1px is for top border on div element.
div {
position: relative;
display: inline-block;
border: 1px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 1px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
Just to demonstrate if you have border of 5px then you should use -5px in calc.
div {
position: relative;
display: inline-block;
border: 5px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 5px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
#bottom{
background-repeat: repeat-x;
height:121px;
width: 984px;
margin-left: 20px;
margin-top: 13px;
}
#bottom .content{
width: 182px; /*328 co je 1/3 - 20margin left*/
height: 121px;
line-height: 20px;
margin-top: 0px;
margin-left: 9px;
margin-right:0px;
display:inline-block;
position:relative;
}
<div id="bottom">
<div class="content">
<img src="http://placehold.it/182x121"/>
<button>Text</button>
</div>
</div>
May be you are trying to achieve something like this.
.userIcon {
background: url('https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png') no-repeat;
height:20px;
width:20px;
background-size:20px;
top: 8px;
}
.left {
float:left;
}
.right {
float:right;
}
.clear{
clear:both;
}
.button{
padding:10px;
color: #FFF;
background-color: #0095ff;
border:1px solid #07c;
box-shadow: inset 0 1px 0 #66bfff;
}
.btnText{
margin:2px 0px 0px 10px;
}
<div>
<button class="button">
<span class="left userIcon"></span>
<span class="right btnText">Create user account</span>
<span class="clear"></span>
</button>
</div>
If you just want to make the image to come over the button, you can make the display as block
check the following snippet
div img{
display:block;
}
button{
text-align:center;
margin:40px;
padding:10px;
}
<div>
<img src="https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png">
<button>Text</button>
</div>
Hope this helps

How can I vertically center text over a responsive image?

How can I get the caption text on these images to move around when then the browser window is resized? My implementation is jicky and I need a way to keep the text from sliding around when the window is resized.
Codepen
<div class="row">
<div class="col-md-6">
<img src="http://placekitten.com/600/375" class="img-responsive" />
<h2 class="homeImageLink">
<span>Caption Text</span>
</h2>
</div>
<div class="col-md-6">
<img src="http://placekitten.com/600/375" class="img-responsive" />
<h2 class="homeImageLink">
<span>Caption Text</span>
</h2>
</div>
</div>
.homeImageLink {
position: absolute;
top: 110px;
left: 0;
text-align: center;
width: 100%;
}
.homeImageLink span {
color: red;
font-weight: 300;
font-style: italic;
text-transform: uppercase;
letter-spacing: 15px;
pointer-events: none;
}
Just add one class to parent container, make it's position relative.
.img-container {
position:relative;
}
And then make homeImageLink absolute and give top at around 45%..
It will make it vertically centered..
.homeImageLink {
position: absolute;
top: calc(50% - 24px); //24px is font size of H1 I assume
left: 0;
text-align: center;
width: 100%;
}
Demo here : http://codepen.io/anon/pen/bJadE
I came up with another solution, here's a working demo:
http://codepen.io/niente0/pen/jyzdRp
HTML:
<DIV class=wrapper>
<DIV class=divimage></DIV>
<DIV class=divtext>THIS IS A TEST</DIV>
</DIV>
CSS:
HTML,BODY {
max-width:1200px;
}
.wrapper {
position:relative;
width:100%;
max-width:1200px;
height:100%;
min-height:320px
}
.divimage { position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:url(https://thumbs.dreamstime.com/t/empty-red-banner-corners-ropes-textile-white-background-d-illustration-70434974.jpg);
background-repeat:no-repeat;
background-size:100% auto;
}
.divtext {
position:absolute;
top:0;
left:0;
width:100%;
padding-top:13.5%;
text-align:center;
font-weight:bold;
font-size:5vw;
color:white;
font-family:arial;
}
#media (min-width: 1200px) {
.divtext{
font-size:60px;
}
}