Placing text over an image - html

I want to place the text and headers I added in my code above the image I set in. Every time I center the text, the image is always covering it. The text and headers I have has to be above the image and not under.
#eventcenterimg {
text-align: center;
width: 30%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-repeat: no-repeat;
}
#starting-info {
text-align: center;
margin-left: 40vh;
font-family: 'Roboto Condensed', sans-serif;
color: black;
display: inline;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght#300;400&display=swap" rel="stylesheet">
<img src="img/correaevent.png" height="970" alt="" id="eventcenterimg">
<div class="correa-events-info">
<h4 id="starting-info">Book and experience any special events at Correa Events Center.</h4>
<h4 id="starting-info">Call to book at:</h4>
</div>
<div class="socialmedia">
<i class="fab fa-facebook-f"></i>
</div>

Just an alternative minimal solution, you could also set z-index: -1 for the <img> as a quick fix, without making changes on other elements.
Example:
#eventcenterimg {
/* 👇 Add this */
z-index: -1;
text-align: center;
width: 30%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-repeat: no-repeat;
}

I haven't tried your code yet, but if the case is just about things covering something else. Try changing this:
Set your text's z-index to 2 (set it in your styling)
I hope that works

only use absolute positioning when you have to. Use flex
#eventcenterimg {
text-align: center;
width: 30%;
/*position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -17%);
background-repeat: no-repeat; */
}
.starting-info {
text-align: center;
width: 100%;
font-family: 'Roboto Condensed', sans-serif;
color: black;
display: inline-block;
}
#container {
display: flex;
flex-direction: column;
justify-content:center;
align-items:center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
intitial-scale=1.0">
<title>Correa Events</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght#300;400&display=swap" rel="stylesheet">
</head>
<body>
<div id='container'>
<div class="correa-events-info">
<h4 class="starting-info">Book and experience any special events at Correa Events Center.</h4>
<h4 class="starting-info">Call to book at:</h4>
</div>
<img src="https://via.placeholder.com/200" height="970" alt="" id="eventcenterimg">
<div class="socialmedia">
<i class="fab fa-facebook-f"></i>
</div>
</div>
</body>
</html>

Related

Parallax effect only working on background image and not text

