Gap between background image and image in html - html

There is a gap between my background image and I wish to close that gap. How would I go around doing that?
I have tried removing the text, setting margins to 0, removing whitespace, placing the divs inline with each other, setting the background image as a standalone image in HTML, changing the height of the image. I am stumped!
HTML:
<div class="main">
<h1 id="mainTitle">Sample Text</h1>
<hr>
<i class="fa fa-id-card" aria-hidden="true"></i><h3 id="underTitle">Sample Text</h3>
</div>
<input type="submit" class="btn" value="Sample Text">
<div class="projects">
<h1 id="proTitle">Sample Text</h1>
<img src="images/codebg.jpg" alt="Sample Text" id="codeimg">
</div>
CSS:
html, body{
font-family: 'Thasadith', sans-serif;
background-image: url(images/bg.png);
background-repeat: no-repeat;
}
.main{
position: absolute;
left: 50%;
transform: translateX(-50%);
text-align: center;
top: 350px;
font-size: 0;
margin: 0 auto;
}
#mainTitle{ font-size: 100px;}
#underTitle{ font-size: 50px; margin-top: 10px;}
#mainTitle, #underTitle{
transition: font-size 1s;
}
#mainTitle:hover{
font-size: 110px;
}
#underTitle:hover{
font-size: 60px
}
.fa-id-card{
position: absolute;
transform: translateX(-125px);
top: 77%;
font-size: 20px;
}
hr{
margin: 0 auto;
padding: 0;
background-color: black;
}
.btn{
position: absolute;
left: 50%;
transform: translateX(-50%);
text-align: center;
top: 560px;
width: 100px;
background-color: black;
color: white;
transition: width 1s ease;
}
.btn:hover{
color: white;
width: 110px;
}
.projects{
position: absolute;
left: 50%;
transform: translateX(-50%);
text-align: center;
top: 1100px;
/*background-image: url(images/codebg.jpg);*/
width: 100%;
height: 100%;
margin: 0 auto;
}
#proTitle{
color: black;
margin: 0 auto;
}
#codeimg{
opacity: 0.4;
}
Ideally, there should be no gap between the images
Thanks for any help anyone is able to provide

You can change the position type of your image.
Add this code in your CSS file:
img
{
position: relative;
bottom: -4px;
}
I recreate your code changing the images.
You can see in this link:
https://codepen.io/mvinnicius/pen/aPyObB
I hope help you

Here are some minor changes that make it work:
CSS: Add break.before and break.after styles for your title id's
#mainTitle{
font-size: 100px;
break.after: 0; }
#underTitle{
font-size: 50px;
margin-top: 10px;
break.before: 0; }
#mainTitle, #underTitle{
transition: font-size 1s; }
#mainTitle:hover{
font-size: 110px;
break.after: 0; }
#underTitle:hover{
font-size: 60px;
break.before: 0; }
HTML: Trade <div class="main"> for the Semantically correct <main>, then instead of using <h1> and <h3>(which force space around them), wrap it in a <p> tag.
<main>
<div>
<p><span id="mainTitle">Sample Text</span>
<hr>
<i class="fa fa-id-card" aria-hidden="true"></i><span id="underTitle">Sample Text</span>
</p>
</div>
<input type="submit" class="btn" value="Sample Text">
<div class="projects">
<h1 id="proTitle">Sample Text</h1>
<img src="images/codebg.jpg" alt="Sample Text" id="codeimg">
</div>
</main>

play with .projects css
top and left

Related

Rotated text on left border of responsive div

