How can I position text and a image like this? - html

I'm a newbie and I have been struggling positioning text and Image as the pictures show below. If I use "relative" and "absolute" positioning the text container would position itself over the next content of the page. What would be the best way to make the layout like this?
Desktop Version
Mobile version
I did this while ago and if you open in it Firefox you should see what I'm aming for. Idk why it's not working on Chrome. (If you look at the mobile size, everything is like I want it to be)
https://helaris.github.io/lns/
and code is here: https://github.com/helaris/lns

You can use z-index.
You have to make the image upper.

Managed to get it like on the images above. Not sure If this is the easiest way or not but it works.
Codepen link
HTML -
> <div class="container">
<section class="welcome-section">
<div class="welcome-text-container">
<h1>Welcome to LNS</h1>
<p>We are priviliged to be able to teach you the Norwegian language,
and thereby open the doors to the society around you.
We aim to facilitate your transition to life here in Norway in a
smooth manner. A wise man once said:
Speak to a person in their language, and you speak to their heart.
We also pride ourselves in working on engaging and keeping you
involved in Stavanger life. We know that classroom courses will teach
you how to speak Norwegian, and we provide you just that!
<br>Welcome to class!</p>
</div>
<div>
<img src="images/welcome-image.jpg" alt="">
</div>
</section>
</div>
CSS:
> body {
background-color: #f5f5f5;
}
.container {
position: relative;
max-width: 1200px;
margin: 50px auto;
}
.container img {
position: relative;
width: 80%;
height: 100%;
right: -200px;
}
.welcome-text-container {
z-index: 1;
position: absolute;
max-width: 380px;
background-color: #fff;
line-height: 1.9;
text-align: left;
padding: 1rem;
bottom: 0;
}
.welcome-text-container h1 {
font-family: 'Frank Ruhl Libre', serif;
font-size: 2rem;
font-weight: 400;
padding: 1rem;
border-bottom: 1px solid #a8bfff;
}
.welcome-text-container p {
font-family: 'Montserrat', sans-serif;
padding: 40px 5px 10px 5px;
font-size: 16px;
}
#media screen and (max-width: 901px) {
.welcome-section {
display: flex;
flex-direction: column;
align-items: center;
}
.welcome-text-container {
position: relative;
order: 2;
bottom: 100px;
margin: 0px 15px;
max-width: 35rem;
}
.container img {
order: 1;
width: 100%;
position: initial;
}
.welcome-text-container p {
font-size: 0.9rem;
}
}

Related

CSS - keeping card slide effect within rounded borders

I am making a personal site about Boy Scout merit badges. I have a page with a background image where I put up a CSS grid containing cards, each of which is about a different badge. The card shows the badge emblem and has the title of the badge. When you hover over the card there is a sliding up of white text with a blue background that explains the badge. When you stop hovering, it slides back down.
The effect works for the most part, but there's one small problem. The cards have rounded borders, and when the blue slides down, at the very end of the slide down, the blue extends beyond the edges of the card. It is very distracting. It starts the slide up the same way, but for some reason it's more distracting on the way down than on the way up. Here's what it looks like at that end.
Here is my HTML:
<main class="main--grid-container">
<div class="mb-blocks center rounded-border wrapper">
<img class="mb-emblem" src="https://retailobjects.scoutshop.org/media/catalog/product/cache/15846fcd7c7438adaa15ad763c45b358/1/0/10504.jpg" alt="american heritage badge emblem">
<h4>American Heritage</h4>
<div class="overlay">
<div class="content">
<p>
Scouts learn about American history while working on the American Heritage
merit badge. Topics covered range from the Declaration of Interdependence,
to the history of the US flag, to historic places, to their own family
history. They also learn about careers related to the study of American
heritage.
</p>
</div>
</div>
</div>
</main>
Here is the CSS:
body {
background-color: lightgreen;
}
.mb-emblem {
height: 150px;
}
.main--grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 25px;
padding-left: 25px;
padding-right: 25px;
}
.center {
text-align: center;
}
.rounded-border {
border-radius: 25px;
}
.mb-blocks {
padding: 25px;
background-color: white;
z-index: 2;
}
h4 {
font-size: 24px;
margin: 0;
}
.wrapper {
position: relative;
}
.content {
color: #fff;
font-size: 1em;
padding: 1em;
}
.content span {
font-size: .75em;
display: block;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #003366;
border-radius: 25px;
width: 100%;
height: 0;
transition: .5s ease;
overflow: hidden;
margin: 0;
}
.wrapper:hover .overlay {
height: 100%;
}
I changed the background-image to a background-color and put it in a CodePen to make it easier to see. Here is the CodePen.
Thanks for the help!
All you need to do is add overflow: hidden to the mb-blocks class.
Like this:
.mb-blocks {
padding: 25px;
background-color: white;
z-index: 2;
overflow: hidden;
}
replace this style code to fix the problem.
.mb-blocks {
padding: 25px;
background-color: white;
z-index: 2;
overflow: hidden; /* This is the important part */
}

