column-width property in Multiple column layout - css

Code:
<div class="test">content</div>
.test{
width:500px;
border:1px solid red;
column-width: 100px;
}
I got one column . But I want 4 columns.
Then I added property
column-count: 4;
but column width != 100px . Why ?

Try this Demo:https://jsfiddle.net/9ympv93L/
CSS
-webkit-columns: 4 100px;
-moz-columns: 4 100px;
columns: 4 100px;

u have to set the
.test {
width: 100%;
}

try this
<div class="test">content</div>
.test{
-webkit-column-width: 100px; /* Chrome, Safari, Opera */
-moz-column-width: 100px; /* Firefox */
column-width: 100px;
-webkit-column-count: 4;
-moz-column-count: 4; /* Firefox */
}

Related

Feature query for grid in IE

I'm using a feature query, my goal is to display grid on all browsers except IE. IE doesn't support feature queries, so all code in the feature query will be ignored.
It's working for me in IE, but on Chrome/all other browsers the code outside of the feature query is applying styles, but the feature query is still working like it's displaying grid, but also taking the margin/padding from the code outside of the feature query. Is there a way around this?
feature query
#supports(grid-auto-rows:auto){
.Gallery{
display:-ms-grid;
display:grid;
grid-gap: 5px;
grid-template-columns:repeat(auto-fit, minmax(170px, 1fr));
grid-auto-rows:95px;
grid-auto-flow: dense;
}
.horiz{
-ms-grid-column-span: 2;
grid-column: span 2;
}
.vert{
-ms-grid-row-span: 2;
grid-row: span 2;
}
.big{
-ms-grid-column-span:2;
grid-column:span 2;
-ms-grid-row-span: 2;
grid-row: span 2;
}
.imgContainer {
width: 100%;
height: 100%;
}
.img {
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
}
}
styles outside of the feature query that's being applied
.Gallery {
display: flex;
flex-wrap: wrap;
margin: -1em 0 1em -0.5em;
}
.img {
padding: 1em 0 0 0.5em;
flex: 1 0;
min-width:100%;
height:100%;
}

CSS List with column padding

I have created an unordered list with three columns. The columns touch when going responsive and shrinking the resolution. What can I use to give somesort of padding between them?
.li-3col {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
}
Try using the column-gap property:
.li-3col {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-gap: 40px; /* Chrome, Safari, Opera */
-moz-column-gap: 40px; /* Firefox */
column-gap: 40px;
}
You can learn more about the column-gap property here.

How do i fix this broken CSS Masonry?

I am modifying a pinterest clone script and working on replacing jquery masonry with css masonry, i think have added css values properly, but the masonry is still breaking a bit, can you guys please take a look and let me know what i might be doing wrong?
CSS thats making the masonry work is listed below,
Code:
#grid-container {
max-width:1200px;
-webkit-column-count: 4; /* Chrome, Safari, Opera */
-moz-column-count: 4; /* Firefox */
column-count: 4;
margin: 176px auto 0;
}
#grid-container > .post {
width: 290px;
margin: 0 5px 0;
position: relative;
display: block;
height: auto;
}
Live URL : http://labs.imvges.xyz/
Regards,
Jqn
Setting column-count to 4 will ensure there are always 4 columns, instead of showing the max number of columns based on the post card widths. Use column-width instead. See below for that change and a few others.
#grid-container {
max-width:1200px;
-moz-column-width: 288px;
-webkit-column-width: 288px;
column-width: 288px;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
margin: 176px auto 0;
}
#grid-container > .post {
width: 100%;
margin: 0 5px 0;
display: inline-block;
height: auto;
}

display two columns in the block

I need some help with a problem.
There is a list in the block certain height. Height more than the height of the list, so it is displayed in 2 columns.
I did not get to do so at first filled the first column of the list items, then the second. it looks like this
css
.wrap{
}
.wrap ol{
height: 290px;
width: 500px;
display: block;
outline: 1px solid red;
overflow: hidden;
}
.wrap ol li{
width: 50%;
float: left;
}
An easy way is to use CSS multi-column.
.wrap{
column-count: 2;
-moz-column-count: 2;
-webkit-column-count: 2;
}
See http://jsfiddle.net/aC4Nc/
To increase compatiblity with old browsers, use this polyfill

