Aligning Two Block Elements Horizontally Rather Than Manually Using "Position" [duplicate] - html

This question already exists:
Is Inline Block Not Working Because Margins Are Set? [duplicate]
Closed 2 years ago.
I have a header and a "p" element that I want on one horizontal line. I've managed to obtain the desired result manually using CSS "position" function, but I would like to learn the proper way to do this so that both elements are mathematically aligned for future reference. I want the middle of each element to be on the same horizontal line, as one element has more height than the other. I tried using "display: inline-block" and that didn't work, perhaps because I have different margins set for each element but I'm not sure.
HTML:
<div class="head-one">
<h2 id="#about-me">About Me</h2>
<p id="cal">My name is Cal Cook. I'm 26 years old and live in Boston, Massachusetts. I'm from NYC originally. I'm passionate about cryptocurrency, web design and SEO. I built this site to feature my work.</p>
</div>
CSS:
h2 {
padding: 75px;
margin-left: 30px;
font-family: 'Nunito Sans', sans-serif;
}
#cal {
font-family: 'Roboto', sans-serif;
border: solid;
border-radius: 25px;
padding: 10px;
margin-left: 350px;
margin-right: 250px;
position: relative;
bottom: 140px;
}

It's a perfect situation (like almost every other) for CSS_layout/Flexbox
.head-one {
display: flex;
align-items: center;
justify-content: space-around;
}
#cal {
max-width: 60vw;
border: solid;
border-radius: 25px;
padding: 10px;
}
<div class="head-one">
<h2 id="#about-me">About Me</h2>
<p id="cal">My name is Cal Cook. I'm 26 years old and live in Boston, Massachusetts. I'm from NYC originally. I'm passionate about cryptocurrency, web design and SEO. I built this site to feature my work.</p>
</div>
CSS_layout/Flexbox

I would suggest removing all of your positing code. Use display: flex on the container and flex: 1 on the #cal element.
.head-one {
display: flex;
align-items: center;
}
h2 {
font-family: 'Nunito Sans', sans-serif;
white-space: no-wrap;
padding: 75px;
}
#cal {
font-family: 'Roboto', sans-serif;
border: solid;
border-radius: 25px;
padding: 10px;
flex: 1;
}
<div class="head-one">
<h2 id="#about-me">About Me</h2>
<p id="cal">My name is Cal Cook. I'm 26 years old and live in Boston, Massachusetts. I'm from NYC originally. I'm passionate about cryptocurrency, web design and SEO. I built this site to feature my work.</p>
</div>

Related

Center text with white-space: nowrap;

I'm trying to center my title so I used white-space: nowrap; so it didn't stack and it appeared in one line but now it won't center. So there is the CSS code for the title and the appearance of it is fine, the only problem is that, instead of appearing centered, it starts from the center, and it keeps going right. So like, instead of " Meet The Seekers ", it does " Meet the Seekers"
My code snippet is:
.section-title {
font-size: 4rem;
font-weight: 300;
color: black;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 0.2rem;
clear: both;
display: inline-block;
overflow: hidden;
white-space: nowrap;
justify-content: center;
}
<div class="about-top">
<h1 class="section-title">Meet the <span>SEE</span>kers</h1>
<p>We are a team of young entrepreneurs, who decided it was time to modernize the way we search the web. A diverse group of unexpected talents came together to make SEE-Tool available to every web user.</p>
</div>
I'm not sure why you have justify-content: center in your code as it does not do anything there. You also don't need inline-block as span tag is not block element.
You may remove the display property and add text-align: center, so it will be centering your h1 tag.
.section-title {
font-size: 4rem;
font-weight: 300;
color: black;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 0.2rem;
text-align: center;
}
<div class="about-top">
<h1 class="section-title">Meet the <span>SEE</span>kers</h1>
<p>We are a team of young entrepreneurs, who decided it was time to modernize the way we search the web. A diverse group of unexpected talents came together to make SEE-Tool available to every web user.</p>
</div>
just use text-align:center
.section-title {
font-weight: 300;
color: black;
margin:0 auto;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 0.2rem;
text-align:center;
}
<div class="about-top">
<h1 class="section-title">Meet the <span>SEE</span>kers</h1>
<p>We are a team of young entrepreneurs, who decided it was
time to modernize the way we search the web. A diverse group
of unexpected talents came together to make SEE-Tool available
to every web user.</p>
</div>

