trying to put two stacked images to align right to a lone image in css - html

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.

Related

Why I can't set image on top of div in scroll wrapper div card

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>

always keep pseudo element horizontally in the middle

How do I always keep a pseudo element horizontally in the middle? I have it positioned absolutely with a percentage value, which I undrstood was relative to the width of the element but on different screen sizes the circular "OR" is not consistently in the middle...
See below:
.content {
display: flex;
flex-direction: row;
justify-content: space-evenly;
text-align: center;
margin: 20px;
}
.cc-content {
width: 50%;
padding: 5px 20px;
position: relative;
background-color: red;
}
.cc-content-1 {
margin-right: 3px;
}
.cc-content-2 {
margin-left: 3px;
}
.cc-content-1:after {
content: 'OR';
display: inline-block;
position: absolute;
vertical-align: middle;
line-height: 60px;
top: 20px;
left: 90%;
z-index: 1;
font-size: 21px;
font-weight: bold;
border-radius: 100%;
width: 60px;
height: 60px;
background-color: #F2F2F2;
color: #006AAD;
}
<div class="content">
<div class="cc-content cc-content-1">
<h3>Header Here</h3>
<p>Lorem Ipsuom gshjgshj gshjgsajhusgs gsaiyusgisysgsyigs</p>
</div>
<div class="cc-content cc-content-2">
<h3>Header Here</h3>
<p>Lorem Ipsuom gshjgshj gshjgsajhusgs gsaiyusgisysgsyigs</p>
</div>
</div>
If you resize the window you can see the circle shifts ever so slightly off cente, how do I always keep it in center with position absolute? Is not not percentage? I tried playing with flex since it is in a flex container but that doesn't seem to do anything.
How do I horizontally center a position absolute :after element?
Very similar to #mgrsskls but using actual :after element. Its an old trick to use absolute, then add left and negative margin equal to half-width. But in your case there is additional margin which needs to be thought of as well.
.content {
display: flex;
flex-direction: row;
justify-content: space-evenly;
text-align: center;
margin: 20px;
}
.cc-content {
width: 50%;
padding: 5px 20px;
position: relative;
background-color: red;
}
.cc-content-1 {
margin-right: 3px;
}
.cc-content-2 {
margin-left: 3px;
}
.cc-content-1:after {
content: 'OR';
display: inline-block;
position: absolute;
vertical-align: middle;
line-height: 60px;
top: 20px;
left: 100%;
margin-left: -27px;
z-index: 1;
font-size: 21px;
font-weight: bold;
border-radius: 100%;
width: 60px;
height: 60px;
background-color: #F2F2F2;
color: #006AAD;
}
<div class="content">
<div class="cc-content cc-content-1">
<h3>Header Here</h3>
<p>Lorem Ipsuom gshjgshj gshjgsajhusgs gsaiyusgisysgsyigs</p>
</div>
<div class="cc-content cc-content-2">
<h3>Header Here</h3>
<p>Lorem Ipsuom gshjgshj gshjgsajhusgs gsaiyusgisysgsyigs</p>
</div>
</div>
First of all I would put the "or" in the HTML, so screen readers would read it out loud correctly. Then you can position that element relative to the whole container, with percentage yes. You move it exactly to the middle with left: 50% and then by its half width back to the left with transform: translateX(-50%) (that way you don't have to know how wide the "or" element is).
.content {
display: flex;
flex-direction: row;
justify-content: space-evenly;
text-align: center;
margin: 20px;
position: relative;
}
.cc-content {
width: 50%;
padding: 5px 20px;
position: relative;
background-color: red;
}
.cc-content-1 {
margin-right: 3px;
}
.cc-content-2 {
margin-left: 3px;
}
.or {
display: inline-block;
position: absolute;
vertical-align: middle;
line-height: 60px;
top: 20px;
left: 50%;
transform: translateX(-50%);
z-index: 1;
font-size: 21px;
font-weight: bold;
border-radius: 100%;
width: 60px;
height: 60px;
background-color: #F2F2F2;
color: #006AAD;
text-transform: uppercase;
}
<div class="content">
<div class="cc-content cc-content-1">
<h3>Header Here</h3>
<p>Lorem Ipsuom gshjgshj gshjgsajhusgs gsaiyusgisysgsyigs</p>
</div>
<div class="or">or</div>
<div class="cc-content cc-content-2">
<h3>Header Here</h3>
<p>Lorem Ipsuom gshjgshj gshjgsajhusgs gsaiyusgisysgsyigs</p>
</div>
</div>
Instead of left: 90%, you can do left: calc(100% - 30px).
30px is half the width of the pseudo-element.

Positioning elements around element

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>

CSS arrange two divs next to each other

I have following HTML:
<div className={`page-header-profile-photo-container`}>
<div className="user-picture">
</div>
<div className="user-name">
<p>Sample GmbhH</p>
</div>
</div>
And my css:
.page-header-profile-photo-container{
position: absolute;
top: 10%;
right: 130px;
width: 200px;
}
.user-picture {
position: relative;
top: 10%;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #787567;
}
.user-name{
position: absolute;
top: 5%;
}
This renders like following:
I want to have some space between circular div and text. page-header-profile-photo-container's position has to be absolute.
How can I fix this?
First of all correct your syntax like className to class and try the following code. No need to position:absolute in user-name class
.page-header-profile-photo-container{
width: 200px;
position: absolute;
top: 10%;
right: 130px;
}
.user-picture {
position: relative;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #787567;
display: inline-block;
vertical-align: middle;
}
.user-name{
display: inline-block;
vertical-align: middle;
}
<div class=page-header-profile-photo-container>
<div class="user-picture">
</div>
<div class="user-name">
<p>Sample GmbhH</p>
</div>
</div>
Don't use absolute positioning in user name. Absolute positioning puts an item in a particular position no matter what (doesn't care if it gets overlapped)
Using flex-box it will work good for me. Hope this help.
.page-header-profile-photo-container{
background-color: #f5f5f5;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
position: absolute;
height: 50px;
top: 10%;
right: 130px;
padding: 5px 10px;
width: 200px;
}
.user-picture {
position: relative;
width: 40px;
height: 40px;
border-radius: 50%;
/*background-color: #787567;*/
}
.user-picture img{
border-radius: 50%;
display: block;
height: auto;
max-width: 100%;
}
.user-name{
font-size: 15px;
}
<div class=page-header-profile-photo-container>
<div class="user-picture">
<img src="http://placehold.it/40x40" alt="Profile Picture" />
</div>
<div class="user-name">
<p>Sample GmbhH</p>
</div>
</div>