I am facing issue making text around the borders of a div, with dynamic content/images.
Here is html code:
<div class="fp-wrapper">
<a href="/url1">
<img class="fp-image" src="image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
css:
.fp-wrapper {
position: relative;
display: inline-block;
margin: auto;
}
.fp-image {
width: 80%;
float:left;
padding: 10px;
border: 1px solid #53565a;
z-index: 1;
}
.fp-title1, .fp-title2{
padding: 0 10px;
background: #fff;
position: absolute;
top: 0;
left: 30px;
color: #53565a;
text-transform: uppercase;
font-weight: 500;
}
.fp-title2 {
bottom: 50%;
top: unset !important;
transform: translate(-50%,-50%) rotate(-90deg);
}
Fiddle: https://jsfiddle.net/wutzbvef/
Now the problem is that the content is dynamic, so min-height/max-height or negative margins won't work (I think so). Also I need to make it responsive, covering the border. Is this approach correct or need to make it by some other approach. Please help.
Edit:
I may not explained better, but I basically want to vertical align top the -90deg rotated paragraph i.e. .fp-title2
Use transform-origin
.fp-wrapper {
position: relative;
display: inline-block;
margin-left: 50px;
}
.fp-image {
width: 100%;
padding: 10px;
border: 1px solid #53565a;
z-index: 1;
}
.fp-title1,
.fp-title2 {
padding: 0 10px;
background: #fff;
position: absolute;
top: 0;
left: 30px;
color: #53565a;
text-transform: uppercase;
font-weight: 500;
}
.fp-title2 {
transform: translate(-100%, 0%) rotate(-90deg);
transform-origin: right center;
}
.w2 .fp-image {
width: 80%;
}
.w3 .fp-image {
width: 60%;
}
<div class="fp-wrapper">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
<div class="fp-wrapper w2">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
<div class="fp-wrapper w3">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
Try rotating first, then re-center the div. Otherwise it's ok.
transform: rotate(-90deg) translate(-50%, -50%);
You can also use a variable font-size for smaller images.
(I would also use an :after class for this btw), use the a tag, like this:
.fp-wrapper {
}
.fp-wrapper a {
width: 40%;
display:inline-block;
position: relative;
z-index:1;
float:left;
padding: 10px;
border: 1px solid #53565a;
}
.fp-image {
width: 100%;
}
.fp-wrapper a:before{
position: absolute;
content:'text top';
padding: 0 10px;
background: #fff;
display:inline-block;
top: 0px;
left: 50%;
transform: translateX(-50%);
color: #53565a;
text-transform: uppercase;
font-weight: 500;
z-index:20;
}
.fp-wrapper a:after {
position:absolute;
content:"left text";
display:inline-block;
text-transform: uppercase;
font-weight: 500;
padding: 0 10px;
top:50%;
transform: translateX(-50%) rotate(-90deg);
left:10px;
z-index:10;
background-color:#fff;
}
<div class="fp-wrapper">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
</div>
<div class="fp-wrapper">
<a href="/url1" style="width:30%;">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
</div>

Add a Link to an Overlay Image

I would like to add a link to an image that has an overlay applied to it. When users hover over the image they get an opaque overlay and text appear. This works great, however I also need users to be able to click that image and taken to a link.
I have pasted my code below - the overlay works but the link portion does not. I believe it's because the overlay is interfering. I tried changing the placement of the link but was unable to do so. I am able to make the '+' be the link, but ideally the entire image should link.
Any thoughts?
JSFiddle
.roomphoto:hover .img__description { transform: translateY(0); }
.roomphoto .img__description_layer { top: 30px; }
.roomphoto:hover .img__description_layer { visibility: visible; opacity: 1; }
.img__description_layer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
color: #cdcbca;
visibility: hidden;
opacity: 0;
display: flex;
align-items: center;
justify-content: center;
transition: opacity .2s, visibility .2s;
}
.roomphoto {
height: 166px;
}
.img__description {
transition: .2s;
transform: translateY(1em);
z-index: 999;
}
.overlay {
position: relative;
}
.overlay:after {
position: absolute;
content:"";
top:0;
left:0;
width:100%;
height:100%;
opacity:0;
}
.overlay:hover:after {
opacity: .8;
}
.blue:after {
background-color: #1a3761;
}
.img__description a {
color: #fff;
}
.roomselect {
clear: both;
float: none;
width: 100%;
max-width: 1000px;
margin: 0px auto;
padding-top: 20px;
}
.roomselect img {
width: 100%;
margin-bottom: -10px;
}
.room3 {
width: 32%;
text-align: left;
float:left;
}
<div class="roomselect"><div class="room3">
<div class="roomphoto overlay blue">
<a href="http://www.google.com">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
</a>
<div class="img__description_layer">
<p class="img__description">
<span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span>
</p>
</div>
</div>
</div>
You need to rearrange your html in such a way that when you click on image, you are actually clicking on the anchor tag. I have made some changes to your html, let me know if these work. You might have to increase roomphoto height.
<div class="roomselect">
<div class="room3">
<a href="http://www.google.com">
<div class="roomphoto overlay blue">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
<div class="img__description_layer">
<p class="img__description"><span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span></p>
</div>
</div>
</a>
</div>
</div>

How do you place text along the bottom of an image?