some parts of my site are not responsive how do i fix it?

i'm new and after finishing my site i realized the parts i created are not responsive is there a way to fix it without starting from scratch?
herer is my css, i tried to add media query and put the width to 100% but it didn't help the problem.
.main_content {
display: flex;
justify-content: center;
}
.main_content h1 {
margin-top: 80px;
display: inline-block;
width: 50vw;
text-align: center;
font-family: "henny penny";
color: #995932;
}
.main_content p {
margin-top: 10px;
display: inline-block;
font-family: "roboto";
color: #995932;
background-color: #fdc8a8;
width: 50vw;
height: 50vh;
padding: 30px 30px;
text-align: justify;
line-height: 4.5vh;
box-shadow: 8px 15px rgba(0, 0, 0, 0.2);
}
.sub_content {
display: flex;
justify-content: center;
align-items: center;
margin-top: 30px;
margin-bottom: 50px;
}
.sub_content div {
width: 40vw;
margin: 20px;
}
.sub_content h2 {
text-align: center;
font-family: "henny penny";
color: #9c9c27;
}
.sub_content p {
text-align: justify;
font-family: "roboto";
color: #aaaa36;
padding: 40px 40px;
background-color: #ffff99;
line-height: 3.5vh;
box-shadow: 8px 15px rgba(0, 0, 0, 0.2);
}
.mayor_content h2 {
margin-top: 30px;
margin-bottom: 20px;
text-align: center;
font-family: "henny penny";
color: #5a873b;
}
.mayor_content div {
margin: 0 auto;
width: 80vw;
height: 80vh;
text-align: center;
background-color: #b6db9d;
box-shadow: 8px 15px rgba(0, 0, 0, 0.2);
}
.mayor_content div h3 {
margin-bottom: 20px;
font-family: "henny penny";
color: #5a873b;
}
.mayor_content div p {
display: inline-block;
text-align: justify;
width: 35vw;
height: 20vh;
color: #547c39;
}
.mayor_content img {
width: 150px;
height: 200px;
position: relative;
bottom: 300px;
left: 570px;
image-rendering: crisp-edges;
}
the html seems organized but if i could order it more then i would be happy to.
<main>
<section>
<div class="main_content">
<div>
<h1>Mardi Gras in New Orleans</h1>
<p>The holiday of Mardi Gras is celebrated in all of Louisiana, including the city of
New
Orleans.
Celebrations
are
concentrated for about two weeks before and through Shrove Tuesday, the day before Ash Wednesday
(the
start
of
lent in the Western Christian tradition). Usually there is one major parade each day (weather
permitting);
many
days have several large parades. The largest and most elaborate parades take place the last five
days of
the
Mardi Gras season. In the final week, many events occur throughout New Orleans and surrounding
communities,
including parades and balls </p>
</div>
</div>
<div class="sub_content">
<div>
<h2>Traditional colors</h2>
<p>The colors traditionally associated with Mardi Gras in New Orleans are green, gold,
and
purple. The
colors
were first specified in proclamations by the Rex organization during the lead-up to their
inaugural
parade
in 1872, suggesting that balconies be draped in banners of these colors. It is unknown why these
specific
colors were chosen; some accounts suggest that they were initially selected solely on their
aesthetic
appeal, as opposed to any true symbolism.</p>
</div>
<div>
<h2>Costumes and masks</h2>
<p>In New Orleans, costumes and masks are seldom publicly worn by non-Krewe members on
the
days before Fat
Tuesday (other than at parties), but are frequently worn on Mardi Gras. Laws against concealing
one's
identity with a mask are suspended for the day. Banks are closed, and some businesses and other
places
with
security concerns (such as convenience stores) post signs asking people to remove their masks
before
entering.</p>
</div>
</div>
</section>
<div class="break_point2"></div>
<section class="mayor_content">
<h2>Mayor of New Orleans</h2>
<div>
<h3>LaToya Cantrell</h3>
<p>LaToya Cantrell born April 3, 1972 is an American politician serving as the Mayor of New
Orleans, Louisiana, a post she has held since May 7, 2018. A Democrat, Cantrell is the first woman
to
hold the post. Before becoming mayor, Cantrell represented District B on the New Orleans City
Council
from 2012–2018.</p>
</div>
<img src="./images/mayor.jpeg" alt="LaToya Cantrell">
</section>
</main>
Because you are using vw in certain places, this unit takes a fixed percentage of browser size of 50vw mean 500px of 1000px screen and 50px of 100px screen, I would suggest to use rem instead also, you can go a bit advanced and use css clamp() to fix width of multiple screen at once.

