CSS - keeping card slide effect within rounded borders - html

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 */
}

Related

How do I make text in the middle of a sentence scroll?

I wanted to make a landing page for fun, and see how to make it look better, and I figured that I could make a sentence with spinning text in the middle. I've added a GIF to let you guys see what I want it to look like. I did see another post on here similar to mine, but the person that replied had it messed up slightly
I tried using CSS scrolling text, but that made the entire sentence start moving. I tried putting the beginning and end in different DIVs but then they were all seperated.
It needs to be independent element but you can inline-block it. Within this also overflow:hidden element will be a bigger element to be scrolled inside.
h1 {
display: flex;
height: 40px;
/* to center: */
justify-content: center;
}
.scroll-container {
text-align: center;
display: inline-block;
overflow: hidden;
position: relative;
height: 40px;
/* border: 1px solid red; */
margin-left: 10px;
margin-right: 10px;
}
.text-inside .item {
height: 40px;
}
.text-inside {
margin-top: 0;
transition: 500ms;
animation: 3s infinite test;
}
#keyframes test {
0% {
margin-top: 0;
}
25% {
margin-top: 0;
}
50% {
margin-top: -40px;
}
100% {
margin-top: -80px;
}
}
<div style="inline-block">
<h1>Welcome to
<div class="scroll-container">
<div class="text-inside">
<div class="item">Paris</div>
<div class="item">Frankfurt</div>
<div class="item">Milano</div>
</div>
</div>, Joshua
</h1>

Create underline after last line of text to fill white space

I'm having trouble with a SCSS/CSS styling idea, I want to fill the space before or after the last line of a heading with a solid line. The last line of text does not have a set width (it varies depending on screen size) I'm open to any suggestions.
Here's what I want to achieve when the text is aligned right or left.
|Here is some text on screen| |Here is some text on screen|
|very cool -----------------| or |----------------- very cool|
| | | |
| | | |
EDIT Code added for clarity:
HTML
<h1>You're the painter, we just want to see you paint.</h1>
CSS (that is how far I've got)
h1{
font-family: "doesntMatter";
font-style: bold;
font-size: 2rem;
text-align: left;
}
h1::after{
display: inline-block;
line-height: 0;
position: relative;
bottom: 2.5rem;
border-bottom: 10px solid red;
width: 100%;
content: "";
}
I found a solution to my problem, if you take this code here and run it, the last line will be struck through.
.container {
width: 100%;
padding-inline: 2rem;
}
.text {
font-style: bold;
font-size: 2.5rem;
line-height: 2.5rem;
position: relative;
overflow-x:hidden;
}
.text::after {
position: absolute;
left:0;
bottom: 0.9rem;
width: 100%;
border-bottom: 0.4rem solid #000;
content: "";
}
<section class="container">
<h1 class="text">You're the painter, we are just the paint, brushes and canvas</h1>
</section>
But if you remove left:0; from the text::after styling, it magically jumps over to fill the blank space at the end.
I added a margin-left: 1rem to give the things some breathing room but yea I really don't know what's going on.
I don't know how it works but it just kind of does, if the .text{} element has overflow-x: hidden applied to it then the effect will cutoff at the width of the header.
.container {
width: 100%;
padding-inline: 2rem;
}
.text {
font-style: bold;
font-size: 2.5rem;
line-height: 2.5rem;
position: relative;
overflow-x: hidden;
}
.text::after {
position: absolute;
bottom: 0.9rem;
width: 100%;
margin-left: 1rem;
border-bottom: 0.4rem solid #000;
content: "";
}
<section class="container">
<h1 class="text">You're the painter, we are just the paint, brushes and canvas</h1>
</section>
That is one way to do the effect, if you want the line to spill off the page, you apply overflow-x: hidden to the .container{} element and remove if from the .text{}... since my container is 100% width the line goes off the page and works as intended.
.container {
width: 100%;
padding-inline: 2rem;
overflow-x: hidden;
}
.text {
font-style: bold;
font-size: 2.5rem;
line-height: 2.5rem;
position: relative;
}
.text::after {
position: absolute;
bottom: 0.9rem;
width: 100%;
margin-left: 1rem;
border-bottom: 0.4rem solid #000;
content: "";
}
<section class="container">
<h1 class="text">You're the painter, we are just the paint, brushes and canvas</h1>
</section>
The line responds to any changes in the width of the last line. There's a few edge cases that I'm going to have to look into like if the last line of text practically fills the entire width of the header, then there's just a little nub at the end.
But it's been fixed! I hope this helps anyone in the future that couldn't figure out the right combination of words to google to find a solution.
Building on what you have already, this snippet puts the text within a span element. This enables a white padding which can overwrite that part of the red line which is under the actual text.
h1 {
font-family: "doesntMatter";
font-style: bold;
font-size: 2rem;
text-align: left;
position: relative;
}
h1>span::after {
display: inline-block;
position: absolute;
border-bottom: 10px solid red;
width: 100%;
left: 0;
margin-top: -11px;
content: "X";
color: transparent;
z-index: -1;
}
h1>span {
background: white;
padding-bottom: 11px;
}
<h1><span>You're the painter, we just want to see you paint.</span></h1>
Note - it's a little bit hacky, including positioning 1px different from the height of the line. This is because on modern screens which use more than one screen pixel for a CSS pixel the system can 'leave behind' traces of color when it is positioning (e.g. a screen pixel - not a whole CSS pixel).

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.

How can I position text and a image like this?

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;
}
}

Question about fixed-navbar + text-align right CSS/HTML

just starting out on my code journey and am hoping you can shed some light here. I just can't quite figure out how to adjust my code to reflect what I'm trying to do. I've tried to use float:right but then it seems to tamper with my ability to modify margins afterwards.
I've tried to adjust padding/margin/ text-align and can't seem to get my navbar text to the position that I want. What I want is to align it right,
and then offset it from the top where it is, and then to create space between the words for presentation. I'd like to keep it as a fixed navbar with the logo and text present during scrolling, at all times.
Here's a link to jsfiddle for an example, see below for my topnav CSS code.
https://jsfiddle.net/gbr403/t1u7q3wL/
.topnav {
background-color: black;
overflow: hidden;
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%;
height: 63px;
border-bottom: 1px solid seashell;
}
You can use flexbox to align items in navbar. See example below
body {
margin: 0;
}
.navbar,
.navbar--links {
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar {
background-color: #222;
padding: 13px 15px;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.navbar--logo {
width: 50px;
height: 50px;
}
.navbar--links a {
text-decoration: none;
color: #fff;
margin-left: 18px;
}
<nav class="navbar">
<img src="https://images.pexels.com/photos/258174/pexels-photo-258174.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" class="navbar--logo"/>
<div class="navbar--links">
Mission
Featured Tea
Locations
</div>
</nav>
Use css flex. The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure without using float or positioning.
body {
background-color: black;
}
.topnav {
background-color: black;
overflow: hidden;
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%;
height: 63px;
border-bottom: 1px solid seashell;
display: flex;
justify-content: space-between;
align-items:center;
}
.topnav a {
font-size: large;
font-family: sans-serif;
}
#img1 {
}
#logoid{
height: 50px;
width: 150px;
padding: 10px;
}
<body>
<header>
<div class="image1">
<img id="img1" src="">
</div>
<div class="topnav">
<div class="navlogo">
<img id="logoid" src="https://via.placeholder.com/150">
</div>
<div>
Mission
Featured Tea
Locations
</div>
</div>
</header>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>1111<br/><br/><br/><br/><br/><br/>2222
</body>