I have tried every solution I could find on the web on this subject. I have come to the conclusion that the problem may be that my page contains a scroll-snap-type.
scroll-snap-type: y mandatory;
scroll-behavior: smooth;
This is an overview of the div that I would like to scroll horizontally.
<section id="work">
<h2>WORK</h2>
<div id="carrousel">
<div class==="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Velit rerum voluptas iusto ipsam officiis
earum atque unde nesciunt provident ullam rem ea tempore.</h4>
</div>
<div class="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem Ipsum<h4>
</div>
<div class="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem Ipsum</h4>
</div>
<div class="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem Ipsum</h4>
</div>
</div>
</section>
#carrousel {
display: flex;
flex-direction: row;
height: 70vh;
width: 100vw;
}
#work {
background-color: #0F0F0F;
color: white;
display: flex;
flex-flow: column;
justify-content: center;
}
If I understand you correctly, to fix your issue, you can simply in your CSS (stylesheet) type the following code:
#carrouse1 {
overflow-x: auto;
}
...and do the same thing if you have more than one
If you want to make another section be horizontally scrolled, then just use the same CSS property on that too!
Related
I have a big "img" background image that is put inside the "Figure" tag as the main background of the site. I set the max-width to 100% and the height to 100% too.
When I start scrolling from the top of my page to the bottom.
As soon as I reach the beginning/top of an image, the scroll stops, then I need to scroll again to reach the bottom of the page. Same as when I scroll from bottom to up. This problem is happening on the touchpad scroll and the keyboard up and down arrows.
I noticed that whether scrolling from top to bottom or bottom to up of the image, the vertical scroll bar doesn't move; it starts moving when I have to scroll again up or down of the site.
However, the following steps are done.
The scrolling worked smoothly when I reduced the "Height" of the img exactly below "86%" in the CSS file. However, "86% - 100%" the problem starts there.
I tried to use the "img" tag, then I replaced it with the "Background-Image: url()" property. Same problem with step one.
I tried to reduce (compress) the image size. Same problem with step one.
I used the "Background-size" with the different values (contain, cover, auto). Same problem with step one.
I used "Background-Attachment: Scroll;" the Same problem as step one.
Updated: I added "P" with a lot of lorem text under the image so that I can scroll enough. The scrolling problem was solved even though the height of the image is "Height: 100%", whether it's "img tag" or "Background-Image: url()"
Thus, the main problem is with the height, but I need the image to be "100%" not below "86%".
Any suggestions, please?
<body>
--Hidden Content--
<!------------------
----MAIN CONTENT----
-------------------->
<main>
<section class="upperpart">
<header class="main_header">
<div class="getoff">
<h2>get rm10 off</h2>
<p>your first order
<span>code:shemya</span>
</p>
</div>
<div class="share">
<h2>share & earn</h2>
<p>up to 15% off</p>
</div>
<div>
<h2>cash on delivery</h2>
</div>
</header>
<figure class="main_figure">
<img src="https://www.lux-review.com/wp-
content/uploads/2022/05/Kids-Fashion.jpg" alt=""
height="85%">
<figcaption></figcaption>
<img src="" alt="">
<div class="figure_ads">
<p>mega year end sale now on</p>
<p>up to <span>80%</span>off</p>
<button>buy now</button>
</div>
</figure>
<section class="middelpart">
--Hidden Content--
</section>
<section class="bottompart">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing
elit. Reprehenderit fugit earum accusantium non
amet
.</p>
</section>
</main>
main {
width: 100vw;
min-height: 100vh;
margin-top: 15.2rem;
}
main .upperpart {
background-color: antiquewhite;
height: 80rem;
width: 90vw;
margin: 0 auto;
/* visibility: hidden; */
}
.upperpart .main_figure {
width: 90vw;
/* max-height: 60rem; */
position: relative;
}
.upperpart .main_figure img {
max-width: 100%;
height: 100%;
}
main .bottompart p {
font-size: 2rem;
margin-top: 5rem;
}
I tried to reproduce your problem, I don't really see where is the problem.
The only thing I've found is the section upperpart is not close before the main closure.
main {
width: 100vw;
min-height: 100vh;
margin-top: 15.2rem;
}
main .upperpart {
background-color: antiquewhite;
height: 80rem;
width: 90vw;
margin: 0 auto;
/* visibility: hidden; */
}
.upperpart .main_figure {
width: 90vw;
/* max-height: 60rem; */
position: relative;
}
.upperpart .main_figure img {
max-width: 100%;
height: 100%;
}
main .bottompart p {
font-size: 2rem;
margin-top: 5rem;
}
<main>
<section class="upperpart">
<header class="main_header">
<div class="getoff">
<h2>get rm10 off</h2>
<p>your first order
<span>code:shemya</span>
</p>
</div>
<div class="share">
<h2>share & earn</h2>
<p>up to 15% off</p>
</div>
<div>
<h2>cash on delivery</h2>
</div>
</header>
<figure class="main_figure">
<img src="https://www.lux-review.com/wp-content/uploads/2022/05/Kids-Fashion.jpg" alt="" height="85%">
<figcaption></figcaption>
<img src="" alt="">
<div class="figure_ads">
<p>mega year end sale now on</p>
<p>up to <span>80%</span>off</p>
<button>buy now</button>
</div>
</figure>
<section class="middelpart">
--Hidden Content--
</section>
<section class="bottompart">
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Reprehenderit fugit earum accusantium non amet.</p>
</section>
</section>
</main>
I don't have scrolling trouble on this snippet. Do you have?
Desired outcome: I have three columns. I need them to be all the same width, as well as text and buttons to be on the same level in all three of them.
Problem: Depending on the number of words, columns become wider and buttons start to jump when text is resizing, and all three texts are resizing on a different points. I need to prevent that. How can I achieve this?
HTML:
<section class="sub-offer">
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus a
rerum sapiente odit porro obcaecati fugit, maxime modi veritatis
quis!
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi
perspiciatis voluptas qui iste, voluptatem atque ab rerum illum quia
incidunt odio?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Beatae
vitae aut fugit dicta repellendus dolorem, quam, accusamus hic nemo
ullam quod porro atque error?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
</section>
CSS:
.sub-offer {
text-align: center;
display: flex;
position: relative;
.offer-container {
background: linear-gradient(to bottom right, #2e2e3b, #0f1519);
}
h2 {
font-family: 'Playfair Display', serif;
font-size: 15px;
position: absolute;
margin-left: auto;
margin-right: auto;
margin-top: 4.3em;
width: 33%;
text-align: center;
}
p {
font-size: 12px;
margin-top: 2em;
padding: 0 0.5em 0 0.5em;
font-family: 'Montserrat', sans-serif;
}
a {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-size: 12px;
background: white;
margin: 3em 0 2.5em 0;
padding: 0.5em;
text-decoration: none;
color: black;
&:hover {
background: #e5e5e5;
}
}
}
How they look now:
You can add a media query to change the flex-direction when the screen resizes.
Add the following indie .sub-offer class.
#media(max-width: 600px){
flex-direction: column;
}
Add the following inside h2 element.
#media(max-width: 600px){
width: 100%;
}
I solved my issue. To give all three columns the same width I've used what #tacoshy recommended in the comments: section.sub-offer { display: flex; } .offer-container { width: calc(100% / 3); }
To align all three buttons though leaving all them responsive I've wrapped my button into a div and used the following css:
.more-btn {
display: flex;
align-self: center;
margin-top: auto;
}
I'm not really a good dev, but I can give it a try. What I do when I want to make things line up perfectly is use grid, so I tried adding it to .offer-container like this .offer-container {display: grid; grid-template-rows: 1fr 1fr 1fr;}. A working example is below. Though, since I'm new to helping people on StackOverflow or really StackOverflow in general, I'm sure I didn't do something right. for example, providing a solution to a different problem or fixing issues that you didn't as for. If you need a list of what I changed, you can see that here: added } for sub-offer removed extra closing bracket on a{} separated &:hover to a:hover{} made <p> text white. I hope this is the solution you were looking for if your problem hasn't already been fixed.
.sub-offer {
text-align: center;
display: flex;
position: relative;
width:100px
}
.offer-container {
background: linear-gradient(to bottom right, #2e2e3b, #0f1519);
display: grid;
grid-template-rows: 1fr 1fr 1fr;
}
h2 {
font-family: 'Playfair Display', serif;
font-size: 15px;
position: absolute;
margin-left: auto;
margin-right: auto;
margin-top: 4.3em;
width: 33%;
text-align: center;
}
p {
font-size: 12px;
margin-top: 2em;
padding: 0 0.5em 0 0.5em;
font-family: 'Montserrat', sans-serif;
color: white;
}
a {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-size: 12px;
background: white;
margin: 3em 0 2.5em 0;
padding: 0.5em;
text-decoration: none;
color: black;
}
a:hover {
background: #e5e5e5;
}
<section class="sub-offer">
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus a
rerum sapiente odit porro obcaecati fugit, maxime modi veritatis
quis!
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi
perspiciatis voluptas qui iste, voluptatem atque ab rerum illum quia
incidunt odio?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Beatae
vitae aut fugit dicta repellendus dolorem, quam, accusamus hic nemo
ullam quod porro atque error?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
</section>
I am trying to get a flex display living in a grid to behave like I want. Upon resizing the browser, the flex area refuses to drop below 2 columns no matter what I tinker with and am at a loss as to what to do. I've just taken up markup/coding and am still in the phase of layouts. I'm trying to leverage the powers of Grid and Flex together but am having minimal luck.
Here is what I have so far....please disregard and styling as this is just me tinkering.
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
color: #333;
}
.container {
display: grid;
grid-template-columns: repeat(autofit, minmax(200px, 1fr));
grid-template-rows: autofit 250px 1fr autofit;
grid-template-areas:
"h h h"
"c c c"
"p p p"
"f f f";
}
.flex-container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
margin: 0, auto;
}
.main-box {
width: 350px;
text-align: center;
justify-content: center;
margin-top: 2rem;
}
.text-wrap {
background-color: #eee;
width: 300px;
margin: auto;
}
.main-box p {
max-width: 200px;
margin: auto;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
li {
display: inline-block;
}
.green {
grid-area: h;
}
.red {
grid-area: c;
background-image: url("img/bgmain.jpg");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 250px;
}
.blue {
grid-area: p;
}
.yellow {
grid-area: f;
}
<!DOCTYPE html>
<html>
<head>
<title>Grid/Flex Test</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<body>
<div class="container">
<div class="green">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
<div class="red">Test</div>
<div class="blue">
<div class="flex-container">
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
</div>
</div>
<div class="yellow">
<span>Copyright © Designed by: Useless Dipshit</span>
</div>
</div>
</body>
</html>
So yeah, I'm a noob.
I forgot:
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
That solved everything for me.
I know a solution to create equal height columns using display:table like:
.row {
display: table;
width: 100%;
}
.col{
display: table-cell;
}
but my case is a bit different, since I am using flexbox and row class has display:flex:
.row {
display: flex;
display: ms-flex;
flex-wrap: wrap;
}
and all cols have .large-4 class:
.large-4 {
width: 25%;
max-width: 25%;
flex: 0 0 30%;
}
I can't use flex:1 for .large-4 as well because it varies in different viewport.
here is a snippet of html:
<div class="row">
<div class="large-4">
<div class="card">
<img src="https://picsum.photos/200/200" alt="author">
<div class="card-content">
<h1 class="card-title">Title</h1>
<p class="grey-text mgb-05">2012-09-05, by Basir Payenda</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae quas eligendi id est iste
distinctio
optio vel aliquam provident, ipsa reprehenderit in corrupti quia ratione quisquam amet veniam totam
veritatis.
</p>
</div>
</div>
</div>
<div class="large-4">
<div class="card">
<img src="https://picsum.photos/200/200" alt="author">
<div class="card-content">
<h1 class="card-title">Title</h1>
<p class="grey-text mgb-0">2012-09-05, by Basir Payenda</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.
</p>
</div>
</div>
</div>
<div class="large-4">
<div class="card">
<img src="https://picsum.photos/200/200" alt="author">
<div class="card-content">
<h1 class="card-title">Title</h1>
<p class="grey-text mgb-05">2012-09-05, by Basir Payenda</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae quas eligendi id est iste
distinctio.
</p>
</div>
</div>
</div>
</div>
code-pen link can be found here! how to I acheive equal height columns using flexbox? or any other better solution. thanks
You need to add display: flex to the .large-4 element:
.large-4 {
width: 25%;
max-width: 25%;
flex: 0 0 30%;
display: flex;
}
You'll notice when you inspect your elements using the inspector tool, large-4 elements are actually all the same height. It's the content inside that is not. So by making the parent element flex, it will make the children elements fill the space.
You already have equal-height columns, but inside them is a container that is contracting to its content. Expand that container.
.card {
height: 100%;
}
I want to make sure the image and the text in the columns are aligned to the bottom of the image and the top of the text. Does anybody know how to achieve this without explicitly setting the height of .c-grid__content to 200px?
Right now I'm using flexbox. Maybe css-grid is the answer?
Please take a look at this codepen: https://codepen.io/simoncoudeville/pen/VMZmVa?editors=1100#0.
p {
margin-bottom: 10px;
font-family: sans-serif;
}
img {
max-width: 100%;
margin-bottom: 10px;
}
.c-grid {
padding: 40px 20px;
display: flex;
}
.c-grid__item {
flex-basis: 100%;
margin: 0 20px;
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: flex-end;
}
.c-grid__picture {
width: 100%;
}
.c-grid__content {
display: flex;
flex-direction: column;
}
<div class="c-grid">
<article class="c-grid__item">
<div class="c-grid__picture">
<img src="http://via.placeholder.com/400x200">
</div>
<div class="c-grid__content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore ratione commodi corrupti itaque sed architecto!</p>
</div>
</article>
<article class="c-grid__item">
<div class="c-grid__picture">
<img src="http://via.placeholder.com/400x600">
</div>
<div class="c-grid__content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore ratione commodi corrupti itaque sed architecto! Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</div>
</article>
<article class="c-grid__item">
<div class="c-grid__picture">
<img src="http://via.placeholder.com/400x400">
</div>
<div class="c-grid__content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore ratione commodi corrupti itaque sed architecto! </p>
</div>
</article>
</div>
Align-items: baseline on the flexbox container seems to do the trick in this case. See the solution here: https://codepen.io/simoncoudeville/pen/yzOvmN?editors=1100
Looking at your codepen, this doesn't appear to require responsive design. If I am correct in that assumption, why not use a table that separates the images and text by rows, vertically aligning the top row at the bottom and the bottom row at the top?
It would limit the important CSS to just a few lines:
.c-grid__picture {
vertical-align: baseline;
}
.c-grid__content {
vertical-align: top;
}
Here is an example in JSFiddle
I was able to achieve this setting the flex-basis of the .c-grid__content to 0.
.c-grid__content {
...
flex-basis: 0;
}
https://codepen.io/antibland/pen/WZrXpw?editors=1100