How would I add a second line to a <div> and make it have a different font size?

I'm currently working on a simple COVID-19 site where some info gathered from some flask code is shown in s, with some CSS making the backgrounds into white boxes. However, I am not completely sure how I can add a "cases" right underneath the number while still being in the box. I'm sorry if my question is slightly unclear. I will show my code below.
HTML I am attempting to use:
<div class="boxed">{{data}}</div>
<div><p>cases</p></div>
CSS I am attempting to use:
.boxed {
font-size: 800%;
width: 700px;
text-align: center;
padding: 80px;
background: whitesmoke;
font-family: 'Ubuntu', Helvetica, Arial, sans-serif;
font-weight: bold;
color: rgb(49,74,128);
margin: 2% auto;
border-radius: 60px;
}
Right now, the "cases" text shows under the box with the number in it, instead of being inside of it.
I apologize if it is kind of a bad or simple question- I am a beginner in making websites. Any help would be greatly appreciated!
Just move the p tag inside div.boxed and add separate CSS for title and cases
.boxed {
font-size: 800%;
width: 700px;
text-align: center;
padding: 80px;
background: whitesmoke;
color: rgb(49,74,128);
margin: 2% auto;
border-radius: 60px;
}
.title {
font-family: 'Ubuntu', Helvetica, Arial, sans-serif;
font-weight: bold;
}
.body {
/* your body styling */
}
<div class="boxed">
<div class="title">{{data}}</div>
<p class="body">cases</p>
</div>
You can move <p>cases</p> inside your .boxed div.
<div class="boxed">
{{data}}
<p>cases</p>
</div>
Then add the styling below to your css.
.boxed p {
font-size: 32px;
}
Testing: https://jsfiddle.net/z3acqfjg/1/

Flex Layout Not Working as Intended With ngFor Loop

I searched but couldn't find a question quite like mine. Apologies if there's an answer somewhere.
I'm attempting to do a very simple flex layout in row format where 2 containers are side by side. I have a card component with an ngFor loop inside another component. Here's my code:
top-cta-HTML:
<section id="cta-container">
<h1>Take Control of Your Financial Future</h1>
<h4>
Whether you’re looking at annuities to guarantee future income, <br />save
for a life change, or selling your structured settlement,<br />
we’re here to help with guidance, advice, and experience
</h4>
<app-cta-card></app-cta-card>
</section>
top-cta-CSS:
#cta-container {
margin: 2.5rem 0 0 auto;
padding: 0 20px 0 5px;
background-color: orange;
width: 35%;
border-bottom-left-radius: 60px;
text-align: end;
}
#cta-container h1 {
font-size: 2.75rem;
font-weight: 900;
}
#cta-container h4 {
margin-top: -20px;
font-size: 1.2rem;
font-weight: 500;
line-height: 1.5em;
}
card-HTML:
<article id="card-parent-container">
<div class="top-cta-card" *ngFor="let card of ctaCards">
<div class="cta-card-topper">1</div>
<h3>{{ card.title }}</h3>
➔
<p>{{ card.description }}</p>
</div>
</article>
card-CSS:
.top-cta-card {
background-color: var(--cream);
width: 300px;
}
#card-parent-container {
display: flex;
flex-direction: column;
}
.cta-card-topper {
background-color: var(--teal);
height: 100%;
width: 100%;
color: var(--teal);
}
.top-cta-links {
background-color: var(--teal);
color: var(--cream);
padding: 5px 6px;
border-radius: 50%;
box-shadow: 3px 2px 3px var(--gunMetal50);
}
This code produces 2 cards stacked on top of each other and no matter what I change they won't sit in row format.
As a test, I made 2 divs inside the top-cta-HTML file with no ngFor loop and got the desired result. Any ideas here on what I'm doing wrong?
Thank you for any and all help, I really appreciate it!
So the issue was that my flex code was one layer too deep. I ended up putting the flex code on app-cta-card it the flex works as intended.
Here's the Stack Blitz code:
https://stackblitz.com/edit/angular-6oxcmy

