/    Sign up×
Community /Pin to ProfileBookmark

CSS Beginner Project Need Help

So I’m trying to center my H1 near the top and my P right under the H1. However, when centering the P, the H1 gets pushed away.

Below´s the code.

[code]

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″ />
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″ />
<link
href=”https://fonts.googleapis.com/css?family=Oxanium&display=swap”
rel=”stylesheet”
/>
<link rel=”stylesheet” href=”style.css” />
<title>Document</title>
</head>
<body>
<div class=”container”>
<div class=”menu”>
<ul>
<li class=”logo”><img src=”./Img/crypto.png” alt=”” /></li>
<li class=”active”>Home</li>
<li>Services</li>
<li>Products</li>
<li>Contact</li>
<li>
<a href=”#” class=”signup-btn”><span>Sign Up</span></a>
</li>
</ul>
</div>
<div class=”background”>
<section id=”BackgroundText”>
<h1>
I will scam you! Send me your Credit card info
</h1>
<p>You wont belive how many scames we pulled off</p>
</section>

<img src=”./Img/rich.png” alt=”” />
</div>
</div>
</body>
</html>
[/code]

[code]

* {
margin: 0;
padding: 0;
font-family: “Oxanium”, cursive;
overflow: hidden;
}

.container {
position: relative;
width: 100vw;
height: 100vh;
background: #42455a;
z-index: -2;
}

.menu ul {
display: inline-flex;
margin: 50px;
}

.menu ul li {
list-style: none;
margin: 0 20px;
color: #b2b1b1;
cursor: pointer;
}

.logo,
img {
margin: -7px 48px 0 0;
width: 40px;
}

.active:active {
color: #19dafa !important;
}

.signup-btn {
position: absolute;
right: 100px;
text-decoration: none;
color: white;
border: 2px solid transparent;
border-radius: 20px;
background-image: linear-gradient(#42455a, #42455a),
radial-gradient(circle at top left, #fd00da, #19d7f8);
background-origin: border-box;
background-clip: content-box, border-box;
text-align: center;
}

.signup-btn span {
display: block;
padding: 8px 22px;
}

.background {
display: flex;
align-items: center;
justify-content: flex-end;
border: 2px solid blue;
width: 100vw;
height: 70vh;
background-image: radial-gradient(circle at top left, #fd00da, #19d7f8);
}

.background img {
position: absolute;
width: 450px;
opacity: 0.8;
z-index: 1;
}

#BackgroundText {
display: flex;
border: 2px solid black;
height: 100%;
width: 100%;
}

#BackgroundText,
h1 {
margin: auto;
border: 2px solid red;
text-align: center;
color: white;
z-index: 2;
text-transform: uppercase;
}

#BackgroundText,
p {
margin: 100px 10px auto;
text-align: center;
font-size: 1.5rem;
border: 2px solid orange;
color: white;
z-index: 2;
text-transform: uppercase;
}

[/code]

to post a comment
CSSHTML

3 Comments(s)

Copy linkTweet thisAlerts:
@tracknutMar 07.2020 — I didn't download and test your code, but this usage:
``<i>
</i>#BackgroundText,
h1 {<i>
</i>
``

and the same for the following for "p" is not what you think it is. The comma in there defines styling for *both* #BackgroundText and h1, not "any h1 inside #BackgroundText" as you want. Then a few lines later, you define a different style for #BackgroundText and p, overriding the first. What you want is "#BackgroundText h1" with no comma, and the same for the one for the paragraph.
Copy linkTweet thisAlerts:
@DevNedauthorMar 07.2020 — @tracknut#1615846 Managed to fix by doing a workaround. But thx for clarifying the difference between a comma and non-comma.
Copy linkTweet thisAlerts:
@siddhi_patelMar 27.2020 — Hello..

You can say you can put your <p> tag just under the h1 tag .just use two division for this two tag and after set margin and padding to get your position it is possible. After that you can set position and margin padding and style to that Division tag.by set position of your division .
×

Success!

Help @DevNed spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...