Centering text inside of parallax image made with SimpleParallax.js - css

I'm very new to coding and I'm trying to add some subheader text to a parallax image on my project. I created the parallax effect with SimpleParallax.js and put it, and an h2 subhead, inside of a div, but the text just sits underneath the photo. I implemented the solution outlined here
I added position: relative styling to the parallax class and the following code to the h2 text:
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%)
But, the text still isn't positioned correctly. It moves the text all the way to the top of the page where the h1 text is.
I need help figuring out how to situate the h2 text inside of the parallax image, ideally center-left justified.
This is a snippet of the problem area:
<header>
<img src="https://cdn.glitch.me/7cebc84e-df9c-45e9-95c1-
516a7a17465b/Header.jpg?v=1675454184505" class="header-image" alt="A
rendered image of our funky trike" />
<h1 class="header-text">Join us for a Funk-Filled Ride as we
<br> Roll Out, Pop Up, and Get Down!</h1>
</header>
<div>
<img class="frame-2" src="https://cdn.glitch.global/7cebc84e-
df9c-45e9-95c1-516a7a17465b/Frame-2.jpg?v=1675454173228">
<h2 class="subhead-text">Roll Out: our portable party can go
wherever you go</h2>
</div>
<style>
.header-image {
width: 100%;
}
.header-text {
color: #f3f3f3;
font-family: Verdana, Geneva, Tahoma, sans-serif;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
font-size: 7vh;
font-weight: bold;
font-style: italic;
background-color: #f41230bd;
width: 85%;
padding: 5px;
}
.subhead-text {
color: #f3f3f3;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-weight: bold;
font-style: italic;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
}
.frame-2 {
position: relative;
} </style>
The whole project is available on Code Pen.
Thanks for any help!

Related

How to position (offset) absolute element from it's current position (NOT from parent)?

I'm not sure if I'm having a brain freeze or lack of knowledge. This should be super straight forward but I can't make it to work:
I have a pseudo element that I want to be positioned absolute (so it's taken out of the flow and doesn't distort the other elements)
AND
I want the pseudo element to be offset from its CURRENT position, eg just 20px to the left from where it is now.
I CAN'T use the typical positioning offset from the parent via left: __px because it's causing problems on different screen sizes.
Could someone please enlighten me how to achieve this?
Thanks a lot!
JSFIDDLE: https://jsfiddle.net/AlphaX/pcsa2ow6/
.x_cta_error_msg {
line-height: 1.5;
background-color: lightgreen;
padding: 10px 15px 10px 45px;
height: 50px
}
.x_cta_error_msg::before, .x_simple_cta_error_msg::before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f06a";
font-size: 18px;
position: absolute;
}
<div style="position: relative">
<div class="x_cta_error_msg">
Some text that will be here to showing to the user as an info through the journey of making a booking.
</div>
</div>
<!-- just loading the fontawesome icon -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
You can make use of transform: translateX(-150%); to move it to the left where 150% means 150% its own width.
.x_cta_error_msg {
line-height: 1.5;
background-color: lightgreen;
padding: 10px 15px 10px 45px;
height: 50px
}
.x_cta_error_msg::before, .x_simple_cta_error_msg::before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f06a";
font-size: 18px;
position: absolute;
transform: translateX(-150%);
}
<div style="position: relative">
<div class="x_cta_error_msg">
Some text that will be here to showing to the user as an info through the journey of making a booking.
</div>
</div>
<!-- just loading the fontawesome icon -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
Although position:relative should work for you along with left as stated in comment.
don't use positionning at all and rely on normal flow:
.x_cta_error_msg {
line-height: 1.5;
background-color: lightgreen;
padding: 10px 15px 10px 45px;
height: 50px;
text-indent:-20px; /* all what you need */
}
.x_cta_error_msg::before,
.x_simple_cta_error_msg::before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f06a";
font-size: 18px;
}
<div style="position: relative">
<div class="x_cta_error_msg">
Some text that will be here to showing to the user as an info through the journey of making a booking
Some text that will be here to s.
</div>
</div>
<!-- just loading the fontawesome icon -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />

bootstrap tooltip overflow issues leading to slider