How to overlap HTML block level element over another HTML block level element while retaining responsive behaviour across screen sizes

I am trying to replicate the behaviour of a piece of HTML and CSS content that appears on the website i have provided a link to below. The website in question is www.air-it.co.uk.
I have included below a mockup image, which indicates the layout that i want to achieve.
I do not know how else other than to link to the working version on the website below to visualise this for users reading this question, because i do not know how to solve the problem i am trying to address with this question using HTML and CSS.
The example of this can be seen roughly 1/3 of the way down the following page.
www.air-it.co.uk
Essentially, it appears to be be positioning one div on the left over another div on the right within a container. It appears to be leveraging a 'card content' element which is placed over another div containing a background image.
I could possibly do this at one screen size using absolute positioning, i think. But i need it to behave responsively in a similar way (or the same way) as the example above?
I am aware that the above example uses Foundation. But my question would be is there an inbuilt way to do this using Bootstrap?
I would imagine the alternative here is to customise CSS for different media queries in order to do this, which unfortunately i don't know how to do.
Please do not simply close this question again if you would like to take umbrage with my syntax or question structure. Kindly post your feedback or criticism in a comment which will allow me to revise this question as opposed to simply closing the question with no additional clues or feedback as to why you have chosen to do so.
Thank you.
maybe this can help, try to open in full view
body {
font-family: Roboto;
margin: 0;
}
.overlap-section {
min-height: 450px;
background-color: #fff;
display: inline-block;
float: left;
width: 45%;
border: 1px solid #ff5722;
padding: 50px;
position: absolute;
z-index: 99;
top: 50%;
transform: translateY(-50%);
left: 5%;
}
.main-box {
background-color: lightgray;
height: 100%;
width: 75%;
float: right;
position: relative;
}
.main-section {
height: 100vh;
position: relative;
}
.text-wrapper {
display: inline-block;
position: absolute;
top: 50%;
right: 26%;
transform: translate(50%, -50%);
}
.text-wrapper h2 {
display: inline-flex;
margin: 0;
text-transform: uppercase;
line-height: 42px;
color: #fff;
font-weight: bold;
}
.overlap-section h3 {
text-transform: uppercase;
font-weight: bold;
font-size: 30px;
padding-bottom: 25px;
}
.overlap-section label {
font-size: 25px;
display: block;
}
.overlap-section span {
font-size: 16px;
padding: 18px 0;
display: block;
}
.button-wrapper {
margin: 0 auto;
display: table;
padding-top: 52px;
}
.button-wrapper .custom-btn {
color: #fff;
background-color: #ff5722;
padding: 14px 35px;
border: 0;
font-size: 19px;
}
<div class="main-section">
<div class="overlap-section">
<h3>Header text is here</h3>
<label>More header text here</label>
<span>List item</span>
<div class="button-wrapper">
<button class="btn-default custom-btn" type="button">Call to action here</button>
</div>
</div>
<div class="main-box">
<div class="text-wrapper">
<h2>This Grey Element</h2><br>
<h2>Will contain an image</h2>
</div>
</div>
</div>

How can I make this CSS card responsive?

