html


CSS: Reset width for items in CSS Grid


We have a legacy section of tiled items that were done with Flexbox. The container of the items is a ul:
ul.icon-grid {
display: flex;
flex-wrap: wrap;
list-style: none;
padding-left: 0;
}
And then the items inside are li:
.icon-swatch__wrapper {
width: 180px;
height: 110px;
text-align: center;
font-size: 12px;
border: 1px solid #ccc;
margin: 5px;
padding: 10px;
}
I had to use a width and height since the tiles have varied content and I needed them to be the same size. Obviously, if I could use css grid I'd have no such problem.
So I am trying to add a scss block inside a #supports for grid, which although it works the fixed width of the items is throwing off the grid gutters.
#supports (display: grid) {
ul.icon-grid {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(4, 1fr);
list-style: none;
padding: 0;
.icon-swatch__wrapper, li {
margin: 0;
width: auto;
}
}
}
I tried using width: auto as you see to remove the previously used width: 180px for the old flexbox version, but the tiles do not properly size to the grid.
If I remove the width: 180px from the flexbox version, the grid version looks perfect. But then if someone has a browser that supports flex but not gris, it looks terrible.
How can I basically "remove" the width: 180px?
With flexbox you need to define the size of flex items. You can use width, height and flex-basis.
With Grid, the approach is different. You can size the items at the container level. No need to define a size on the items.
ul.icon-grid {
display: grid;
grid-template-columns: repeat(4, 180px);
grid-auto-rows: 110px;
grid-gap: 10px;
}

Related Links

<div> padding auto increasing when using table-cell
How do I align these pictures vertically?
html align doesn't work when loop
Iphone square radio button issue
I need to centered element in a form inline
How should i change $.ajax part of code to work it out?
Copying columns of values from Excel worksheet to an HTML table in a website
rvest cannot find node with xpath
How to call HTML button without ID or Name using VBA?
How do we ignore <body scroll=“no”> in MS webbrowser control
Using <embed> to embed an HTML document causes large gap
How can I make a sprite element look selected like regular text?
Regex that makes sure a match starts with a string
framework7 mobile web app not displaying correctly on mobile
bootstrap empty space in ie9
Wrking with transform property ( skew )

Categories

HOME
nativescript
time-series
express
httpurlconnection
xsd
system
torrent
dotvvm
couchbase
dropdown
google-direction
python-asyncio
milo
fuse
github-pages
ghostscript
dhis-2
firebug
stdvector
kettle
data-cleaning
web-console
jdbctemplate
wso2-emm
roles
concat
healpy
rest-client
shellcode
bitrix
sketch-3
http-status-code-403
iexpress
invoice
curses
amqp
google-weave
coinbase
smartthings
mediawiki-templates
variadic-macro
delphi-xe2
bitcore
android-bootstrap-widgets
pngquant
latent-semantic-analysis
opentbs
sakai
macbook
zurmocrm
formcraft
game-ai
buildpath
metro-ui-css
mpmediaitem
number-systems
pyglet
eventemitter
graphing
sendwithus
opalrb
back-button-control
isa
sdp
barcode4j
multiple-databases
swrevealviewcontroller
software-quality
preloadjs
android-install-apk
pyral
bitrise
wireless-connection
session-state
svndump
arc4random
easypie
data-driven-tests
yahoo-pipes
palm-os
activity-lifecycle
regexp-substr
postgresql-8.2
jquery-mobile-checkbox
oracle-commerce
boilerplatejs
cllocationcoordinate2d
flash-cs3
everyplay
session-management
quartz-2d
writeablebitmap
copycopter
ontopia
tool-rec
nsusernotification
sunspot-solr
pdf-to-html
azure-storage-emulator
rvmrc
bada
sketchflow
java-interop
jaxer
gnu-toolchain
sharp-architecture
ghci
lighthouse
umn-mapserver
elips-studio
approval
terminal-services-gateway
ie8-webslice
webapplicationstresstool
instant-message

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App