So I have a 3 flexboxes and flex items inside of them. I need them to be on the left, like on the following image:
But for some reason my image and header are stuck on the right, and can't even be aligned with align-items.
So I have the following result:
I'm not really sure what's the problem here, I tried to do float:left for image, but it doesn't move.
art_container is a huge container, inside of which are 3 flexboxes - art_block, and flex items inside of them.
.article img{
position: absolute;
top:0;
right:0;
}
.art_container {
position: relative;
top: 10%;
left: 0;
/* transform: translateY(30%) translateX(30%); */
width: 100vh;
height: 110vh;
background-color: white;
}
.art_block {
position: relative;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
min-width: 100%;
height: 300px;
background-color: black;
border-bottom: 1px solid white;
}
.art_block img {
flex: 1 1 auto;
width: 300px;
height: 200px;
object-fit: cover;
border: 2px solid red;
}
.art_block h2 {
color: #fff;
font-size: 1.5rem;
font-weight: 800;
font-family: "Open Sans", sans-serif;
}
<article class="article">
<div class="art_container">
<div class="art_block" id="block1">
<img src="https://via.placeholder.com/300">
<h2>Sony's new releases for 2018</h2>
</div>
<div class="art_block" id="block2">
<img src="https://via.placeholder.com/300">
<h2>10 tips to be a better gamer</h2>
</div>
<div class="art_block" id="block3">
<img src="https://via.placeholder.com/300">
<h2>Microsoft has some new tips</h2>
</div>
</div>
</article>
Edit: so i've found that i have another image style for outside container, which i guess may affect my flex image:
.article img{
position: absolute;
top:0;
right:0;
}
So that's a style for a bigger div, inside of which is my art_container, and now i'm wondering, how could i make .art_container img style, while not being affected by .article img style?
Sometimes the best strategy is just to step back and simplify. I'm not sure why you have all the fixed sizing on the images and containers, but that's probably not necessary. If you have minimum sizes in mind, use other means to ensure that, such as wrapping to vertical using media queries. The more you stay flexible the simpler your layout will be.
Here's a start.
.art_block {
display: flex;
justify-content: start;
align-items: center;
flex-wrap: wrap;
background-color: black;
border-bottom: 1px solid white;
}
.art_block img {
flex: none;
max-width: 200px;
object-fit: cover;
border: 2px solid red;
margin: 15px;
}
.art_block h2 {
color: #fff;
font-size: 1.5rem;
font-weight: 800;
font-family: "Open Sans", sans-serif;
margin: 15px;
}
<div class="art_container">
<div class="art_block" id="block1">
<img src="https://via.placeholder.com/300">
<h2>Sony's new releases for 2018</h2>
</div>
<div class="art_block" id="block2">
<img src="https://via.placeholder.com/300">
<h2>10 tips to be a better gamer</h2>
</div>
<div class="art_block" id="block3">
<img src="https://via.placeholder.com/300">
<h2>Microsoft has some new tips</h2>
</div>
</div>
Simply use flex-wrap: no-wrap; so your image and text remains on the same line.
I've add a wrapper for your text so you can add some p tags inside
.art_container {
position: relative;
top: 10%;
left: 0;
/* transform: translateY(30%) translateX(30%); */
width: 100%;
height: 110vh;
background-color: white;
}
.art_block {
position: relative;
display: flex;
flex-wrap: no-wrap;/* use this */
min-width: 100%;
height: 300px;
background-color: black;
border-bottom: 1px solid white;
}
.art_block img {
flex: 1 1 auto;
width: 300px;
height: 200px;
object-fit: cover;
}
.art_block h2 {
color: #fff;
font-size: 1.5rem;
font-weight: 800;
font-family: "Open Sans", sans-serif;
}
<div class="art_container">
<div class="art_block" id="block1">
<img src="https://via.placeholder.com/300">
<div class="wrap-text">
<h2>Sony's new releases for 2018</h2>
</div>
</div>
<div class="art_block" id="block2">
<img src="https://via.placeholder.com/300">
<div class="wrap-text">
<h2>10 tips to be a better gamer</h2>
</div>
</div>
<div class="art_block" id="block3">
<img src="https://via.placeholder.com/300">
<div class="wrap-text">
<h2>Microsoft has some new tips</h2>
</div>
</div>
</div>
Related
I created a cards-based horizontal scroller. And the cards are nicely scrolling inside the wrapper. The issue I'm having is that even after I applied the z-index to our member-owner-card-image, the photos still go under the card when I want to put them on the top of each card.
Is there any solution so that I can add the image on top of the card? I'm trying to fix it, but no solution has been found.
.scrolling-wrapper {
-webkit-overflow-scrolling: touch;
height: 331px;
width: 100%;
padding-inline: 40px;
position: relative;
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
z-index: 0;
}
.scrolling-wrapper::-webkit-scrollbar {
display: none;
}
.card {
width: 100%;
flex: 0 0 auto;
background-color: green;
border-radius: 20px;
position: relative;
margin-right: 10px;
}
.our-member-owner-card-image {
position: absolute;
top: -30px;
z-index: 10;
}
.card-content {
position: absolute;
padding-top: 38px;
}
.member-detail {
padding-top: 55px;
line-height: 1.7;
}
.member-detail h3 {
text-align: center;
color: #263244;
font-weight: 700;
font-family: 'Lato';
}
.member-detail p {
text-align: center;
color: #737C89;
}
.member-description {
padding-inline: 20px;
color: #263244;
line-height: 1.6;
padding-top: 9px;
font-weight: 500;
font-size: 17px;
}
.member-description span {
color: red;
text-decoration: underline;
}
<div class="scrolling-wrapper">
<div class="card">
<div class="our-member-owner-card-image">
<img width="220px" src="https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" />
</div>
<div class="card-content">
<div class="member-detail">
<h3>Sohaib</h3>
<p>Chairman</p>
</div>
<div class="member-description">
Sohaib Ashraf has extensive work experience during his career
of more than 25 years in the financial services sector.<span
>Read more</span
>
</div>
</div>
</div>
<div class="card">
<div class="our-member-owner-card-image">
<img width="220px" src="https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" />
</div>
<div class="card-content">
<div class="member-detail">
<h3>Sohaib Ashraf</h3>
<p>Chairman</p>
</div>
<div class="member-description">
Sohaib Ashraf has extensive work experience during his career
of more than 25 years in the financial services sector.<span
>Read more</span
>
</div>
</div>
</div>
</div>
You could add the image as a background-image to the card. I added few examples how you can use background-image:
.card{
width: 400px;
height: 300px;
margin: 10px;
border-radius: 6px;
background-color: gray;
}
.card-1, .card-2 .image, .card-3 .image{
/* Here, we use background-image to set the image */
background-image: url("https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80");
/* The background should be a cover photo,
so it fills the whole card: */
background-size: cover;
/* We don't want the image to repeat itself */
background-repeat: no-repeat;
/* When the ratio of the image changes, it will zoom into
this point, which we want to happen in the center of the image */
background-position: center;
}
.card-2, .card-3{
display: grid;
grid-template-rows: 1fr 1fr;
}
.card-2 .image{
border-radius: 6px 6px 0px 0px;
}
.card-3{
padding: 10px;
}
/* This is to demonstrate: */
h2{
color: white;
display: flex;
justify-content: center;
font-family: sans-serif;
}
<div class="card-1 card">
<h2>Test title</h2>
</div>
<div class="card-2 card">
<div class="image"></div>
<div class="content">
<h2> Test title</h2>
</div>
</div>
<div class="card-3 card">
<div class="image"></div>
<div class="content">
<h2> Test title</h2>
</div>
</div>
i'm trying to two pictures that are stacked upon each other to lay beside a full picture like the image below - i'm trying to get those two images that are stacked on each other to align next to the other lone image.
can anyone help me with this. i don't know if its flexbox or i should use positioning to solve the problem because the image is stuck below and i'm trying to make the images go up and also make them align right next to the lone image (p.s i have tried positioning but does not work for some reason)
.lone-image {
display: flex;
}
.images {
background-size: cover;
background-image: url(xii.jpg);
width: 45%;
height: 520px;
position: relative;
left: 50px;
}
.Xiaomi h1 {
position: absolute;
color: white;
font-weight: normal;
font-size: 40px;
bottom: 70%;
right: 60%;
}
.xiaomi-text {
color: white;
position: absolute;
top: 25%;
left: 6%;
font-size: 12px;
}
.Buy-now button {
background-color: #706c6c;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
position: absolute;
bottom: 60%;
right: 76%;
}
.images2 {
background-image: url(canon.jpg);
background-size: cover;
width: 37%;
height: 280px;
position: relative;
margin-bottom: 10px;
}
.Canon h1 {
font-weight: normal;
font-size: 40px;
position: absolute;
top: 40px;
left: 15px;
}
.button2 button {
color: white;
background-color: #706c6c;
padding: 6px 12px;
border: none;
position: absolute;
font-size: 16px;
top: 150px;
left: 15px;
}
.images3 {
background-image: url(dell.jpg);
background-size: cover;
width: 37%;
height: 280px;
flex-wrap: wrap;
}
.stacked-image {
display: flex;
flex-flow: column;
align-items: flex-end;
}
<div class="lone-image">
<div class="images">
<div class="Xiaomi">
<h1> Xiaomi X15</h1>
</div>
<div class="Buy-now">
<button> BUY NOW</button>
</div>
<div class="xiaomi-text">
<p> Discover your passion in the phone of dreams so order now</p>
</div>
</div>
</div>
<div class="stacked-image">
<div class="images2">
<div class="Canon">
<h1>CANON MP56 </h1>
</div>
<div class="button2">
<button> BUY NOW</button>
</div>
</div>
<div class="images3">
<div class="Dell">
<h1>Dell X5-MWS</h1>
</div>
<div class="button3">
<button> BUY NOW</button>
</div>
</div>
</div>
If I'm understanding you correctly, you are looking for flexbox. Here is a basic example:
JSFiddle
<div class="parent">
<img src="" alt="left"/>
<div class="child">
<img src="" alt="hi"/>
<img src="" alt="hi"/>
</div>
</div>
.parent {
display: flex;
}
.child {
display: flex;
flex-direction: column;
}
If you want the change how they vertically align, you can just play around with the align-items CSS property on the parent class.
HTML CODE
<div class="wrapper">
<div class="flex-container">
<div class="box one">
<img src="img\xii.jpg" alt="phone1" />
<section class="section1">
<p>Xiaomi X15</p>
<br />
<h2>New Powerhouse Phone From The Xiaomi Brand</h2>
<br />
<button> BUY NOW</button>
</section>
</div>
</div>
</div>
CSS CODE
.flex-container {
display: flex;
background-color: #fff;
border: 2px solid black;
flex-wrap: wrap;
}
.wrapper {
width: 100px;
max-width: 960px;
margin: 0 auto;
}
.one p {
position: absolute;
bottom: -350px;
color: white;
font-size: 50px;
left: 500px;
text-align: center;
font-weight: lighter;
font-family: calibri;
}
.section1 h2 {
position: absolute;
bottom: -500px;
left: 300px;
color: white;
}
please help im a beginner in css and this is my first stackoverflow post
my texts are not horizantally in place and keeps breaking down that each word forms a new paragraph how can i solve this please? i have tried the display:inline- block but it didnt work.as you can see from my code i made the div tag that the image is on to be position relative so i can move the h2 and span and button elements to be nn the image. i intend on using flexbox because on i want to position more images to be on the side of the initial image
What you can do is:
Define some width and height (max-width and min-width to be more flexible) for your box;
Use background-image CSS prop instead of HTML <img />, which will ensure the image fills the background of your container;
Use flex-box with its all properties to lay out your elements. There will be no need for position: absolute for the text and header.
Other notes to your code: there are some closing tags missing in your HTML as well as closing } braces in the CSS. That is never a good practice to leave your code without them, even though in some cases the browser can fill them out for you.
Here is an example of how you can achieve what you were asking about:
.wrapper {
width: 100%;
max-width: 960px;
margin: 0 auto ;
display: flex;
justify-content: space-between;
}
.flex-container{
display: flex;
background-color:#fff;
border: 2px solid black;
flex-wrap: wrap;
width: auto;
height: 200px;
min-width: 100px;
max-width: 400px;
}
.one {
background-image: url('https://cdn.thewirecutter.com/wp-content/uploads/2018/05/smartphone-tp-top-2x1-lowres1024-7951.jpg');
background-size: cover;
}
.section1 {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.section1 p{
color: white;
font-size: 25px;
text-align: left;
font-weight: lighter;
font-family: calibri;
padding: 10px;
margin: 0
}
.section1 h2{
color: white;
padding: 10px;
margin: 0
}
button {
max-width: 100px
}
<div class="wrapper">
<div class="flex-container">
<div class="box one">
<section class="section1">
<p>Xiaomi X15 </p>
<h2>New Powerhouse Phone From The Xiaomi Brand</h2>
<button> BUY NOW</button>
</section>
</div>
</div>
<div class="flex-container">
<div class="box one">
<section class="section1">
<p>Xiaomi X15 </p>
<h2>New Powerhouse Phone From The Xiaomi Brand</h2>
<button> BUY NOW</button>
</section>
</div>
</div>
</div>
I need to position elements on a side like in the image above and have onclick function on them to show the corresponding text. Any info on how to best achieve this to be responsive?
By responseive i mean that the dots and text should always stay on the same position relative to the size of the bottle.
What I did was to put everything inside the container div and then positioned the elements relative to that div and the bottle image absolute to the container div.
It kinda works when container div has fixed dimensions, but I guess there are better ways to do it.
EDIT: Added code! I suck at formatting, sorry.
<div class="bottle-one">
<div class="bottle-one-content">
<div class="bottle-one-image">
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
</div>
<a href="#msg1" class="droplet droplet1 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg2" class="droplet droplet2 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg3" class="droplet droplet3 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg4" class="droplet droplet4 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<img src="assets/images/bottle1.png" alt="" class="bottle-one-bottle">
</div>
</div>
.bottle-one {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 30%;
}
.bottle-one-image {
height: 100%;
position: relative;
width: 251px;
}
.message {
left: -340px;
top: 180px;
position: relative;
display: flex;
align-items: center;
justify-content: flex-end;
text-transform: uppercase;
font-size: .7rem;
color: #004197;
height: 30px;
width: 400px;
margin-bottom: 1rem;
}
.message-hidden {
display: flex;
}
.message-hidden div:nth-of-type(1) {
text-align: right;
font-family: 'BrandonGrotesqueWeb-Black', sans-serif;
letter-spacing: 2px;
border-right: 1px solid #004197;
width: 70%;
}
.message-hidden div:nth-of-type(2) {
width: 30%;
display: flex;
overflow:hidden;
}
I came up with this to help you with aligning your element to the left of a div.
By using a mix of [psuedo-elements] and floats, I think this gives you the desired effect you are looking for. Post your code and I'll be more then happy to help you with the other part.
html {
width: 550px;
border: none;;
}
body {
font-family: sans-serif;
color: rgba(0,0,0,.15);
height:200px;
}
body:after {
content: '';
display: block;
clear: both;
}
div {
position: relative;
}
div:after {
font-size: 200%;
position: absolute;
left: 0;
right: 0;
top: 0;
text-align: center;
}
.sibling {
border: 3px solid red;
height:200px;
}
.sibling.root:after {
content: 'Sibling';
color: green;
}
.float {
float: left;
border: 3px solid blue;
height: 90px;
width: 150px;
z-index: 1;
}
.float:after {
content: 'floated Element';
color: red;
}
.root {
overflow: hidden;
}
<div class="float">
</div>
<div class="sibling root">
</div>
I'm experiencing an issue with my text where I don't see it at all, or it doesn't act as though I would think it would in a flexbox. I have three images in the flexbox right now, but I would like to place small 'captions' under each of them(not in the p element, the purple, but I would like to place it on the white, which is right under the purple box(the p element). I thought that by adding a child element, that element would at least line up vertically with the element above it but I guess I'm wrong. Can anyone help? Another piece of info is that really my images are 250 pixels, but I wanted to accommodate for a snippet so I made it 50 pixels, but that's probably irrelevant.
#footer {
display: flex;
height: 130px;
width: 100%;
background-color: #862d59;
clear: both;
}
#footer, #wrapper:after{
height: 130px;
}
.wrap {
margin: 0 auto;
width: 100%;
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.sub {
padding: 12px;
width: 32%;
height: 100px;
color: white;
border-right: solid white 1px;
}
.sub:last-child {
border: 0px;
}
html {
height: 100%;
}
body {
height: 100%;
margin:0;
font-family: courier;
font-size: 22px;
color: white;
}
#wrapper {
position: relative;
margin-left: auto;
margin-right: auto;
width: 85%;
min-height: 100%;
margin-top: -130px;
}
#inner {
position:absolute;
display:flex;
flex-wrap: wrap;
height: 600px;
top:50%;
align-items: center;
justify-content: space-between;
margin-top: -300px;
align-content: center;
width: 100%;
}
#inner p {
background-color: #26004d;
padding: 60px;
border-radius: 9px;
}
#inner img {
border-radius: 8px;
}
<div id="wrapper">
<div id="inner">
<p><img src="cat1.jpeg" alt="Picture of a cat" width="50" height="50"></p>
<p><img src="dog1.jpg" alt="Picture of a cat" width="50" height="50"></p>
<p><img src="park.jpg" alt="Picture of a cat" width="50" height="50"></p>
</div>
</div>
<div id="footer">
<div class="wrap">
<div class="sub"></div>
<div class="sub"></div>
<div class="sub"></div>
</div>
</div>
Without additional info / image, here's the solution I was able to come up with. If you want to keep each image / caption grouped together, wrap them in another parent div. Then just add the caption below that, which is a block element and should flow below the image, as intended. Snippet below.
#footer {
display: flex;
height: 130px;
width: 100%;
background-color: #862d59;
clear: both;
}
#footer, #wrapper:after{
height: 130px;
}
.wrap {
margin: 0 auto;
width: 100%;
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.sub {
padding: 12px;
width: 32%;
height: 100px;
color: white;
border-right: solid white 1px;
}
.sub:last-child {
border: 0px;
}
html {
height: 100%;
}
body {
height: 100%;
margin:0;
font-family: courier;
font-size: 22px;
color: white;
}
#wrapper {
position: relative;
margin-left: auto;
margin-right: auto;
width: 85%;
min-height: 100%;
}
#inner {
position:absolute;
display:flex;
flex-wrap: wrap;
height: 600px;
top:50%;
align-items: center;
justify-content: space-between;
margin-top: -300px;
align-content: center;
width: 100%;
}
#inner p {
background-color: #26004d;
padding: 60px;
border-radius: 9px;
}
#inner p.caption {
color: #000;
background-color: transparent;
border-radius: 0;
}
#inner img {
display: block;
border-radius: 8px;
}
<div id="wrapper">
<div id="inner">
<div class="image-wrapper">
<p>
<img src="http://placehold.it/100x100" alt="Picture of a cat">
</p>
<p class="caption">Caption</p>
</div>
<div class="image-wrapper">
<p>
<img src="http://placehold.it/100x100" alt="Picture of a cat">
</p>
<p class="caption">Caption</p>
</div>
<div class="image-wrapper">
<p>
<img src="http://placehold.it/100x100" alt="Picture of a cat">
</p>
<p class="caption">Caption</p>
</div>
</div>
</div>
<div id="footer">
<div class="wrap">
<div class="sub"></div>
<div class="sub"></div>
<div class="sub"></div>
</div>
</div>
Let me know if you have any questions, or if this doesn't satisfy your description.