Edit: here is a CodePen with CSS / HTML
I spend the weekend creating a CSS card for a website, only to realize that it's not responsive, at all. I'm not very well versed in CSS or responsive design, so I am hoping someone with more experience can help me out. So far, I've tried playing around with the #media tag, but I have not had any success. This is the relevant CSS:
#import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
background: #ffffff;
font-family: 'Muli', sans-serif;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
.courses-container {
}
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
display: flex;
max-width: 100%;
margin: 20px;
overflow: hidden;
width: 1300px;
}
.course h6 {
opacity: 0.6;
margin: 0;
letter-spacing: 1px;
text-transform: uppercase;
}
.course h2 {
letter-spacing: 1px;
margin: 10px 0;
}
.course-preview {
background-color: #2a265f;
color: #fff;
padding: 30px;
max-width: 250px;
}
.course-preview a {
color: #fff;
display: inline-block;
font-size: 12px;
opacity: 0.6;
margin-top: 30px;
text-decoration: none;
}
.course-info {
padding: 30px;
position: relative;
width: 100%;
}
.right-container {
padding: 30px;
background-color: #fff;
width: 30%;
line-height: 200%;
}
.progress-container {
position: absolute;
top: 30px;
right: 30px;
text-align: right;
width: 150px;
}
.progress {
background-color: #ddd;
border-radius: 3px;
height: 5px;
width: 100%;
}
.progress::after {
border-radius: 3px;
background-color: #2a265f;
content: '';
position: absolute;
top: 0;
left: 0;
height: 5px;
width: 10%;
}
.progress-text {
font-size: 10px;
opacity: 0.6;
letter-spacing: 1px;
}
This is a simple suggestion, using CSS Grid. It's a two column card (as yours): the left column width-fixed (300px), the right column width-fluid. I've applied a little gap between them just to make my example clearer.
.card {
max-width: 1000px;
display: grid;
grid-template: "left right" / 300px 1fr;
background-color: #fed330;
border-radius: 10px;
height: 300px;
}
.card>* {
padding: 20px;
}
.left {
grid-area: left;
}
.right {
grid-area: right;
}
#media screen and (max-width: 700px) {
.card {
grid-template: "left" "right" / 100%;
}
}
<div class="card">
<div class="left">
Lorem ipsum....
</div>
<div class="right">
Lorem ipsum...
</div>
</div>
It could be a useful starting point.
#gaston
A good way to test and learn about CSS is to use the browser's "Inspect" feature, with which you can test the css behavior in real time.
Activating, Deactivating features, changing values, and adding new ones.
You see the result in real time.
Then just adjust your code according to your tests.
Just right-click on the area you want to inspect. and then Inspect.
You will see an area with HTML and another with CSS.
Click on the areas in HTML and see the corresponding css.
***** Then just test to find the desired result.
That's how I found the solution in your code:
In the ".course" class of your css you added the "width" property twice.
"max-width: 100%;"
"width: 1000px;"
However, the last property entered has priority over the previous ones.
"width: 1000px;" is defining that your card will ALWAYS have 1000px.
SOLUTION:
Just remove: "max-width: 100%;"
And Modify "width: 1000px;" for "max-width: 1000px;"
So your card will have a maximum of 1000px, the minimum will be defined according to the width of the window
It will look like this:
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba (0, 0, 0, 0.2);
display: flex;
margin: 20px;
overflow: hidden;
max-width: 1000px;
}
The #media function will set the css when the screen is adjusted to a minimum or maximum width chosen by you.
What is defined within #media will have priority over other css. but only when the window meets the width you set.
You can use this to change the shape of your card completely to very small screens, placing the purple part on top of the card for example.
If you've solved your problem, mark the right answer to help others.
Good luck.

I can't figure out how to place the words for each div element in the middle of each side using CSS and HTML

Just like the title says, I'm trying to create a rough layout for a website and I want to not only center the words on each side like they already are, but also have them in the middle. When I use transform and put the words in the middle of the page, the h1 element doesn't move but then the p element keeps going down the page rather than adjusting it with every new row. Any tips?
<div class="left-side" >
<h1>Welcome.</h1>
<p>I want to welcome you!</p>
</div>
<div class="right-side">
<h1>Corey Michaud.</h1>
<p>Corey is my name :)</p>
</div>
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
}
body {
text-align: center;
overflow: hidden;
font-family: 'Rubik', sans-serif;
}
.left-side {
background: white;
width: 50%;
height: 100%;
left: 0;
color: black;
position: absolute;
}
.right-side {
background: black;
width: 50%;
height: 100%;
right: 0;
color: white;
position: absolute;
}
h1 {
font-size: 72px;
font-weight: 700;
}
p {
font-size: 48px;
font-weight: 300;
}
You want to use css flexbox. Add
.left-side, .right-side{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
Hopefully this is helpful!

How to align a h2 with a div side by side without colapsing when window changes size?

I have been trying to align two elements, a h2 and a div side by side without having one of them colapse when the window changes to a smaller size. I've searched the web a bit but found nothing similar that would help and my solutions just wouldn't work so I though here there would be someone able to help me.
So I want it to be displayed like this at all times:
https://imagizer.imageshack.us/v2/912x135q90/631/ZYR7sc.png (Can't post images sorry!)
But when window size changes dispite the fact the div should adapt at some point it just breaks to next line:
https://imagizer.imageshack.us/v2/730x144q90/912/yRBpkc.png
Here is my code on this one:
HTML
<div id='pagetitle'>
<h2 id='subtitle'>Weapons</h2>
<div id='hline'></div>
</div>
CSS
#pagetitle { /* This div is for centering both of the elements. */
width: 90%;
margin: 0 auto;
display: block;
}
#subtitle {
display: inline-block;
color: #72c9b9;
font-size: 30px;
font-weight: 300;
text-align: center;
}
#hline {
display: inline-block;
background-color: #72c9b9;
width: 70%;
height: 1px;
position: relative;
bottom: 4px;
margin-left: 20px;
}
So this is it guys, any sugestions? Thanks in advance.
cs.almeida
Here's a way how to do it:
demo
<div id='pagetitle'>
<h2 id='subtitle'><span>Weapons</span></h2>
</div>
#pagetitle {
width: 90%;
margin: 0 auto;
display: block;
}
#subtitle {
border-bottom: #72c9b9 solid 2px;
height: 18px;
display: block;
color: #72c9b9;
font-size: 30px;
font-weight: 300;
}
#subtitle > span {
background-color: white;
padding: 10px 20px;
}