'Can I order my CSS columns horizontally instead of vertically? Not using float or positioning [duplicate]
Not Using position and float, if any others way please help me Here is Html Code
<div class="column-content">
<div class="single-column" style="height: 220px"></div>
<div class="single-column" style="height: 160px"></div>
<div class="single-column" style="height: 250px"></div>
<div class="single-column" style="height: 150px"></div>
<div class="single-column" style="height: 180px"></div>
<div class="single-column" style="height: 120px"></div>
<div class="single-column" style="height: 140px"></div>
<div class="single-column" style="height: 190px"></div>
</div>
Here is Css Code
.column-content{
column-count: 3;
}
.single-column{
background: purple;
width: 100%;
display: inline-block;
margin-bottom: 20px;
}
Solution 1:[1]
To expand on my comment;
You need to use inline-flex with combinations of widths to achieve your desired result;
.column-content {
width: 100%;
min-width: 100%;
}
.single-column {
width:33%;
min-width:33%;
display: inline-flex;
height: 100px;
min-height: 100px;
background-color: hotpink;
}
This can be tested in my JSFiddle although your heights throw it off
Solution 2:[2]
You can pattern-match also by multiple elements at the beginning of a list (like a:b:xs):
module Main where
import Data.Char
main = print $ unformat "1T3e1s1t" -- [(1,'T'),(3,'e'),(1,'s'),(1,'t')]
unformat :: String -> [(Int, Char)]
unformat (i:c:xs) = (digitToInt i, c) : unformat xs
unformat _ = []
Data.Char.digitToInt converts '0' to 0 and 'f' to 15, for example.
Solution 3:[3]
Here my solution with foldl. In each step we remember prev chars as a Jsut c if it's the first item of tuple or Nothing if it's second item of tuple.
module Main where
import Data.Char
main :: IO ()
main = print $ unformat "1T3e1s1t"
unformat :: String -> [(Int, Char)]
unformat s = snd $ foldl opr (Nothing , []) s
where
opr (prev, acc) c = case prev of
Just n -> (Nothing, acc ++ [(digitToInt n, c)])
Nothing -> (Just c, acc)
The output will be:
[(1,'T'),(3,'e'),(1,'s'),(1,'t')]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Can O' Spam |
| Solution 2 | |
| Solution 3 | S4eed3sm |
