I'm trying to create a page where I have image 1 on top and the text at the bottom and image 2 at the bottom and the text on top. I'm not sure how to go about doing it this way.
In my JSFIDDLE I would like "Text 1" to be at the bottom. "Text 2" on top and "Text 3" at the bottom.
my html
<div class="gallery_wrapper">
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/QuLaaLb.jpg">
</div>
<div class="gallery_title">
<h2>
Text 1
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 2
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/QuLaaLb.jpg">
</div>
<div class="gallery_title">
<h2>
Text 3
</h2>
</div>
</div>
JSFIDDLE
This should help you get started. You can use flex and pseudo-properties to achieve this.
.gallery_wrapper {
display: flex;
}
.gallery {
background: #333333;
}
.gallery:nth-child(even) {
display: flex;
flex-direction: column-reverse;
}
.gallery_title {
color: #fff
}
<div class="gallery_wrapper">
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 1
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 2
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 3
</h2>
</div>
</div>
</div>
You can use flexbox for your requirement.
In flexbox there are two properties with which you can solve your issue. Either using order or using flex-direction. But flex-direction is for parent and order is for child. So you can use any of the properties to solve your problem.
In this example snippet, I use order.
.item {
display: flex;
flex-direction: column;
}
.text {
font-size: 20px;
}
.image {
display: flex;
width: 200px;
height: 200px;
background-image: url('https://files.allaboutbirds.net/wp-content/themes/html5blank-stable/images/blue-winged-warbler.jpg');
background-size: cover;
background-repeat: no-repeat;
}
.item:nth-child(2n) .text {
order: 2;
}
<section>
<div class="item">
<span class="text">Text 1</span>
<span class="image"></span>
</div>
<div class="item">
<span class="text">Text 2</span>
<span class="image"></span>
</div>
<div class="item">
<span class="text">Text 3</span>
<span class="image"></span>
</div>
</section>
You can add the following CSS to achieve this.
.gallery{
position: relative;
}
.gallery_title{
position: absolute;
bottom: 5px;
left: 0;
}
.gallery:nth-child(even) .gallery_title{
bottom: auto;
top: 5px;
}
Check the link here jsfiddle
Related
I'm trying to achieve this, where brown gets pushed down when pink is too long, and pink is dynamically sized based on its text content.
I was only able to achieve this using javascript and two templates, if pink length is over X use second template, but I'm wondering if there's a way to achieve this using CSS only?
I tried meddling with grid auto-fill/auto-fit with minmax, float, flex with wrap, but I couldn't get to the desired result with these.
.parent {
width: 170px;
}
.flex {
display: flex;
}
div {
outline: 2px solid rgba(255, 0,0, 0.3);
}
<div>
<p>scenario A</p>
<div class="parent flex">
<div>
<div class="one">A short title</div>
<div class="three">Some text here</div>
<div class="three">some more text</div>
</div>
<div>
<button>A button</button>
</div>
</div>
</div>
<div>
<p>scenario B</p>
<div class="parent">
<div class="one">Testing a very long title</div>
<div class="flex">
<div>
<div class="three">Some text here</div>
<div class="three">some more text</div>
</div>
<div>
<button>A button</button>
</div>
</div>
</div>
</div>
<p>can a component achieve both a and b with only css?
I found a solution, it requires having fixed height in the first row, and the right side button will basically overflow when needed.
Will wait a bit before accepting my own solution in case someone came with a better one.
.container {
width: 300px;
display: flex;
gap: 10px;
padding: 16px;
font-size: 14px;
font-family: Arial;
}
.text {
flex: 1;
min-width: 0;
}
.first-row {
height: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
.image {
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #444;
}
.title {
flex-grow: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<h2>Long title</h2>
<div class="container">
<div class="image"></div>
<div class="text">
<div class="first-row">
<div class="title">Test title test title test title</div>
<button>Visit store</button>
</div>
<div class="three">in the stores</div>
<div class="three">sponsored</div>
</div>
</div>
<h2>Short title</h2>
<div class="container">
<div class="image"></div>
<div class="text">
<div class="first-row">
<div class="title">Short title</div>
<button>Visit place</button>
</div>
<div class="three">in the stores</div>
<div class="three">sponsored</div>
</div>
</div>
<h2>Very long title</h2>
<div class="container">
<div class="image"></div>
<div class="text">
<div class="first-row">
<div class="title">Test title test titleTest title test titleTest title test title</div>
<button>Visit place</button>
</div>
<div class="three">in the stores</div>
<div class="three">sponsored</div>
</div>
</div>
im so clueless in css,I have a loader,when i click the function it just starts below the image ina div which is so ugly,i want it to come over, it any idea?
<div class="card" (click)="SendToBank($event)">
<div class="k-block" *ngIf="loadingSpinner">
<div class="spinner-border text-info" role="status" >
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="card-body">
<img class="bank-logo" src="../assets/Img/2.png" id="seb">
<span> SEB</span>
</div>
</div>
any idea how i can achieve that?
Well you just need to position it fixed and style it a little bit.
Read more here css position
I left out the Angular related code.
.k-block {
position:fixed;
display:flex;
width: 100%;
height: 100%;
left:0;
top:0;
align-items: center;
justify-content: center;
background: rgba(0,0,0,0.5)
}
<div class="card">
<div class="k-block">
<div class="spinner-border text-info" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="card-body">
<img class="bank-logo" src="../assets/Img/2.png" id="seb">
<span> SEB</span>
</div>
</div>
I am trying to display an array list from left to right with a div scroll. But it become top to bottom. How should I do to solve it? This my demo code as you reference.
HTML
<div>
<h2 class="ylet-primary-500 alignleft">Sessions</h2>
</div>
<div style="clear: both;"></div>
<div *ngFor="let batch of batches">
<div class="box">
<div>
<h3 class="classes">
{{batch.month}}
<span class="chips"> </span>
</h3>
</div>
<div style="clear: both;">
<p class="timings">
<mat-icon matPrefix>access_time</mat-icon><span>{{batch.time}}</span>
<span class="slots"> <mat-icon>list_alt</mat-icon>{{batch.slots}}</span>
</p>
</div>
</div>
</div>
CSS
.box {
border: 1px solid #ccc;
padding: 4px;
width: 70%;
direction: rtl;
display: inline-block;
}
Try to wrap loop div container with div container and add css flex style.
<div class="container">
<div *ngFor="let batch of batches">
<div class="box">
<div>
<h3 class="classes">
{{batch.month}}
<span class="chips"> </span>
</h3>
</div>
<div style="clear: both;">
<p class="timings">
<mat-icon matPrefix>access_time</mat-icon><span>{{batch.time}}</span>
<span class="slots"> <mat-icon>list_alt</mat-icon>{{batch.slots}}</span>
</p>
</div>
</div>
</div>
.container {
display: flex;
flex-wrap: wrap;
}
I want to show tooltips next to items in a rather complex editor with custom scrolling. The tooltips should "escape" the container that has overflow: hidden set to limit the viewport.
Here is an example that shows the problem:
.container {
border: 1px black solid;
width: 200px;
height: 200px;
overflow: hidden;
}
.inner {
display: flex;
flex-direction: column;
}
.row {
display: flex;
}
.column {
background-color: #99FF99;
padding: 25px;
}
.tooltip-container {
position: relative;
}
.content {
background-color: #9999FF;
width: 50px;
height: 50px;
}
.tooltip {
z-index: 1;
background-color: #FF9999;
display: none;
position: absolute;
left: 100%;
top: 0%;
white-space: nowrap;
}
.tooltip-container:hover .tooltip {
display: inline-block;
}
<div class="container">
<div class="inner" id="inner" style="margin-left: -40px; margin-top: -40px">
<div class="row">
<div class="column">
<div class="tooltip-container">
<div class="content">
1
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 1
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
2
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 2
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
4
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 4
</div>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="tooltip-container">
<div class="content">
3
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 3
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
5
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 5
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
6
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 6
</div>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="tooltip-container">
<div class="content">
7
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 7
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
8
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 8
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
9
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 9
</div>
</div>
</div>
</div>
</div>
</div>
JSFiddle
Of course I searched for the problem and there are a lot solutions to the problem already. However I did not find one that solves my problem
The most cited solution is to make the tooltip position: absolute and add a wrapper outside of the div with overflow:hidden as can be seen here. This does not work in my case because the tooltip should be to the right of the item it describes. So I need the relative position on the tooltip container.
I tried wrapping the tooltip with position:relative and some offset in a wrapper with position:absolute. This did not work, as the wrapper catches the mouse hover for the tooltip. Also this means I have to know the size of the attached item.
I tried laying out the items in the tooltip-container horizontally and then use the standard position:absolute trick, but I could not make that work either.
Does anybody have an idea?
Constraints:
the tooltip appears in a container which has overflow:hidden and should escape it
the content in the container can be moved around
there are no fixed sizes
if possible it should be a CSS only solution (but most definitely no jQuery)
the tooltip should appear to the right of the attached item (bonus points if it can appear to any side of the item)
the tooltip may not only contain text but also other controls and inputs
The only CSS trick you can use is the position:fixed that you block with a null transform and you can have most of your constraints:
body {
min-height:200vh;
transform:translate(0,0);
}
.container {
border: 1px black solid;
width: 200px;
height: 200px;
overflow: hidden;
}
.inner {
display: flex;
flex-direction: column;
}
.row {
display: flex;
}
.column {
background-color: #99FF99;
padding: 25px;
}
.tooltip-container {
position: relative;
}
.content {
background-color: #9999FF;
width: 50px;
height: 50px;
}
.tooltip {
z-index: 1;
background-color: #FF9999;
display: none;
position: fixed;
transform:translate(50px,-50px);
/*left: 100%;
top: 0%;*/
white-space: nowrap;
}
.tooltip-container:hover .tooltip {
display: inline-block;
}
<div class="container">
<div class="inner" id="inner" style="margin-left: -40px; margin-top: -40px">
<div class="row">
<div class="column">
<div class="tooltip-container">
<div class="content">
1
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 1
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
2
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 2
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
4
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 4
</div>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="tooltip-container">
<div class="content">
3
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 3
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
5
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 5
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
6
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 6
</div>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="tooltip-container">
<div class="content">
7
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 7
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
8
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 8
</div>
</div>
</div>
<div class="column">
<div class="tooltip-container">
<div class="content">
9
</div>
<div class="tooltip">
Super nice and awesome and cool and hot 9
</div>
</div>
</div>
</div>
</div>
</div>
I've seen this thread but its for 2 column (col-md-6) and I've tried the jsfidlle too for 3 column but column 1st and column 2nd become stack.
Bootstrap 3 Align Text To Bottom of Div
what I want for my project is
.row {
position: relative;
}
.bottom-align-text {
position: absolute;
bottom: 0;
right: 0;
}
<div class="container">
<div class="row">
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
<div class="col-sm-4">
<img src="//placehold.it/600x300" alt="Logo" class="img-responsive"/>
</div>
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
</div>
</div>
how to make them both align bottom?
flexbox can do that
.row div {
border: 1px solid red;
}
.flexy {
display: flex;
text-align: center;
}
.flexy .bottom-align-text {
display: flex;
justify-content: center;
align-items: flex-end;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row flexy">
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
<div class="col-sm-4">
<img src="//placehold.it/600x300" alt="Logo" class="img-responsive" />
</div>
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
</div>
</div>
You can wrap column 1st and column 2nd in to a row then we'll have 2 columns structure. See my jsFiddle demo: https://jsfiddle.net/robinhuy/kg1ykfL1/3/