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

Override CSS Classes Infinitely
Vertical spacing textboxes with Bootstrap form-horizontal
Vertical line with text around
Bootstrap dropdown styles weird on dropdown
translatex with transition not work smooth in RTL mode
Using Accelerated Mobile Pages with Bootstrap
Robohelp: How to reference a .chm file rather than copy it into a merged project?
How do you print every match of a RegEx to a different file?
Inserting select box in the CKEditor Text Area
Append additional HTML result in calling MVC action by Ajax in DNN8
Is there any relationship between swt components and html components
Show each product in aside while hover
ck-editor changes html codes of non-ascii characters to actual characters
Having trouble aligning my table header (two items in a column are overlapping)
HTML CSS horizontally align the middle of a div to another div side
My nested dropdown menus are not coming on bringing mouse over in navigation bar while designing a website

Categories

HOME
osx
exception
uiimageview
asp.net-core-mvc
ace-editor
random
vpn
finance
rxandroidble
credentials
geode
nested
navicat
oracle-jet
draw.io
llvm-clang
imagej
logstash-forwarder
youtrack
mysql-python
vertices
pool
key-value
azure-automation
control
intro.js
flash-builder
google-material-icons
ipv4
compiler-optimization
intern
filereader
ansible-tower
intl-tel-input
welcome-file
android-seekbar
upsource
aptana3
gantt-chart
elasticsearch-2.0
pkg-config
lansa
mule-el
oledbconnection
pyglet
ansi-sql
nssm
logistics
python-packaging
flask-potion
substr
ui-sref
tclsh
sjcl
hy
azure-vpn
aws-ec2
wireless-connection
fann
weechat
scaletransform
normalize
openimaj
thinktecture
hector
gwt-super-dev-mode
multi-table
boolean-operations
subform
prawn
webp
tanuki
flash-media-server
gui-testing
jcaps
horn
cruisecontrol
rman
webfaction
httpfilecollection
hit-highlighting
render-to-string
novell-idm
instant-message
desktop-search

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