I am using Bootstrap's tooltip to display text against some of the buttons within the display page. Everything is working fine except that the display of the tooltip goes entirely below the footer. For e.g.
The click button highlighted in blue should give "add new record":
The image below shows the "add new record going below the footer instead of being displayed near to the button itself
Error image:
The CSS code goes something like this:
.tooltip {
position: absolute;
z-index: 1070;
display: inline;
margin: 0;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
font-style: normal;
font-weight: 400;
line-height: 1.5;
text-align: left;
text-align: start;
text-decoration: none;
text-shadow: none;
text-transform: none;
letter-spacing: normal;
word-break: normal;
word-spacing: normal;
white-space: normal;
line-break: auto;
font-size: .875rem;
word-wrap: break-word;
opacity: 0;
pointer-events: none
}
.tooltip.show {
opacity: .9
}
.tooltip .arrow {
position: absolute;
display: inline;
width: .8rem;
height: .4rem
}
.tooltip .arrow::before {
position: absolute;
content: "";
border-color: transparent;
border-style: solid
}
The html looks something this
<div class="tooltip fade bs-tooltip-bottom" role="tooltip" id="tooltip785907">
<div class="arrow">
</div>
<div class="tooltip-inner">Add a new record
</div>
</div>
Any guidance would be much appreciated
On which relative positioned element is the tooltip absolute positioned? I think that is the problem.
Can you show more of your HTML and CSS?

CSS Animate Div Width from Left to Right