Responsive Picture Gallery

I'm working on a responsive picture gallery and I'm looking to modify some code I found. I've made a jsFiddle to show you what I'm working with.
jsFiddle
I want to be able to have a couple buttons below each image in the gallery. As you notice, if there is an image underneath an image the image above has its text cut off. I've thought about adding a margin bottom to .box as such:
.box {
float: left;
position: relative;
width: 14.28%;
padding-bottom: 14.28%;
margin-bottom: 30px;
}
jsFiddle with margin-bottom
I'm wondering if there is a better way to approach this. It seems if you re-size the window too small the text overlaps the images.
You just need to make the bottom padding on .box-container 30px:
.box_container {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 10px 10px 30px 10px;
margin-bottom: -35px;
margin-left: 5px;
margin-right: 5px;
}
http://jsfiddle.net/jFwYU/3/
body {
margin: 0;
padding: 0;
background: #EEE;
font: 10px/13px'Lucida Sans', sans-serif;
}
.box {
float: left;
position: relative;
width: 14.28%;
padding-bottom: 10px;
}
.boxInner img {
width: 100%;
}
body.no-touch .boxInner:hover .titleBox, body.touch .boxInner.touchFocus .titleBox {
margin-bottom: 0;
}
#media only screen and (max-width : 480px) {
/* Smartphone view: 1 tile */
.box {
width: 100%;
padding-bottom: 10px;
}
}
#media only screen and (max-width : 650px) and (min-width : 481px) {
/* Tablet view: 2 tiles */
.box {
width: 50%;
padding-bottom: 10px;
}
}
#media only screen and (max-width : 1050px) and (min-width : 651px) {
/* Small desktop / ipad view: 3 tiles */
.box {
width: 33.3%;
padding-bottom: 10px;
}
}
#media only screen and (max-width : 1290px) and (min-width : 1051px) {
/* Medium desktop: 4 tiles */
.box {
width: 25%;
padding-bottom: 10px;
}
}
#media only screen and (max-width : 1590px) and (min-width : 1291px) {
/* Large desktop: 5 tiles */
.box {
width: 20%;
padding-bottom: 10px;
}
}
#media only screen and (max-width : 1920px) and (min-width : 1591px) {
/* Extra large desktop: 6 tiles */
.box {
width: 16.6%;
padding-bottom: 10px;
}
}
1) Removed position:absolute; for boxInner and box_container
2) Avoid using floats and position:absolute; together
3) Only horizontal dimensions should be defined in percentage, not the vertical ones(padding-bottom:33% is not good)
It seems that perhaps the simplest solution for this problem would be to modify the css for the box:
.box {
float: left;
position: relative;
width: 14.28%;
height: 14.28%;
margin-bottom: 40px;
}
height is a much more semantic way than padding-bottom to get what you are looking for, and to make sure the text displays properly (which probably shouldn't be absolutely positioned, but minor issue), add a margin-bottom.
You could also have the margin-bottom as a percent to have it be a percent of the size of the box, say, 20% or so, but px might be a good idea if you're not worried about teeny tiny boxes being an issue (whole gallery less than 50px)
Hope that helps!
I created something to help a college student get started. I adapted your images to the attached code. There are some features that the student needed that you did not ask for, but you can easily remove them.
I believe it meets the intent of preserving the space between images and allows text for each picture. The text is locked to its picture.
The code is not optimized and can certainly be improved, but it will hopefully put you a little closer to what you wanted,
Updated: Example Photo Gallery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Photo Viewer</title>
<style>
html {
border: 0 none transparent;
}
body {
padding: 0;
margin: 0;
font-family: arial, tahoma, sans-serif;
font-weight: 400;
font-size: 15px;
background: #FEFADA;
color: #2C2218;
width: 100%;
height: 100%;
border: none;
text-align: center;
font-style: normal;
font-weight: normal;
font-variant: normal;
cursor: pointer;
}
.picture {
/*Add venfor specific property*/
-webkit-column-count: 4;
/*Set the default to 4 columns*/
column-count: 4;
/*Set text line height*/
line-height: 1.5;
/*Add venfor specific property*/
-webkit-column-gap: 15px;
column-gap: 15px;
/*Outer margin for picture container*/
margin: auto 10px;
}
/*Switch to three columns at this display width*/
#media (max-width: 1024px) {
.picture {
/*Add venfor specific property*/
-webkit-column-count: 3;
column-count: 3;
}
}
/*Switch to two columns at this display width*/
#media (max-width: 764px) {
.picture {
/*Add venfor specific property*/
-webkit-column-count: 2;
column-count: 2;
}
}
/*Switch to one columns at this display width*/
#media (max-width: 480px) {
.picture {
/*Add venfor specific property*/
-webkit-column-count: 1;
column-count: 1;
}
}
.hide {
display: none;
}
.img, .selected-img {
width: 100%;
margin: 8px auto;
white-space: nowrap;
}
.selected-img {
max-width: 1024px;
}
.selected {
position: fixed;
margin: 5px auto;
left: 0;
right: 0;
z-index: 10;
display: block;
}
.closeme {
-webkit-align-content: center;
left: 0;
right: 0;
width: auto;
margin: auto;
display: block;
}
.disable {
background: rgba(0, 0, 0, .3);
width: 100% !important;
height: 100% !important;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 5;
position: fixed;
}
.btn {
border: 1px;
border-color: transparent #D1C89D transparent #D1C89D;
background: #EBE6C1;
height: 40px;
margin: auto 0;
width: 100%;
}
.picture-text {
margin: auto;
padding: 10px 3px;
display: table-cell;
white-space: normal;
}
.inline-block {
display: inline-block;
white-space: nowrap;
}
</style>
</head>
<body>
<div>
<!-- Hide the selected image window until its needed with the hide class -->
<div id="selectedWindow" class="hide">
<button class="closeme btn" onclick="closeWindow()">Click this Button or on the Selected Image to close window.</button>
<!-- Load the selected image here -->
<img id="selectedImage" class="selected-img" onclick="closeWindow()" />
</div>
<button class="btn" onclick="loadImages()">Load Images</button>
<div id="imageContainer" class="picture" onclick="loadSelectedPicture(event)"></div>
<div id="disableMask"></div>
</div>
<script type="application/javascript">
function loadImages() {
// For DEBUG if you need it: alert("Made it to the function");
var element = document.getElementById("imageContainer");
var imageArray = ["http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/1.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/2.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/3.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/4.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/5.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/6.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/7.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/8.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/9.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/10.jpg", "http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/11.jpg"];
var picture = "";
for (var i = 0; i < imageArray.length; i++) {
// Create an id for each image and add its class.
picture += "<div><img id=\"i" + i + "\" class=\"img\" src=\"" + imageArray[i] + "\"><div class=\"inline-block\"><div class=\"picture-text\">Here is some text for each image. How long can this text be before we have some issues.</div></div></div>";
// For DEBUG if you need it: console.log(picture);
}
element.innerHTML = picture;
}
function loadSelectedPicture(event) {
var target = event.target || event.srcElement;
this.stopEventPropagation(event);
var selectedElement = document.getElementById(target.id);
var imageElement = document.getElementById("selectedImage");
if (!selectedElement.src)
return;
imageElement.src = selectedElement.src;
document.getElementById("selectedWindow").className = "selected";
document.getElementById("disableMask").className = "disable";
}
function stopEventPropagation(event) {
if (!event)
event = window.event;
//IE9 & Other Browsers
if (event.stopPropagation) {
event.stopPropagation();
}
//IE8 and Lower
else {
event.cancelBubble = true;
}
}
function closeWindow() {
document.getElementById("selectedWindow").className = "hide";
document.getElementById("disableMask").className = "";
}
</script>
</body>
</html>
I will try to update this post with a working jsFiddle when I have some free time.

Resources