How do I float an image exactly in the center above text inside a box?

I can't get this to work :( I'm just trying to float the image slightly outside the box (half in, half out) above the name but in the center. What am I doing wrong here?
body {
margin-top: 100px;
}
.box_info {
display: inline-block;
padding: 20px;
min-width: 300px;
background-color: #DDD;
border-radius: 4px;
text-align: center;
}
.box_info_name {
display: block;
font-size: 24px;
}
.box_info_logo {
max-width: 100%;
height: auto;
position: absolute;
text-align: center;
}
.box_info_name_inside {}
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150x150" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>
Here is a fiddle: https://jsfiddle.net/ffxyc6d0/1/
try This One :
body{
margin-top:100px;
}
.box_info{
display: inline-block;
padding: 20px;
min-width: 300px;
background-color: #DDD;
border-radius: 4px;
text-align:center;
}
.box_info_name{
display: block;
font-size: 24px;
}
.box_info_logo{
width: 150px;
height: 150px;
position: relative;
bottom: 50px;
text-align:center;
}
.box_info_name_inside{
}
<body>
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150x150" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>
</body>
If the image is fixed size (not going to change dynamically) you can position it with a negative margin of half the images height, e.g. margin-top: -85px; (Take an extra -10px off as well as the half image height since there's 20px of padding on the parent container)
Example below:
body {
margin-top: 100px;
}
.box_info {
display: inline-block;
padding: 20px;
min-width: 300px;
background-color: #DDD;
border-radius: 4px;
text-align: center;
}
.box_info_name {
display: block;
font-size: 24px;
}
.box_info_logo {
display: inline-block;
margin-top: -85px;
max-width: 100%;
height: auto;
text-align: center;
}
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150x150" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>
You can do it with flexbox as well :)
body{
margin-top:100px;
}
.box_info{
background: #ccc;
}
.box_info_name{
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
font-size: 24px;
}
.box_info_logo{
position: relative;
margin-top: -75px;
}
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150x150/fff" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>
I like to give 'outside the box' answers to questions like this, without using javascript having to change all the margins gets to be a little annoying. So I've tackled it another way. Rather than moving everything around the page why not just make part of the background transparent.
.box_info {
display: inline-block;
padding: 20px;
min-width: 300px;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 95px, #DDD 95px);
border-radius: 4px;
text-align: center;
}
.box_info_name {
display: block;
font-size: 24px;
}
.box_info_logo {
text-align: center;
}
.box_info_name_inside {}
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>
<div class="box_info">
<div class="box_info_name">
<img width="150px" src="https://lh4.googleusercontent.com/-1rv6qW3mpvA/AAAAAAAAAAI/AAAAAAAAS3M/xq0SSZzrgVg/photo.jpg" class="box_info_logo">
<div class="box_info_name_inside">Andrew Bone</div>
</div>
</div>
I've used background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 95px, #DDD 95px); to say anything after 95px should be #DDD and before that needs to be transparent.
95px is height of the image (150px) divided by 2 (75px) plus the padding of the outer box (20px).
Which is great if the image size stays the same, if you plan on it changing then we might need to look at adding a little javascript.
linear-gradient is not supported in IE6 but is in modern IE as well as Edge, Chrome, and firefox.
I hope you find this helpful.
I'm not sure if I'm understanding your question correctly, but maybe this is waht you wan't.
I've simply removed the position: absolute from your .box_info_logo class.
Like this:
body{
margin-top:100px;
}
.box_info{
display: inline-block;
padding: 20px;
min-width: 300px;
background-color: #DDD;
border-radius: 4px;
text-align:center;
}
.box_info_name{
display: block;
font-size: 24px;
}
.box_info_logo{
max-width: 100%;
height: auto;
text-align:center;
}
.box_info_name_inside{
}
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150x150" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>
To keep .box_info the same size as that in your jsfiddle example, you can add position: relative to this class whilst keeping .box_info_logo as position: absolute.
body {
margin-top: 150px;
}
.box_info {
display: inline-block;
padding: 20px;
min-width: 300px;
background-color: #DDD;
border-radius: 4px;
text-align: center;
position: relative;
}
.box_info_name {
display: block;
font-size: 24px;
}
.box_info_logo {
max-width: 100%;
height: auto;
position: absolute;
text-align: center;
left: 0;
right: 0;
margin: auto;
bottom: 50px;
}
.box_info_name_inside {}
<div class="box_info">
<div class="box_info_name">
<img src="http://placehold.it/150x150" class="box_info_logo">
<div class="box_info_name_inside">Name</div>
</div>
</div>