I'm trying to animate the width of two overlapping divs, in order to show / hide the text contained within them. I'd like one div to animate from left to right, and the other to animate from right to left, so that as one piece of text is being wiped away, the other is being revealed following it.
Here's a JS fiddle of what I've got so far, but they are both being revealed from left to right. How do I get 'cancel' to be revealed from right to left?
https://jsfiddle.net/a43wrq20/
I thought that these rules would do it, but it isn't working for me:
.foo {
right: 0;
width: 0;
}
.foo.active{
right: 0;
width: 120px;
}
Also, they both shift slightly as they're animating? Can anyone see an easy fix for this?
Thanks a lot!
Animate an element's width from right to left cause some issue in this case, as the animated elements child, cancel-text, is left aligned. It will look like it slides in from the right.
The simplest solution is to leave the cancel-text, and animate the login, give it a background color (so it hides the cancel), give them both an absolute position, and you'll most likely get the desired result (if I got it right)
$(document).ready(function(){
$('.clicker').on("click", function(){
// if($('.email.input').val() ){
$('.email.input').toggleClass('up');
$('.password.input').toggleClass('up');
$('.signup').toggleClass('up');
$('.login').toggleClass('up');
$('.login-text-container').toggleClass('active');
// }
});
});
.center-clicker {
display: flex;
width: 100vw;
height: 50px;
top: 5vh;
position: absolute;
}
.clicker {
position: relative;
margin: auto;
display: flex;
align-items: center;
height: 7.5vh;
background: none;
}
.clicker:hover {
cursor: pointer;
}
.text-container {
text-align: center;
height: 100%;
width: 120px;
}
.login-text {
font-family: "HelveticaNeue-Ultra-Light", "Helvetica Neue Ultra Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
white-space: nowrap;
font-weight: 100;
font-size: 2.6em;
color: black;
}
.cancel-text {
font-family: "HelveticaNeue-Ultra-Light", "Helvetica Neue Ultra Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 100;
font-size: 2.6em;
color: black;
}
.login-container {
height: 100%;
width: 100%;
position: absolute;
}
.login-text-container {
position: absolute;
background: white;
overflow: hidden;
left: 0;
width: 0;
-webkit-transition: width .4s;
transition: width .4s;
}
.login-text-container.active {
width: 100%;
-webkit-transition: width .4s;
transition: width .4s;
}
.cancel-container {
height: 100%;
width: 100%;
position: absolute;
}
.cancel-text-container {
position: absolute;
overflow: hidden;
width: 100%;
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div class="center-clicker">
<div class="clicker">
<div class="text-container">
<div class="cancel-container">
<div class="cancel-text-container">
<span class="cancel-text">cancel</span>
</div>
</div>
<div class="login-container">
<div class="login-text-container active">
<span class="login-text"> log in </span>
</div>
</div>
</div>
</div>
</div>
I just modified the right:0; value for the .cancel-text-container to right:-110px;, and the left:0; value for the .login-text-container.active to left:10px;
Is this what you want?:
Updated Fiddle

CSS: aligning overlays

I'm trying to create a responsive design logo, using 2 strings, both slightly transparent. The strings are in different sizes, with the second on top of the first.
I've nearly got what I want (try the HTML below) however I would like the right hand edge of the 2 strings to align - The Div extends to the width of the browser and the overlap changes with the width of the display.
Because I want to give the browser some choices over how it's rendered I would rather not use measurements in pixels.
If it is at all relevant - I plan to add additional elements either side of the Div.
<!DOCTYPE html>
<html>
<head>
<style>
.outerText {
position: relative;
font-family: Arial,sans-serif;
font-weight: 900;
font-size: 800%;
text-align:center;
letter-spacing: -0.1em;
color: red;
opacity: 0.2;
top: 0;
left: 0;
}
.innerText {
position: absolute;
font-family: Arial,sans-serif;
font-weight: 900;
font-size: 600%;
text-align:right;
letter-spacing: -0.1em;
float: right;
color: blue;
opacity: 0.2;
z-index: 1;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
and the result is....<br />
<div style="position:relative">
<span class="outerText">OuterTxt</span>
<span class="innerText">InnerTxt</span>
</div>
<hr />
...nearly right - but the rt edges are not (necessarily) aligned
</body>
</html>
Update: jsfiddle here
You had a typo in your CSS ('postition' instead of 'position'), which was probably confusing things. Also, I think you want to remove the "float: right" once that typo is fixed.
This seems to be what (I think) you wanted:
div { /* make the selector more specific */
height: 150px; /* or whatever's suitable */
}
.outerText {
position: absolute;
bottom: 0;
right: 0;
}
.innerText {
position: absolute;
bottom: 7px; /* adjust as desired to compensate for smaller font size */
right: 0;
}
http://jsfiddle.net/nNMwb/2/
Have a look at Viewport Sized Typography
Experiment with the vw unit, I've found that in your example 28.5vw gives what seems to be the desired result.
.outerText {
position: relative;
font-family: Arial,sans-serif;
font-weight: 900;
font-size: 28.5vw;
text-align:center;
letter-spacing: -0.1em;
color: red;
opacity: 0.2;
top: 0;
left: 0;
}
.innerText {
position: absolute;
font-family: Arial,sans-serif;
font-weight: 900;
font-size: 28.5vw;
text-align:right;
letter-spacing: -0.1em;
float: right;
color: blue;
opacity: 0.2;
z-index: 1;
right: 0;
bottom: 0;
}
example
Embedding the Div in a table cell appears to give me the result I'm looking for - the inner and outer texts are both aligned on the right margin, share the same baseline and don't move relative to each other as the page is resized:
<!DOCTYPE html>
<html>
<head>
<style>
.outerText {
postition: relative;
font-family: Arial,sans-serif;
font-weight: 900;
font-size: 800%;
text-align: right;
letter-spacing: -0.1em;
color: red;
opacity: 0.2;
right: 0;
bottom: 0;
}
.innerText {
position: absolute;
font-family: Arial,sans-serif;
font-weight: 900;
font-size: 600%;
text-align:right;
letter-spacing: -0.1em;
float: right;
color: blue;
opacity: 0.2;
z-index: 1;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
and the result is....<br />
<table>
<tr>
<td>left</td>
<td>
<div style="position:relative">
<span class="outerText">OuterTxt</span>
<span class="innerText">InnerTxt</span>
</div>
</td>
<td>right</td>
</tr>
</table>
<hr />
...yeah!
</body>
</html>

Can't get text to center?

I have a div wrapped around a couple span's and using JS to make the span's fade in and out (for testimonials). Everything works, except I can't get the span text to center within the div. Here's the relevant code:
HTML -
<div class="slideshow">
<span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Hi</span>
<span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Goodbye</span>
</div><br />
And here's the slideshow CSS -
.slideshow {
width:940px;
height:64px;
background-image:url(../images/quotes.png);
}
Can anyone tell me what I'm doing wrong? Oh and yes I've tried text-align:center; with no luck.
[Edit] I'd like to add I've also tried adding in !important with no change.
I tested your code and just added
.slideshow {
text-align: center;
}
and the text centered just fine.
Maybe you've got a typo, or a css definition somewhere else that overrides your text-align?
Edit
I did an "inspect-element" of the fiddle posted and here are the css definitions i got:
<div class="slideshow" style="position: relative; ">
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: 'Lucida Grande', 'Lucida Sans Unicode', Calibri, Arial, sans-serif; position: absolute; z-index: 3; top: 0px; left: 0px; display: block; width: 13px; height: 15px; opacity: 0.275808; ">Hi</span>
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: 'Lucida Grande', 'Lucida Sans Unicode', Calibri, Arial, sans-serif; position: absolute; top: 0px; left: 0px; display: block; width: 52px; height: 15px; z-index: 2; opacity: 0.724192; ">Goodbye</span>
</div>
element.style {
color: #333;
display: block;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Calibri, Arial, sans-serif;
font-size: 12px;
height: 15px;
left: 0px;
opacity: 1;
position: absolute;
top: 0px;
width: 52px;
z-index: 3;
}
I would say the "display: block" is your problem.
You need to apply text-align: center to the containing <div>, and not do anything that causes the <span>s to be rendered as a block (such as floating them). Absolute positioning would also pull elements out of normal flow so they wouldn't be influenced by text-align.
Update : Now a working example has been provided, we can see what is going on. The span elements are being absolutely positioned by the plugin:
$slides.css({position: 'absolute', top:0, left:0}).hide()
Looks like you will need to rethink the layout logic the plugin is using.

Resources