I'm currently following the tutorial on parallax effects on W3Schools. Basically, I have it so where the parallax is scrolling over my background correctly, but it's not scrolling over the text as well.
I tried a lot of things but it still doesn't work. I also saw one other post about this issue, but their code differed a lot from mine so it was hard to understand.
Here is the image of what is happening (the words are scrolling up with the page):
Here's my code:
*{
box-sizing: border-box;
}
body{
margin: 0px;
background-color: #ffffff;
}
ul{
text-align: center;
padding: 0px 20px;
margin: 12px auto;
list-style: none;
position: fixed;
z-index:10;
top: 0;
}
ul, li{
display: inline-table;
}
li{
margin: 10px 30px;
font-size: 15px;
color: #42385d;
font-weight: bold;
font-family: 'Roboto Slab', serif;
}
.navbar{
background-color: #ffcfda;
position: fixed;
width: 100%;
border-bottom: 1px solid #ffcfda;
z-index: 10;
height: 70px;
top: 0;
overflow: hidden;
}
#parallax{
background-image: url("pinkbackground.jpg");
min-height: 100vh;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
position: relative;
}
.transition{
height: 200px;
background-color: #42385d;
width: 100%;
}
.intro-text{
text-align: center;
width: 100%;
color: #42385d;
padding: 37vh;
height: 100vh;
width: 100%;
font-size: 50px;
font-family: 'Roboto Slab', serif;
position: relative;
background-attachment: initial;
}
.question{
font-size: 30px;
font-family: 'Roboto Mono', monospace;
color: #42385d;
font-weight: bolder;
padding-top: 40px;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>schpiel - Applying, Made Easier</title>
<!--meta data-->
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<meta name = "description" content =
"schpiel, like the name implies, makes applying easier.
no, it doesn't sound like that? :(. Using our new autofill
feature, with one click you can apply instantly!">
<!--styling-->
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght#1,300&family=Roboto+Slab&display=swap" rel="stylesheet">
<link rel="icon" href="https://i.imgur.com/RoPgdJh.jpg">
</head>
<body>
<div id="navigation">
<nav class="navbar";>
<ul>
<li>
<a>
Home
</a>
</li>
<li>
<a>
About
</a>
</li>
<li>
<a>
Contact
</a>
</li>
</ul>
</nav>
</div>
<div id="parallax">
<div class="intro-text">
text
<br>
here
</div>
</div>
<div class="transition"></div>
<section id="whatIsSchpiel">
<div class="question">
What is schpiel?
</div>
<div class="answer">
sscsdafads
</div>
</section>
</body>
<footer>
</footer>

Why is the search box not sticking to the right?

*{
margin: 0px;
padding: 0px;
}
.nav{
background-color:bisque;
width: 100%;
height: 60px;
display: flex;
align-items: center;
}
.b{
height: 60px;
width: 10%;
background-color: antiquewhite;
margin: 2px;
justify-content: center;
font-family: 'Anton', sans-serif;
border-radius: 20px;
align-items: center;
display: flex;
}
img{
width: 80px;
height: 60px;
}
#srch{
width: 10%;
height:60px;
display: inline-block;
float: right;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lost and Found</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
</head>
<body>
<div class="nav" >
<img src="img.png" alt="logo" srcset="">
<div class="b"><span>Electronincs</span></div>
<div class="b"><span>Plastics</span></div>
<div class="b"><span>Wearables</span></div>
<div class="b"><span>Others</span></div>
<input id="srch" type="search" value="Search">
</div>
</body>
</html>
The first code is Style.css while the 2nd code for Html file. Why is the search box not sticking to the right ? What mistake have i made ? I am not able to understand.The code is self explantory.
The searchbox has the id #srch. I am designing the nav bar and am a beginner.
Instead of going with this float approach you could do something like,
<div class="nav" >
<div class="nav-items">
<img src="img.png" alt="logo" srcset="">
<div class="b"><span>Electronincs</span></div>
<div class="b"><span>Plastics</span></div>
<div class="b"><span>Wearables</span></div>
<div class="b"><span>Others</span></div>
</div>
<input id="srch" type="search" value="Search">
</div>
.nav{
background-color:bisque;
width: 100%;
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
}
justify-content: space-between takes care of positioning the search box to the right and other items to the left.
Also note that, I added an extra div class "nav-items". It helps to separate other items with search box
Try to avoid float: right; and use instead of it a margin-left: auto; on the input.
You can put it into div for the better layout.
You can use right: 0; to move your search bar to the right.
#srch {
width: 10%;
height:60px;
/* these 2 lines should do the trick! */
right: 0;
position: absolute;
}

How to Put an image on top of the navbar

I need my image to be position: sticky but I need it on top of my navbar.
HTML5. this is for a school project I really need to get it done. please and thank you
<div>
<a href="index.html">
<img class="logo" src="./images/logo.png">
</a>
</div>
<nav> Home
Articles
Contact
Sources</nav>
CSS
nav{
background-color: black;
position: fixed;
text-align: center;
z-index: 10;
top: 3%;
left: 50%
width: 100%;
height:50px ;
transform: translate(-50%, -50%);
display: block;}
div{
transform: translate(-40%, 40%);
top: 3%;
z-index: 10;
overflow: hidden;}
try this and see if are what you want.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div>
<a href="index.html">
<img class="logo" src="./images/logo.png">
</a>
<nav>
<div>
<img src="https://www.history.com/.image/ar_4:3%2Cc_fill%2Ccs_srgb%2Cfl_progressive%2Cq_auto:good%2Cw_1200/MTU3ODc5MDg2NDMzNTEwNzI5/death-of-socrates.jpg"
alt="Your image" class="img">
</div>
Home
Articles
Contact
Sources
</nav>
</div>
</body>
</html>
CSS
nav {
background-color: black;
position: fixed;
text-align: center;
z-index: 10;
top: 3%;
left: 50%;
width: 100%;
height: auto;
transform: translate(-50%, -50%);
display: block;
}
div{
height: auto;
}
.img {
z-index: -1;
}

setting body width changes absolute positioning of div

