I have an image that is a card i need to repeat it 30 times, and on each time i want to apply for a specific card a left position so it overlaps the card before staying on a position like a deck.
The thing is, when i apply a left position to the image card, it applies the same left position to all cards, so there is no overlap position.
So i have something like this:
<template>
<div class="triPack">
<img :style="{'left': -index * 30}" v-for="index in 30" :key="index" src="../../assets/images/cardThemes/blue.png" alt="">
</div>
</template>
<script>
export default {
}
</script>
<style lang="scss">
.triPack {
display: flex;
img {
width: 80px;
height: 100px;
position: relative;
}
}
</style>
i want something like this:
Thank you guys.
You can do it with only css margin-left except the first image :not(:first-child)
So remove it :style="{'left': -index * 30}"
.triPack {
display: flex; }
img {
width: 80px;
height: 100px;
position: relative;
}
img:not(:first-child) {
margin-left: -45px;
}
<div class="triPack">
<img src="https://i.stack.imgur.com/XG0gL.png" alt="">
<img src="https://i.stack.imgur.com/XG0gL.png" alt="">
<img src="https://i.stack.imgur.com/XG0gL.png" alt="">
<img src="https://i.stack.imgur.com/XG0gL.png" alt="">
</div>
Related
I have a carousel with different sized of images but they all have the same height (500px).
On this pictures I want to put the navigations button (prev and next) at the bottom left.
I succeeded to put the navigation buttons where I want on the vertical axe because the height of pictures is fix but still struggling for the horizontal axe
This is what looks like the code actually
<div class="carousel" ng-controller="CarouselController as $ctrl">
<img ng-show="$ctrl.currentIndex == 0"/>
<img ng-show="$ctrl.currentIndex == 1"/>
<img ng-show="$ctrl.currentIndex == 2"/>
<img ng-show="$ctrl.currentIndex == 3"/>
<div class="carousel-navigation">
<a ng-click="$ctrl.showPrevious()"> <
<a ng-click="$ctrl.showNext()" > >
</div>
</div>
.carousel{
position: relative;
.carousel-navigation {
position: absolute;
bottom: 0
}
}
Do you have any idea how I can do that by avoiding javascript ?
EDIT:
EDIT2: On the picture the big square is the <div class='carousel'>, then the square under title is the <img/>and the plain black square is <div class="carousel">. The next big square is just showing what it should look like after clicking on next when the img is less width
You can use the "Left" css property.
Edit : You can use flex property.
(jQuery is just for changing the pictures)
$(document).ready(function(){
$('#button1').click(function(){
$('img').attr('src', 'https://picsum.photos/300/300?random=1');
});
$('#button2').click(function(){
$('img').attr('src', 'https://picsum.photos/200/300?random=1');
});
});
.container{
display: flex;
width: 100%;
}
.container .image-container{
position: relative;
margin: 0 auto;
}
.container .image-container img{
width: 100;
height: auto;
}
.container .image-container .navigation{
position: absolute;
bottom: 3px;
left: 0;
/* styling */
background-color: SlateBlue;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<span class="image-container">
<img src="https://picsum.photos/200/300?random=1" alt="">
<div class="navigation">
Navigation
</div>
</span>
</div>
<button id="button1">Image 1</button>
<button id="button2">Image 2</button>
body {
width: 100%;
max-width: 1200px;
margin-right: 2px;
margin-left: 2px;
}
.fruit {
width: 1200px;
max-height: 39em;
}
img {
float: left;
}
<div class="fruit">
<img src="images/OrangesPinkBackground.jpg" alt=" " width="600px" />
<img src="images/GrapefruitPinkBackground.jpg" alt=" " width="600px" />
</div>
I've tried so many different things I can think of and they just keep ending up like this
Maybe it's a problem with how I have the body styled? because there is a lot more whitespace on the right side where the scroll bar is. What I was trying to was evenly split the two images so they would each take up half the screen and only extend about 40em downwards as well. Somehow I just can't get them to lineup right.
I'll take any suggestions at this point.
<div class="fruit">
<div class="fruit-img">
<img src="images/OrangesPinkBackground.jpg" alt=" "/>
</div>
<div class="fruit-img">
<img src="images/GrapefruitPinkBackground.jpg" alt=" "/>
</div>
</div>
In your parent fruit class:
.fruit{
display: flex;
align-items:center;
height: 39em;
width: 100%;
}
In your child fruit class for each image, this acts as a container
.fruit-img{
height: 100%;
flex-basis: 50%;
}
This is your actual image class
.fruit-img img{
width: 100%;
height: 100%:
}
You can use flexbox. It's more easy than using float.
Use flex with:
justify-content: space-between
to get images align at the end of screen on each side
I tried to position my logo and headerpic on top of each other like this:
img {
position: absolute;
top: 25px;
left: 25px;
}
.imgA1 {
z-index: 1;
}
.imgB1 {
z-index: 3;
}
<img class="imgA1" src="https://placehold.it/200/333333">
<img class="imgB1" src="https://placehold.it/100">
But my logo is still at the top end of my header pic.
My css code looks like this:
.header img.headerpic {
max-width:100%;
float:left;
position:relative;
background:transparent url(../images/header.jpg)
}
.header img.logo {
position: relative;
float:left;
max-width:100%;
background:transparent url(../images/logo.png )
}
and i added this in my index.php:
<body id="home">
<!-- header area -->
<div class="header">
<id="logo">
<img src="<?php echo TEMPLATE_DIR; ?>/images/logo.png" alt="logo"/>
<img class="headerpic" src="<?php echo TEMPLATE_DIR; ?>/images/headspacer.jpg" alt="" />
<div class="infobox"><div class="inner">
</div>
</body>
What do i need to change that my Header-Picture is the background and my logo is on the left in the center of the Picture?
My actual view
position:absolute is relative to the nearest positioned parent, or the entire page. Therefore, here you are setting the images to be at the exact same location.
What you need is for .imgB1 to set position: relative and then move it to place with the top and others. E.g something like so:
#logo img {
position:absolute;
}
.header img.headerpic {
max-width:100%;
top: 10px;
left: 10px;
position: relative !important;
}
<div class="header" id="logo">
<img src="https://placehold.it/200/333333" alt="logo"/>
<img class="headerpic" src="https://placehold.it/100" alt="" />
<div class="infobox"><div class="inner">
</div>
I'm not actually tested this but, if it works thumbs up. I forget to complete my css classes and goes to php and not I have full knowledge of php
margin-left: 25%;
margin-top:25%;
Increase the z-index, case may be that your logo has more z index than img divs
If you want both images to stack on top of each other, what you need to do is to set header as relative and img to absolute like so:
.header{
position: relative;
}
.header img{
position: absolute;
}
<div class="header">
<img class="imgA1" src="https://placehold.it/200/333333">
<img class="imgB1" src="https://placehold.it/100">
</div>
By setting both img.headerpic and img.logo to position:relative, both will occupy their own space and thus won't stack on top of each other.
By defining the parent's position as relative, in this case .header, anything inside .header with an img tag that's positioned absolute will occupy the same space, relative to the parent.
So i have a hexagonal image and when i do ng-repeat i want the result to be as follows.
The width of the container has to be 448px and the images need to be responsive.
This is what i have tried.
CodePen
HTML
<div class="hexagons">
<img src="images/hexagon5.png" alt="">
<img src="images/hexagon6.png" alt="">
<img src="images/hexagon5.png" alt="">
<img src="images/hexagon6.png" alt="">
</div>
CSS
.hexagons {
max-width: 448px;
height: 800px;
position: relative;
}
.hexagons img:nth-child(even) {
position: relative;
top: -115px;
left: 193px;
}
.hexagons img:nth-child(odd) {
position: relative;
}
The result:
Can someone please guide me through this.
This can be achieved by simply offsetting each even elements by half the height of the hexagon, example:
HTML
<div class="hexagons">
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
</div>
CSS
.hexagons {
width: 300px;
}
.hex {
float: left;
width: 150px;
height: 100px;
}
.hex:nth-child(2n) { /* .hex:nth-child(even) works too! */
position: relative;
top: 50px; /* half of 100px */
}
Live example:
http://codepen.io/veksen/pen/GjYKBJ
Your pen corrected: http://codepen.io/veksen/pen/QKkLJg?editors=1100
Note that since images are block elements, I had to set them as blocks, and float them. The container has to be wide enough to accomodate two images (which are 256px wide). The even hexagons also needed to be shifted to the left.
Updated for responsive: http://codepen.io/veksen/pen/XjxWJo?editors=1100
Play with the percentages a bit, but you get the idea!
Well im trying to achieve a basic effect of 6 images placed next to each other ( 2 rows of 3) and want to add some text over them. But the problem is (I think) in the float = left "command" in the CSS, which indeed puts my images nicely next to each other... BUT throws all of my text in the one place instead of nicely with the appropriate image. I've been sitting and thinking on this for solid few days and have no idea what to do. Hope you can help.
CSS
.text {
position: absolute;
z-index: 100;
color: black;
width: 100%;
}
.image {
float: left;
clear: both;
padding: 2px;
position: relative;
}
HTML
<body>
<div class="row" style="width:1600px">
<div class="container">
<img class="image" src="Life.jpg" alt="Life" style="width:520px;height:360px;" />
<p class="text">Life</p>
</div>
<div class="container">
<img class="image" src="Trees are Cool.jpg" alt="Trees Are Cool" style="width:520px;height:360px;" />
<p class="text">Trees are Cool</p>
</div>
<div class="container">
<img class="image" src="Radical dinosaurs.jpg" alt="Radical Dino" style="width:520px;height:360px;" />
<p class="text">Radical Dinosaurs</p>
</div>
<div class="container">
<img class="image" src="Big Round Vuttons.jpg" alt="Big Round Buttons" style="width:520px;height:360px;"/>
<p class="text">Big Round Buttons</p>
</div>
<div class="container">
<img class="image" src="Run.jpg" alt="Run" style="width:520px;height:360px;"/>
<p class="text">Run</p>
</div>
<div class="container">
<img class="image" src="Thats crazy.jpg" alt="That's Crazy" style="width:520px;height:360px;"/>
<p class="text">That's Crazy</p>
</div>
</div>
</body>
Use following css, this will solve your problem
.text {
position: absolute;
z-index: 100;
color: black;
width: 100%;
top: 0;
}
.container {
display: inline-block;
box-sizing: border-box;
padding: 2px;
position: relative;
}
the problem is that you are positioning your image to relative. but your .text is direct child of .container by default .text find it's parent to be position relative but .container has not apply css property position relative then it find .container parent to be position relative and so on, in the end html is position relative that's why all your code stack on the top of each other.
SEE DEMO
try this
.contailer{
position: relative;
}
Add position: relative to the .container class, so it will be the .text element context. The element is positioned in relation to the context.
The context is the last parent that has position: relative / absolute / fixed. Right now the context is probably some higher level container or even the body itself, so all .text items are concentrated there.
It has to do with the position of the elements like other have pointed out
.text {
position: absolute;
z-index: 100;
color: black;
width: 100%;
top: 50px;
left: 50px;
}
.image {
padding: 2px;
position: relative;
}
.container {
float:left;
}
https://jsfiddle.net/xqf8kfd1/1/
Give 'container' class style as follows:
.container {
position: relative;
}
And remove float: left; from 'image' class
try removing the position:absolute and adding float:left to the css text class
.text {
float: left;
z-index: 100;
color: black;
width: 100%;
display: inline-block;
}