How do you place text above an image, such that it runs across the bottom of the image.
i.e.
<div class="i_have_an_image">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
I am struggling to work it out, to see what I mean, The following web site, has a great example of this. I've seen it before on sites, heres an example snapshot of what I mean:
Wrap the image in an inline-block div which has position:relative.
Position the h2 absolutely with bottom:0 and width:100% and the height of the h2 will adjust automatically to the content of the positioned element.
.i_have_an_image {
display: inline-block;
position: relative;
}
.i_have_an_image img {
display: block;
}
.i_have_an_image h2 {
position: absolute;
margin: 0;
bottom: 0;
left: 0;
width:100%;
padding: 1em;
background: rgba(255, 255, 255, 0.5);
color: white;
}
<div class="i_have_an_image">
<img src="http://www.fillmurray.com/460/300" alt="">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
.i_have_an_image{
position:relative;
width:200px;
height:200px;
}
h2{
position:absolute;
bottom:0px;
background:rgba(0,0,0,0.5);
color:#fff;
margin:0px;
}
<div class="i_have_an_image">
<img src="http://i-cdn.phonearena.com/images/article/32854-image/First-samples-from-Sonys-new-13MP-stacked-camera-sensor-capable-of-HDR-video-show-up.jpg">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
.butFrame {
width: 32%;
position: relative;
cursor: pointer;
}
.butFrame .butHeading {
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 10px 0;
display: block;
background: rgba(0, 0, 0, 0.5);
margin: 0;
font-family: inherit;
font-size: 1.2em;
color: #fff;
text-align: center;
text-transform: uppercase;
font-weight: 400;
}
<div class="butFrame">
<img src="https://unsplash.it/g/380/210?random">
<div class="butHeading">Heading</div>
https://jsfiddle.net/n0aLts9w/
Another solution of image with heading and sub heading. (As per your given image)
Demo Here
.i_have_an_image{
position: relative;
background-image: url(http://i.imgur.com/McIDx6g.jpg);
background: url((http://i.imgur.com/McIDx6g.jpg) no-repeat center center;
height: 400px;
width: 400px;
}
.title_wrap{
position: absolute;
background-color: rgba(0, 0, 0, 0.5);
bottom: 0;
left: 0;
right: 0;
padding: 15px;
color: #ffffff;
}
.title_wrap h2 {
font-size: 20px;
margin: 0;
}
.title_wrap h6 {
font-size: 12px;
margin: 0;
}
<div class="i_have_an_image">
<div class="title_wrap">
<h2>Heading goes here</h2>
<h6>I appear on top of the image, but aligned along the bottom</h6>
</div>
</div>
You can make it like this:
I added only the "wrap" div
.wrap {
max-width: 300px;
}
h2 {
position: relative;
top: -78px;
opacity: 0.8;
background: #222222;
color: #fff;
}
<div class="i_have_an_image">
<div class="wrap">
<img src="http://www.theage.com.au/content/dam/images/g/p/o/1/v/l/image.related.homepagePortrait.300x370.gpnu1x.2f8s9.png/1466499504473.jpg" alt="Angelika Graswald in court with her lawyers. " width="300" height="370">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
</div>
This is how I've been doing it recently. It's using the new html5 tag figcaption
It doesn't matter how big the image is or what you put in the figcaption it should just work.
figure.overlay {
display: inline-block;
position: relative;
margin: 0;
}
figure.overlay figcaption {
position: absolute;
background: rgba(0, 0, 0, .5);
color: #fff;
bottom: 4px;
width: calc(100%-10px);
padding: 5px;
}
<figure class="overlay">
<img src="http://www.dogbreedinfo.com/images/germanshepherdface.jpg">
<figcaption>
<h3>
'Some header of some sort!'
</h3> Words that make up a sentance! Or maybe 2 sentances.
<br />
<br />Even with a new line
</figcaption>
</figure>
Ho you can do it with flexbox simply like this:
.imageWrapper {
width: 200px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: flex-start;
border: 1px solid black;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/a/a8/Tour_Eiffel_Wikimedia_Commons.jpg");
background-size: 100%;
}
.textAboveImage {
width: 100%;
height: 50px;
background-color: grey;
z-index: 200;
opacity: 0.5;
}
<div class="imageWrapper">
<div class="textAboveImage">I'm text</div>
</div>
Cheers.
You can make it like this:
I added only the "wrap" div
HTML:
<div class="i_have_an_image">
<div class="wrap">
<img src="http://www.theage.com.au/content/dam/images/g/p/o/1/v/l/image.related.homepagePortrait.300x370.gpnu1x.2f8s9.png/1466499504473.jpg" alt="Angelika Graswald in court with her lawyers. " width="300" height="370">
<h2>I appear on top of the image, but aligned along the bottom</h2>
</div>
</div>
CSS:
.wrap {
max-width: 300px;
}
h2 {
position: relative;
top: -78px;
opacity: 0.8;
background: #222222;
color:#fff;
}

How to make text appear on top of image

I am trying to make my text appear ontop of my background image. I have tried playing around with the z-index and positioning, but cannot seem to get it right.
Here is my HTML:
<div id="float-left">
<div id="triangles">
<img src="img/trianglebackground.png" id="tripic">
</div>
<div id="float-left-text">
<img src="img/portrait.png" id="port">
</div>
</div>
Here is the CSS I have currently:
#tripic {
z-index:1;
height: 550px;
width: 500px;
text-align: center;
opacity: 0.2;
position: relative;
}
#float-left {
float: left;
/*background: url('img/trianglebackground.png') no-repeat center;*/
background-size:500px 550px;
background-color: #03C9A9;
height: 550px;
width: 50%;
z-index:0 ;
position: relative;
}
#float-left-text{
text-align: center;
z-index: 100;
position: absolute;
}
#port {
height: 200px;
width: 125px;
}
Right now, the entire #floatlefttext section is below the background image, whereas I would like it to be ontop. I have tried to use background-image, but I am not sure it's going to be the best way to get the results I would like. Any advice would be great, thanks!
I created a fiddle for you here: https://jsfiddle.net/0w1max4f/
#floatlefttext{
text-align: center;
z-index: 100;
position: absolute;
top: 0px;
left: 0px;
}
Is this what you were looking for? Since your html didn't actually include any text elements (just an image) to be placed on top of the background, but hopefully this will help you anyway.
What I did was to clean up your html (you had some tags that were not properly closed, for example the images and some divs) and add top and left to you absolute positioned div.
You were using absolute and relative positioning correctly but forgot to specifiy where the absolute positioned item were supposed to be placed.
here's a good article about positioning if you want to learn more:
https://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/
Something like this
<div style="position: relative; background: url(path to image); width: (width)px; height: (height)px;">
<div style="position: absolute; bottom: 0; left: 0.5em; width: 400px; font-weight: bold; color: #fff;">
<p>(text to appear at the bottom left of the image)</p>
</div>
<p style="position: absolute; top: 1em; right: 2em; width: 120px; padding: 4px; background-color: #fff; font-weight: bold; font-size: 11px;">
(text to appear at the top right of the image)
</p>
</div>
Be aware that you should separate the css from the html
Fiddle: Text ontop of an image and linkage
CSS:
div.image-container
{
width: 400px;
}
a.imagewrapper
{
width:inherit;
}
img.theimage{
width:inherit;
}
a.teasertext
{
position: absolute;
padding-top: 1%;
color: #fff;
line-height: 1.2em;
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
letter-spacing: .02em;
font-size: 1.5em;
overflow-wrap: break-word;
overflow-y: hidden;
-webkit-transition: all .3s;
transition: all .3s;
font-size: 41px;
width:inherit;
}
HTML:
<div>WOOP DE DOO</div>
<div class="image-container">
<a class="teasertext" href="www.stackoverflow.com">Text on the image, wow amazing !</a>
<a class="imagewrapper" href="www.stackoverflow.com">
<img class="theimage" src="http://img.thesun.co.uk/aidemitlum/archive/01667/THUNDER620_1667926a.jpg">
</a>
</div>
<div class="image-container">
<a class="teasertext" href="www.stackoverflow.com">Text on the image, wow amazing !</a>
<a class="imagewrapper" href="www.stackoverflow.com">
<img class="theimage" src="http://img.thesun.co.uk/aidemitlum/archive/01667/THUNDER620_1667926a.jpg">
</a>
</div>
<div>WOOP DE DOO</div>

