Rotated text on left border of responsive div - html

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>

Related

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 I place headline text behind another headline? (See image)

I would like to have headline text, similar to the way it is the image below, behind my headline text.
https://www.dropbox.com/s/f66x0txr37klbe0/example.png?dl=0
I thought potentially using a relative position on the first header would allow it but I don't see to be doing that correctly as nothing is appearing.
Can someone please help me with the code to achieve this effect?
Here is a working example using css an no z-index. Using the element creation order you can select which one is on top.
https://jsfiddle.net/s2aqxfr9/
<div>
<h1 class="h1-back">
World!
</h1>
<h1 class="h1-front">
Hello!
</h1>
</div>
Here is your CSS
div {
display:inline-block;
}
.h1-back {
position:absolute;
top:0;
left:0;
color:red;
opacity:0.5;
transform: rotate(-20deg);
}
.h1-front {
position:absolute;
top:0;
left:0;
color:blue;
}
way 1
<div class="main">
<img src="img.jpg">
<h1>Title</h1>
</div>
.main{
position:relative
}
.main img{
position:absolute;
z-index:1;
}
.main h1{
position:absolute;
z-index:2;
}
way 2:
<div class="main">
<h1>Title</h1>
</div>
.main{
background-image:url('path/to/img.jpg');
background-position:center;
background-repeat:no-repeat;
}
You have to position the second heading (or any other element) absolutely.
Positionthe top left corner in the middle, then fix the position with transform: translate():
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -40%) rotate(-12deg);
Don't forget that the element needs a parent with position: relative as a reference point.
.hero-section {
position:relative;
display: flex;
justify-content: center;
align-items: center;
min-height: 20vh;
background-color: rgba(0,0,0,0.1);
margin: 0 0 2rem 0;
padding: 1rem;
}
.another-hero-section {
position:relative
background-color: rgba(0,0,0,0.1);
margin: 0 0 1rem 0;
padding: 1rem;
}
.special-heading {
font-family: 'Amatic SC', cursive;
font-size: 5rem;
position: relative;
line-height: 1;
color: #333;
margin: 0;
}
.special-heading span {
font-family: 'Caveat Brush', cursive;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -40%) rotate(-12deg);
color: #127b9b;
text-shadow: 10px 12px 11px #000000cf;
font-size: 6rem;
}
.special-heading-foreground {
font-family: 'Caveat Brush', cursive;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(12deg);
color: #749b12;
text-shadow: 10px 12px 11px #000000cf;
font-size: 6rem;
margin: 0;
line-height 1;
}
<link href="https://fonts.googleapis.com/css?family=Amatic+SC|Caveat+Brush" rel="stylesheet">
<section class="hero-section">
<h1 class="special-heading">Well, interesting background <span>Foreground</span></h1>
</section>
<section class="hero-section">
<h1 class="special-heading">Another background</h1>
<h2 class="special-heading-foreground">Heading 2</h2>
</section>

Gap between background image and image in 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

Get button to hover over image

Hi guys i am trying to get my button in bootstrap 3 to overlap my image, i understand the use of z-index 1 but i cant seem to get it to work at all.
HTML:
.btn-warning {
color: #fff;
background-color: rgba(255, 198, 0, 0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
}
.aboutpic {
margin-bottom: 19px;
}
<div class="aboutpic">
<img src="//via.placeholder.com/350x150" class="img-responsive">
<button type="button" class="btn btn-warning">Download CV</button>
</div>
Try this:
.btn-warning {
color: #fff;
background-color: rgba(255,198,0,0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
You'll need to add a position: absolute; and a z-index: 1 to the button so that it can sit on top of the image.
codepen.io/lauraeddy/pen/KXEwOW
You can set the position of aboutpic to relative and the button to absolute, as in the following example.
UPDATE
Added style attributes to center the button over an arbitrarily sized image, using calc(50% - [button width or button height]).
.btn-warning {
color: #fff;
background-color: rgba(255, 198, 0, 0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
width: 120px;
height: 50px;
}
.aboutpic button {
position: absolute;
top: calc(50% - 25px);
left: calc(50% - 60px);
}
.aboutpic {
margin-bottom: 19px;
position: relative;
width: 350px;
height: 150px;
}
<div class="aboutpic">
<img src="http://via.placeholder.com/350x150" class="img-responsive">
<button type="button" class="btn btn-warning">Download CV</button>
</div>
Please try the following,
.btn-warning {
color: #fff;
background-color: rgba(255,198,0,0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
}
img{
height:200px;
width:200px;
}
.aboutpic{
position:relative;
}
.first{
position:absolute;
z-index:1;
}
.second{
position:absolute;
z-index:2;
left:20px;
top:50px;
}
<div class="aboutpic">
<div class="first">
<img src="https://static.pexels.com/photos/377911/pexels-photo-377911.jpeg" class="img-responsive">
</div>
<div class="second">
<button type="button" class="btn btn-warning">Download CV</button>
</div>
</div>
Hope this helps.

corner ribbon for resposive image

I am trying to make a corner ribbon to sit over an image, on a responsive design site. I have set up a fiddle page with the code I've got so far. As you can see there, it seems to insert a top margin (the corner of the ribbon is not disappearing) and the overflow is not hidden. Any ideas why?
JSfiddle
.ribbon-holder {
overflow: hidden;
}
.ribbon {
position: relative;
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 52px;
left: -32px;
width: 145px;
}
<div class="ribbon-holder">
<div class="ribbon ribbon-holder">Free Shipping!</div>
<a href="http://www.somesite.com">
<img src="http://www.adventurouskate.com/wp-content/uploads/2016/01/planes-black-shower-curtain.jpg" alt="Shower Curtin" />
</a>
</div>
use position:relative in the parent (.ribbon-holder) and absolute in the child (.ribbon)
.ribbon-holder {
overflow: hidden;
position: relative
}
.ribbon {
position: absolute;
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 32px;
left: -32px;
width: 145px;
}
<div class="ribbon-holder">
<div class="ribbon ribbon-holder">Free Shipping!</div>
<a href="http://www.somesite.com">
<img src="http://www.adventurouskate.com/wp-content/uploads/2016/01/planes-black-shower-curtain.jpg" alt="Shower Curtin" />
</a>
</div>
How about this:
html:
<div class="ribbon-holder" >
<a href="http://www.somesite.com" ><img itemprop="image" class="imageSize" src="http://www.adventurouskate.com/wp-content/uploads/2016/01/planes-black-shower-curtain.jpg" alt="Shower Curtin" /></a>
</div>
<div class="ribbon ribbon-holder">
Free Shipping!
</div>
css:
.ribbon-holder{
overflow: hidden;
}
.ribbon{
position: absolute;
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 30px;
left: -32px;
width:145px;
}
https://jsfiddle.net/L4kojc4k/2/
Here are the changes i made :
.ribbon-holder{
overflow: hidden;
position: relative;// added by DamienBannerot
}
.ribbon{
position: absolute;// added by DamienBannerot
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 32px;// added by DamienBannerot
left: -32px;// added by DamienBannerot
width:145px;
}
fiddle here : https://jsfiddle.net/L4kojc4k/4/