HTML/CSS - Increased Font-Size Shifts Everything on Page to Left

I'm building a site as a learning exercise. It's aim is to showcase some stories, so the readability of the text is quite important.
For the Home, About and similar pages, the layout I have is fine. However, on the pages with a story on, after I increase the font-size to 1.2rem or above, the paragraphs seem to move everything on the page to the left relative to the position of everything on the other pages.
I've set the widths for all of the containers but it doesn't seem to be making a difference.
I've tried isolating the problem and only the font size makes any difference. If I set it lower than 1.2rem it shifts back to its correct position.
The HTML for one of the story pages and the story pages CSS file are below. Any bootstrap terms are just terms I've adopted, they're not using any Bootstrap styling. Trying to build this from the ground up.
Apologies if this is obvious or any of the below is badly formatted / badly written.
Appreciate any help.
Thank you!
/* Fonts */
/* Montserrat and Raleway */
#import url('https://fonts.googleapis.com/css?family=Montserrat|Raleway');
/* Reset */
* {
box-sizing: border-box;
}
html {
font-size: 16px;
font-family: 'Raleway', sans-serif;
}
/* Components */
.container {
width: 66%;
margin: 0 auto;
}
.jumbotron {
background-color: #ededed;
padding: 6% 10%;
margin: 20px;
}
.jumbotron-header {
font-size: 2rem;
font-family: 'Montserrat', sans-serif;
}
/*block size and height, margins left and right slightly*/
.story-text {
font-size: 1.5rem;
line-height: 1.5;
margin: 20px;
width: 100%;
}
.story-text > p {
width: 100%;
}
.story-subtitle {
font-size: 2rem;
font-weight: 600;
font-family: 'Montserrat', sans-serif;
}
.quote-block {
margin: 50px 300px;
}
.quote {
font-style: italic;
}
.quote-attribution {
font-weight: 700;
}
/* General Styling */
a {
text-decoration: none;
color: black;
}
/* Navigation */
/* Layout */
.nav-area {
display:flex;
height: 40px;
background-color: #ededed;
align-items: center;
}
.nav-links {
display: flex;
flex-grow: 10;
align-items: center;
}
.logo-area {
display: flex;
flex-grow: 1;
justify-content: space-around;
align-items: center;
background-color: #bcbcbc;
height: inherit;
}
/* Styling */
#logo {
font-size: 20px;
font-weight: bold;
}
.nav-links > div {
height: 40px;
line-height: 40px;
}
.nav-links span {
font-size: 20px;
margin: 20px;
line-height: normal;
vertical-align: middle;
}
.nav-links > div:hover {
background-color: #ffffff;
}
/* Mobile */
/* Burger Menu */
.mobile-nav {
display: none;
}
.mobile-menu {
display: none;
}
.mobile-menu > div {
background-color: #ededed;
border: 1px solid #e5e5e5;
padding: 5%;
}
.mobile-menu > div:hover {
background-color: #cecece;
}
/* Navigation */
#media screen and (max-width: 826px) {
.nav-area {
height: auto;
}
.logo-area {
padding: 5%;
}
}
#media screen and (max-width: 700px) {
.nav-links {
display: none;
}
.mobile-nav {
display: block;
margin: 20px;
}
}
#media screen and (max-width: 740px) {
.jumbotron-header {
font-size: 1rem;
}
.story-text {
font-size: 1rem;
}
.story-subtitle {
font-size: 1.2rem;
}
}
<body>
<!-- Navbar -->
<header>
<div class="nav-area container">
<div class="logo-area">
<span id="logo">The Lovecraft Project</span>
</div>
<div class="nav-links">
<div><span>Home</span></div>
<div><span>About</span></div>
<div><span>Stories</span></div>
</div>
<!-- Burger Menu -->
<i class="mobile-nav fas fa-bars"></i>
</div>
</header>
<div class="container">
<!-- Mobile Menu -->
<div class="mobile-menu">
<div>Home</div>
<div>About</div>
<div>Stories</div>
</div>
</div>
<!-- Content -->
<div class="container">
<div class="jumbotron">
<div class="jumbotron-header">
<h1>The Shadow Over Innsmouth</h1>
<hr>
<p>H.P. Lovecraft</p>
</div>
</div>
<div class="story-text">
<p class="story-subtitle">I.</p>
<p>During the winter of 1927–28 officials of the Federal government made a strange and secret investigation of certain conditions in the ancient Massachusetts seaport of Innsmouth. The public first learned of it in February, when a vast series of raids and arrests occurred, followed by the deliberate burning and dynamiting—under suitable precautions—of an enormous number of crumbling, worm-eaten, and supposedly empty houses along the abandoned waterfront. Uninquiring souls let this occurrence pass as one of the major clashes in a spasmodic war on liquor.</p>
<p>Keener news-followers, however, wondered at the prodigious number of arrests, the abnormally large force of men used in making them, and the secrecy surrounding the disposal of the prisoners. No trials, or even definite charges, were reported; nor were any of the captives seen thereafter in the regular gaols of the nation. There were vague statements about disease and concentration camps, and later about dispersal in various naval and military prisons, but nothing positive ever developed. Innsmouth itself was left almost depopulated, and is even now only beginning to shew signs of a sluggishly revived existence.</p>
<p>Complaints from many liberal organisations were met with long confidential discussions, and representatives were taken on trips to certain camps and prisons. As a result, these societies became surprisingly passive and reticent. Newspaper men were harder to manage, but seemed largely to coöperate with the government in the end. Only one paper—a tabloid always discounted because of its wild policy—mentioned the deep-diving submarine that discharged torpedoes downward in the marine abyss just beyond Devil Reef. That item, gathered by chance in a haunt of sailors, seemed indeed rather far-fetched; since the low, black reef lies a full mile and a half out from Innsmouth Harbour.</p>
<p>People around the country and in the nearby towns muttered a great deal among themselves, but said very little to the outer world. They had talked about dying and half-deserted Innsmouth for nearly a century, and nothing new could be wilder or more hideous than what they had whispered and hinted years before. Many things had taught them secretiveness, and there was now no need to exert pressure on them. Besides, they really knew very little; for wide salt marshes, desolate and unpeopled, keep neighbours off from Innsmouth on the landward side.</p>
<p>But at last I am going to defy the ban on speech about this thing. Results, I am certain, are so thorough that no public harm save a shock of repulsion could ever accrue from a hinting of what was found by those horrified raiders at Innsmouth. Besides, what was found might possibly have more than one explanation. I do not know just how much of the whole tale has been told even to me, and I have many reasons for not wishing to probe deeper. For my contact with this affair has been closer than that of any other layman, and I have carried away impressions which are yet to drive me to drastic measures.</p>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="../Resources/Scripts/script.js"></script>
</body>
I guess the problem is, whenever you are increasing the font-size it is aligning itself accordingly inside the fixed width that you have provided. So, in order to get the desired layout every time use percentages rather than fixed values.