HTML & CSS Auto height not working properly

I have a carousel with images/descriptions in it and my height:auto does not work properly. Height computed is too big
JSBin: JSBin
I can only guess that this is because my .shadow class which is relative with height 150px.
Please take a look on it.
Edit: code as requested
This is result of one item from carousel
<div class="carousel2">
<div class="carousel">
<div class="owl-carousel owl-theme" id="owl-example" style=
"opacity: 1; display: block;">
<div class="owl-wrapper-outer">
<div class="owl-wrapper" style=
"width: 4092px; left: 0px; display: block; -webkit-transform: translate3d(0px, 0px, 0px); -webkit-transition: all 200ms ease; transition: all 200ms ease;">
<div class="owl-item" style="width: 341px;">
<div class="pc">
<div class="c">
<img alt="image" src=
"http://www.ramp-alberta.org/_system/ThumbnailCache/UserFilesImageAug~16~Site~1_004jpg.300.-1.-1108757834.jpg">
<div class="shadow">
<div class="description">
Event1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is my css
.carousel2
{
overflow: hidden;
/* height:400px; */
background-color: #344754;
}
.carousel
{
width: 1364px;
float: left;
height: auto;
}
.shadow
{
position: relative;
bottom: 150px;
left: 0;
right: 0;
background: rgba(222,103,21,0.7);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#B2344855', endColorstr='#B2344855');
height: 150px;
vertical-align: middle;
z-index: 1;
width: 100%;
text-align: center;
}
.pc{
/* border: blue 1px solid; */
width: 1%;
display: table;
margin: auto;
height: auto;
overflow: hidden;
}
.c
{
overflow: hidden;
}
.description
{
padding-top: 15px;
font-family: "FSRufus";
font-size: 30px;
font-weight: bold;
color: white;
}
.owl-item
{
overflow: hidden;
}
You should give class carousel2 a min-height so that CSS will know till what it needs to scale image. Try to use exact size images to save processing time. Also remove height from class Shadow. This should help.