I am having problem with positioning div. I have the following css
.popup{
display: none;
text-align: center;
background: #eee;
max-width: 200px;
font-size: 2em;
color: #ff0000;
position: absolute;
border-radius: 10px;
z-index: 2;
}
Here is the javascript:
$("#main").click(function(event){
$("#popup").css({'left':event.pageX, 'top':event.pageY, 'display':'block'});
});
here goes the HTML
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="shortcut icon" href="img/favicon-ksu.ico" type="image/x-icon">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/main2.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="h1">Something Goes arround here <span style="color: red;">Something More here</span></h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="helper" id="helper">
Click Here!
</div>
<div class="popup" id="popup">
oops! You clicked at wrong place. Try again!
</div>
<div class="workspace" id="workspace" contenteditable="true"></div>
<div id="main" class="main">
</div>
</div>
</div>
</div><!-- /container -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/main2.js"></script>
</body>
</html>
everything works fine up to here! But when i specify following,
body {
padding: 0px;
width: 1230px;
margin: 0 auto;
}
the div is not positioned at the place of click, div appears somewhere else. I am wondering what is wrong! If someone could help!!!
changing position to fixed from absolute solves this problem.
Instead of this:
.popup{
display: none;
text-align: center;
background: #eee;
max-width: 200px;
font-size: 2em;
color: #ff0000;
position: absolute;
border-radius: 10px;
z-index: 2;
}
use this:
.popup{
display: none;
text-align: center;
background: #eee;
max-width: 200px;
font-size: 2em;
color: #ff0000;
position: fixed;
border-radius: 10px;
z-index: 2;
}

Change body background image with css

So I am trying to change my background image, the problem is, as it is on my body, it is also changing on my other web page and I do not want it but I want to keep the same background image. Should I give an id/class to my body on my first page (where I want to hover function)?
<!DOCTYPE Html>
<head>
<meta charset="utf-8" />
<title>MakeHappy, One good thought everyday!</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="randomMessages.js"></script>
<link rel="stylesheet" href="MakeHappy.css" />
</head>
<div id="wink" class="imageSwap">
</div>
<body>
<header>
<nav>
<ul>
<a id="MakeHappy" href="Main.html">Make Happy</a>
<a id="Contact" href="#">Contact us</a>
<a id="Suscribe" href="#">Suscribe</a>
<a id="Project" href="#">Project</a>
</ul>
</nav>
</header>
</body>
\
<!DOCTYPE Html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="randomMessages.js"></script>
<title>MakeHappy, One good thought everyday!</title>
<link rel="stylesheet" href="MakeHappy.css" />
</head>
<body class="Main">
<input type="button" onclick="popup()" value="Click to be Happy!">
<div id="demo"></div>
</body>
\
body {
background-image: url("MakeHappy.jpg");
background-repeat: no-repeat;
background-position: 200px 60px;
background-size: 900px;
background-color: black;
}
body:hover{
background-image: url("MakeHappy2.jpg");
background-position: 200px 60px;
}
.Main{
background-size: 100px;
background-position:top;
}
.imageSwap{
position:absolute;
color: yellow;
padding: 150px;
bottom: 130px;
right: 500px
}
#MakeHappy{
color: white;
position: absolute;
right: 660px;
}
#Contact{
color: white;
position: absolute;
right: 660px;
bottom: 10px;
transform: rotate(180deg);
}
#Suscribe{
color: white;
position: absolute;
left: 320px;
bottom: 300px;
transform: rotate(270deg);
}
#Project{
color: white;
position: absolute;
right: 360px;
bottom: 300px;
transform: rotate(90deg);
}
.Main div{
color: white;
position: fixed;
}
input{
position: fixed;
bottom: 150px;
left: 625px;
}
You should give it a class with that specific background, if you only want the hover on lets say your startpage.
body {
background-image: url("MakeHappy.jpg");
background-repeat: no-repeat;
background-position: 200px 60px;
background-size: 900px;
background-color: black;
}
.startpage-background:hover{
background-image: url("MakeHappy2.jpg");
}
but your first html has errors, you shouldn't declare a div outside the body
Not valid html
<head>
<link rel="stylesheet" href="MakeHappy.css" />
</head>
<div id="wink" class="imageSwap">
</div>
<body>
</body>
But in general your html and css has not good practises and inconsistent code. I never use id to style a element, only classes. Also keep your classes and ids lowercase like some-class instead of SomeClass. Also I think you can avoid to absolute position your navigation elements.