There are some extra space on the right side in my gallery...
My images' container:
.my-gallery figure {
display: block;
float: left;
width: 150px;
}
Is it possible make images always horizontal center in different sized screen without using % percent value? Or someone has a genius idea that makes extra space not so weird?
Or % percent value trick is the only way?
In screen A:
In screen B:
.my-gallery {
width: 100%;
float: left;
}
.my-gallery img {
width: 100%;
height: 112px;
}
.my-gallery figure {
display: block;
float: left;
margin: 0 5px 5px 0;
width: 150px;
}
.my-gallery figcaption {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
min-height: 26px;
}
.my-gallery img {
max-width: 100%;
}
<div class="my-gallery">
<figure>
<a href="big1.jpg">
<img src="http://placehold.it/112x150" alt="1" />
</a>
<figcaption>111111111111111111111111</figcaption>
</figure>
<figure>
<a href="big2.jpg">
<img src="http://placehold.it/112x150" alt="2" />
</a>
<figcaption>222222222222222222222222</figcaption>
</figure>
<figure>
<a href="big3.jpg">
<img src="http://placehold.it/112x150" alt="3" />
</a>
<figcaption>3333333333333333333333333333333</figcaption>
</figure>
<figure>
<a href="big4.jpg">
<img src="http://placehold.it/112x150" alt="4" />
</a>
<figcaption>444444444444444444444444</figcaption>
</figure>
...
</div>
If using % is a problem, you could use css flexbox to get this done.
https://jsfiddle.net/76dybc3p/1/
Change css of .my-gallery and remove the float in figure
.my-gallery {
width: 100%;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.my-gallery figure {
display: block;
margin: 0 5px 5px 0;
width: 150px;
}
The most practical approach is to use #media query
I also changed the .my-gallery rule to
.my-gallery {
margin: 0 auto
}
Sample snippet
.my-gallery {
margin: 0 auto
}
.my-gallery img {
width: 100%;
height: 112px;
}
.my-gallery figure {
display: block;
float: left;
margin: 0 5px 5px 0;
width: 150px;
}
.my-gallery figcaption {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
min-height: 26px;
}
.my-gallery img {
max-width: 100%;
}
#media screen and (min-width: 310px) {
.my-gallery {
width: 310px;
}
}
#media screen and (min-width: 465px) {
.my-gallery {
width: 465px;
}
}
#media screen and (min-width: 620px) {
.my-gallery {
width: 620px;
}
}
<div class="my-gallery">
<figure>
<a href="big1.jpg">
<img src="http://placehold.it/112x150" alt="1" />
</a>
<figcaption>111111111111111111111111</figcaption>
</figure>
<figure>
<a href="big2.jpg">
<img src="http://placehold.it/112x150" alt="2" />
</a>
<figcaption>222222222222222222222222</figcaption>
</figure>
<figure>
<a href="big3.jpg">
<img src="http://placehold.it/112x150" alt="3" />
</a>
<figcaption>3333333333333333333333333333333</figcaption>
</figure>
<figure>
<a href="big4.jpg">
<img src="http://placehold.it/112x150" alt="4" />
</a>
<figcaption>444444444444444444444444</figcaption>
</figure>
</div>
I have no idea why you wouldn't use %, but this is another alternative: use a table to scaffold your items and set the property table-layout: fixed;
HTML
<table>
<tr>
<td>
1
</td>
<td>
2
</td>
<td>
3
</td>
</tr>
</table>
CSS
table{
table-layout: fixed;
}
Related
I have a gallery page. I have tiles that are a preset width. Some images fit it exactly, others are too wide and are set to width 100%. I want to center the image in the tile so it will have black bars on the top and bottom
HTML:
<figure class="gallery-tile">
<img src="images/gallery/lulBBQ.JPG" class="gallery-tile-image">
<figcaption class="gallery-tile-description">
Sample Text.
</figcaption>
</figure>
CSS:
.gallery-tile{
display: block;
position: relative;
overflow: hidden;
float:left;
width: var(--halfwebpageWidth);
height: 640px;
background-color: black;
margin: auto;
}
.gallery-tile-image{
display: block;
overflow: hidden;
width: var(--halfwebpageWidth);
margin: auto;
vertical-align: middle;
}
Use display:flex to align your content vertically centered
.gallery-tile {
position: relative;
overflow: hidden;
float: left;
width: var(--halfwebpageWidth);
height: 640px;
background-color: black;
margin: auto;
display: flex;
align-items: center;
}
.gallery-tile-image {
display: block;
overflow: hidden;
width: var(--halfwebpageWidth);
margin: auto;
vertical-align: middle;
}
<figure class="gallery-tile">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSqrfVof7CYYRtsdCu1VD4AWoPB2gs25PP5hQAuhOwhZngrOhsS" class="gallery-tile-image">
<figcaption class="gallery-tile-description">
Sample Text.
</figcaption>
</figure>
Set height,with and line-height properties according to your needs.
figure {
width: 400px;
height: 300px;
line-height:300px;
text-align: center;
border:1px solid red;
}
figure img {
vertical-align: middle;
max-height:250px;
}
figcaption{
line-height:20px;
height:20px;
margin-top:10px;
}
<figure>
<img src="https://www.w3schools.com/html/pic_trulli.jpg" alt="Trulli" style="width:100%">
<figcaption>Fig.1 - Trulli, Puglia, Italy.</figcaption>
</figure>
I'm working on a responsive website. I have tried EVERYTHING and my footer won't stay down. It's because I used float:left. I don't want it to be fixed, i want it only to appear when i scroll to the bottom of the page. This is my code:
EDIT: ok so i took position:absolute out and now it works on the pages it didn't before. but on the pages where i didn't use float:left it doesn't work anymore.
footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 1.2em;
background-color: #24478f;
color: black;
text-align: center;
font-family: Calibri;
font-size: 4vw;
max-width: 100%;
clear: both;
}
#container figure {
width: 100%;
float: left;
display: block;
overflow: hidden;
}
...
#media only screen and (min-device-width: 1000px) {
#container figure {
width: 33%;
display: block;
overflow: hidden;
}
}
<section id="container">
<figure>
<a href="Portfolio.html#applications">
<img src="../imgs/74599-200.png">
</a>
<figcaption>Multimedia Applications</figcaption>
</figure>
<figure>
<a href="Portfolio.html#retrieval">
<img src="../imgs/info1600.png">
</a>
<figcaption>Information Retrieval</figcaption>
</figure>
<figure>
<a href="Portfolio.html#games">
<img src="../imgs/3281-200.png">
</a>
<figcaption>Computer Games</figcaption>
</figure>
</section>
<footer>
<p> Infia Abelha</p>
</footer>
in order to do that you can use min-height for your section like this
#container{min-height:500px}
and set footer position to relative
footer{position:relative}
remove position:absolute and it works
footer {
width: 100%;
height: 1.2em;
background-color: #24478f;
color: black;
text-align: center;
font-family: Calibri;
font-size: 4vw;
clear: both;
}
#container figure {
width: 100%;
float: left;
display: block;
overflow: hidden;
}
...
#media only screen and (min-device-width: 1000px) {
#container figure {
width: 33%;
display: block;
overflow: hidden;
}
}
<section id="container">
<figure>
<a href="Portfolio.html#applications">
<img src="../imgs/74599-200.png">
</a>
<figcaption>Multimedia Applications</figcaption>
</figure>
<figure>
<a href="Portfolio.html#retrieval">
<img src="../imgs/info1600.png">
</a>
<figcaption>Information Retrieval</figcaption>
</figure>
<figure>
<a href="Portfolio.html#games">
<img src="../imgs/3281-200.png">
</a>
<figcaption>Computer Games</figcaption>
</figure>
<div style="clear:both;"></div>
</section>
<footer>
<p> Infia Abelha</p>
</footer>
Is it possible make this layout with pure css without the flexbox properties?
I try to create the photo gallery collage for the VC slider. Is it possible to use here grid properties? I use nesting flexbox, what is the best practice? flexbox gallery collage
<div class="contaner">
<div class="item">
<img src="http://www.telegraph.co.uk/content/dam/pets/2016/05/31/66900964_AR6KDA-CAT-BIRD-PETS-large_trans++XgrBd0P19THPvf9738yRPd-JR69WJ8Rdth_SfFJ_dbY.jpg" alt="" />
</div>
<div class="item item-flex">
<img class="item-flex-img-big" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
<img class="item-flex-img" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
</div>
<div class="item item-flex">
<img class="item-flex-img" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
<img class="item-flex-img-big" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
</div>
<style>
img {
width: 100%;
max-width: 100%;
object-fit: cover;
object-position:50% 50%;
height: 100%;
}
.contaner {
display: flex;
.item {
flex: 1 1 100%;
}
.item + .item {
padding-left: 10px;
}
.item-flex {
display: flex;
flex-direction: column;
}
.item-flex {
img + img {
margin-top:10px;
}
}
.item-flex-img{
height: 40%;
}
.item-flex-img-big{
height: 60%;
}
}
</style>
You may take a look at column CSS.
.contaner {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-rule-width: 5px;
-moz-column-rule-width: 5px;
column-rule-width: 5px;
height: 600px;
width: 1200px;
padding: 15px 15px 0;
overflow: hidden;
}
span {
display: block;
overflow: hidden;
height: calc(40% - 15px);
min-width: 100%;
margin: 0 0 15px;
}
span:nth-child(1) {
height: calc(100% - 15px);
}
span img {
width: 100%;
object-fit: cover;
object-position:50% 50%;
height: 100%;
}
span:nth-child(2),
span:nth-child(5) {
height: calc(60% - 15px);
}
span:nth-child(1) img {
height: 100%;
margin: 0;
object-position:10% 50%;
}
/* snippet purpose */
body {
margin: 0;
}
.contaner {
box-sizing: border-box;
height: 100vh;
width: 200vh;
}
<div class="contaner">
<span><img src="http://www.telegraph.co.uk/content/dam/pets/2016/05/31/66900964_AR6KDA-CAT-BIRD-PETS-large_trans++XgrBd0P19THPvf9738yRPd-JR69WJ8Rdth_SfFJ_dbY.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
</div>
notice: each image are wrapped in a single span all sibblings (could be figure or any tag else)
I need a set of icons grouped under a div to appear to the right of my logo (which is located on the top-left corner). I need the logo and all icons to have a position of relative. I am using float:left for both divs, but the second div (the group of icons) appears below the logo and not to its right. I have also tried grouping them under an unordered list and input style="float:left" as HTML, but it does not work either.
Here is the CSS:
div.container {
width: 1111px;
}
#parent {
display: flex;
}
.logo {
float: left;
position: relative;
top: 0px;
margin-left: 0px;
}
#icons {
position: relative;
float: left;
white-space: nowrap;
width: 100%;
display: table;
max-width: 100%;
}
.all-icons {
position: relative;
float: left;
vertical-align: middle;
padding: 15px;
display: table-cell;
}
.all-icons img {
height: auto;
width: auto;
max-height: 77px;
max-width: 100%;
margin: 15px;
}
<body>
<div class="container">
<div id="parent">
<div class="logo"> <img src="http://placehold.it/77" width="27%" height="27%"> </div>
<div id="icons" style="float:left" class="all-icons">
<img src="http://placehold.it/77" width="389" height="317">
<img src="http://placehold.it/77" width="451" height="317">
<img src="http://placehold.it/77" width="427" height="317">
<img src="http://placehold.it/77" width="837" height="317">
<img src="http://placehold.it/77" width="594" height="317">
</div>
</div>
</div>
</body>
Is this what you look for?
div.container {
/* width: 1111px; */
}
#parent {
display: flex;
}
.logo img {
margin: 15px;
}
.all-icons {
white-space: nowrap;
}
.all-icons img {
margin: 15px;
}
<div class="container">
<div id="parent">
<div class="logo">
<img src="http://placehold.it/77/f00" alt="">
</div>
<div id="icons" class="all-icons">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
</div>
</div>
</div>
If you can't use flex, try display: table
div.container {
/* width: 1111px; */
}
#parent {
display: table;
}
.logo {
display: table-cell;
}
.all-icons {
display: table-cell;
}
.logo img {
margin: 15px;
}
.all-icons {
white-space: nowrap;
}
.all-icons img {
margin: 15px;
}
<div class="container">
<div id="parent">
<div class="logo">
<img src="http://placehold.it/77/f00" alt="">
</div>
<div id="icons" class="all-icons">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
</div>
</div>
</div>
Add #icons { text-align: right; }, i think this will help you.
please do remove #parent { display: flex;} and also remove #icons { width: 100% }
It looks in line to me (see below image) however the margins/padding make it look like it's below and to the right.
Other things which may prove useful having seen your code:
display: inline-table
http://flexboxgrid.com/
remembering to keep CSS files as small as possible, not as comprehensive as possible to make it easy to find and fix things
Your image of logo class not in center of its parent. Add
text-align: center;
margin: auto;
into you .logo class
I'm building an imagegrid containing of 7x3 blocks, but one block need to fill out 2x2. I'd like to use a list since it have to be responsive (the 2x2 should pop out below on mobile). And I try to avoid javascript. But I cant make it work - any ideas ?
big grid:
img img img img img img img
img img img img blck.... img
img img img img blck.... img
mobile grid:
img img img img
img img img img
img img img img
img img img img
blck..............
blck..............
a friend at the office found a nice solution
<html>
<head>
<style>
.images {
width: 100%;
max-width: 1280px;
position: relative;
}
img {
width: 14.285714286%;
height: auto;
float: left;
}
.group {
max-width: 42.857142857%;
float: left;
}
.group img {
width: 33.333333333%;
}
.teaser {
width: 28.571428571%;
background-color: blue;
color: #fff;
text-align: center;
float: left;
padding-bottom: 28.571428571%;
position: relative;
}
.teaser div {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: blue;
}
#media (max-width: 480px) {
img {
width: 25%;
}
.group {
max-width: 75%;
}
.group img {
width: 33.333333333%;
}
.teaser {
position: absolute;
width: 100%;
padding-bottom: 100%;
float: none;
margin-top: 100%;
}
}
</style>
</head>
<body>
<div class="images">
<div class="group">
<img src="http://placehold.it/400x400/EBE824/fff" alt="" />
<img src="http://placehold.it/400x400/CECAA4/fff" alt="" />
<img src="http://placehold.it/400x400/62C6A0/fff" alt="" />
<img src="http://placehold.it/400x400/F8F07E/fff" alt="" />
<img src="http://placehold.it/400x400/0F8B4B/fff" alt="" />
<img src="http://placehold.it/400x400/EFB92B/fff" alt="" />
<img src="http://placehold.it/400x400/63D1D2/fff" alt="" />
<img src="http://placehold.it/400x400/F5C851/fff" alt="" />
<img src="http://placehold.it/400x400/42BFC0/fff" alt="" />
</div>
<img src="http://placehold.it/400x400/C44D58/fff" alt="" />
<img src="http://placehold.it/400x400/FF6B6B/fff" alt="" />
<img src="http://placehold.it/400x400/C7F464/fff" alt="" />
<img src="http://placehold.it/400x400/4ECDC4/fff" alt="" />
<div class="teaser">
<div>follow me now</div>
</div>
<img src="http://placehold.it/400x400/556270/fff" alt="" />
<img src="http://placehold.it/400x400/542437/fff" alt="" />
<img src="http://placehold.it/400x400/53777A/fff" alt="" />
<img src="http://placehold.it/400x400/C02942/fff" alt="" />
</div>
</body>
</html>