I currently have a CSS grid with a dynamic number of rows where there are subsets of the rows that should be grouped together. I'd like to wrap the first column of those groups together with a drop shadow, but I can't figure out how to do this. I'm able to accomplish what I want with a border, because I'm able to drop the top and bottom border of the middle elements.
Is there a way to do this with or without a grid layout?
.grid {
display: grid;
grid-template-columns: 250px 250px 250px;
grid-column-gap: 20px;
}
.top,
.middle,
.bottom {
border: 2px solid black;
}
.top {
border-bottom: none;
}
.middle {
border-top: none;
border-bottom: none;
}
.bottom {
border-top: none;
}
.title {
text-align: center;
padding: 5px 20px;
}
.title span {
margin: 0 20px;
}
.title,
.details,
.actions {
text-align: center;
vertical-align: middle;
margin: auto 0;
}
<div class="grid">
<span class="top title">
<span>row 1 title</span>
</span>
<span class="details">row 1 details</span>
<span class="actions">row 1 actions</span>
<span class="middle title">
<span>row 2 title</span>
</span>
<span class="details">row 2 details</span>
<span class="actions">row 2 actions</span>
<span class="middle title">
<span>row 3 has an extra long tile that wraps around</span>
</span>
<div class="details">row 3 details</div>
<span class="actions">row 3 actions</span>
<span class="bottom title">
<span>row 4 title</span>
</span>
<span class="details">row 4 details</span>
<span class="actions">row 4 actions</span>
<span class="top title">
<span>row 5 title</span>
</span>
<span class="details">row 5 details</span>
<span class="actions">row 5 actions</span>
<span class="bottom title">
<span>row 6 title</span>
</span>
<span class="details">row 6 details</span>
<span class="actions">row 6 actions</span>
</div>
There is no way to apply styles to all grid items in a specific column or row or group them for that matter. You are already doing the possible option to target the elements directly.
Hacky solution
Here I'm going to use the fact that you are using top, middle and bottom clases and creating and effect of box shadow:
use a convenient box-shadow to a pseudo element placed behind the grid items in the first column,
use background on the grid item to match the column and therefore hiding from view the shadow in between rows,
now use a margin to separate at the bottom class.
.grid {
display: grid;
grid-template-columns: 250px 250px 250px;
grid-column-gap: 20px;
}
.top:after,
.middle:after,
.bottom:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
box-shadow: 0 0px 10px 2px #ddd;
background: #fff;
}
.title.bottom {
margin-bottom: 15px;
background: transparent;
}
.title {
text-align: center;
position: relative;
padding: 5px 20px;
background: #fff;
}
.title span {
margin: 0 20px;
}
.title,
.details,
.actions {
text-align: center;
vertical-align: middle;
margin: auto 0;
}
<div class="grid">
<span class="top title">
<span>row 1 title</span>
</span>
<span class="details">row 1 details</span>
<span class="actions">row 1 actions</span>
<span class="middle title">
<span>row 2 title</span>
</span>
<span class="details">row 2 details</span>
<span class="actions">row 2 actions</span>
<span class="middle title">
<span>row 3 has an extra long tile that wraps around</span>
</span>
<div class="details">row 3 details</div>
<span class="actions">row 3 actions</span>
<span class="bottom title">
<span>row 4 title</span>
</span>
<span class="details">row 4 details</span>
<span class="actions">row 4 actions</span>
<span class="top title">
<span>row 5 title</span>
</span>
<span class="details">row 5 details</span>
<span class="actions">row 5 actions</span>
<span class="bottom title">
<span>row 6 title</span>
</span>
<span class="details">row 6 details</span>
<span class="actions">row 6 actions</span>
</div>
Related
Let's say I have a text and every letter is a span with display: inline-block;:
<div>
<span class="item">A</span>
<span class="item">A</span>
<span class="item">A</span>
<span class="item"> </span>
<span class="item">A</span>
<span class="item">B</span>
<span class="item">C</span>
<span class="item"> </span>
<span class="item">A</span>
<span class="item">B</span>
<span class="item">C</span>
<span class="item">D</span>
<span class="item">E</span>
<span class="item">F</span>
<span class="item"> </span>
<span class="item">A</span>
<span class="item">B</span>
</div>
.item {
display: inline-block;
font-size: 70px;
}
By default, if the screen is viewport is smaller it will break on any letter. I would like to break on spaces, but without removing the inline-block as I need it for something else
Here is a solution with the text inside div elements and the following CSS added:
#wrapper {
display: flex;
flex-wrap: wrap;
}
.text-wrapper {
display: flex;
}
Demo:
#wrapper {
display: flex;
flex-wrap: wrap;
}
.text-wrapper {
display: flex;
}
.item {
display: inline-block;
font-size: 70px;
}
<div id="wrapper">
<div class="text-wrapper">
<span class="item">A</span>
<span class="item">A</span>
<span class="item">A</span>
<span class="item"> </span>
</div>
<div class="text-wrapper">
<span class="item">A</span>
<span class="item">B</span>
<span class="item">C</span>
<span class="item"> </span>
</div>
<div class="text-wrapper">
<span class="item">A</span>
<span class="item">B</span>
<span class="item">C</span>
<span class="item">D</span>
<span class="item">E</span>
<span class="item">F</span>
<span class="item"> </span>
</div>
<div class="text-wrapper">
<span class="item">A</span>
<span class="item">B</span>
</div>
</div>
This question already has answers here:
Make background color extend into overflow area
(4 answers)
Closed 3 years ago.
edit: Not sure this is a duplicate? I don want the background color to extend past the width of the container, I want the container to expand to the size of its display: grid child. Updated the example to better explain my problem.
I am building a table where each row is a css grid. I have done this to leverage the minmax() of each cell, to make the whole table scrollable when its cells can't shrink anymore, while allowing the table to grow if more space is available.
This works fine besides the fact that the styling for the rows only apply to the width of the container.
Please see this example:
.container {
width: 430px;
background: grey;
overflow-x: scroll;
}
.row {
display: grid;
grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(200px, 1fr) minmax(100px, 1fr);
background: red;
height: 3rem;
margin: 0.5rem;
}
.cell {
border: 1px solid black;
}
Scroll to the right inside the box:
<div class="container">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
Elements with the <code>.row</code> class should expand to fit all the cells.
Is there any way to solve this? I'm fine with adding extra elements if need be!
Changing the display of the rows to inline-grid seems to help:
.container {
width: 430px;
background: grey;
overflow-x: scroll;
}
.row {
display: inline-grid;
grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(200px, 1fr) minmax(100px, 1fr);
background: red;
height: 3rem;
}
.cell {
border: 1px solid black;
}
Scroll to the right inside the box:
<div class="container">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
The red background should cover the whole row.
Update 1
To avoid problems with wide container/narrow children getting in one line (as with the solution above), you can use a more convoluted solution, which uses a display: flex; flex-direction: column on the parent, with additional align-items: start that forces the row items to have full width (as opposed to default stretch, which makes the row width no wider than the container).
.container {
width: 430px;
background: grey;
overflow-x: scroll;
display: flex;
flex-direction: column;
align-items: start;
}
.container.container-wide{
width: 1000px;
}
.row {
display: grid;
grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(200px, 1fr) minmax(100px, 1fr);
background: red;
height: 3rem;
}
.cell {
border: 1px solid black;
}
Scroll to the right inside the box:
<div class="container">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
Wide container:
<div class="container container-wide">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
The red background should cover the whole row.
Update 2
To allow for stretch of the row to the full width of the container in case it is wider than the sum of all columns, it is possible to adjust the solution from Update 1 by replacing the display: flex with display: grid, see example below:
.container {
width: 430px;
background: grey;
overflow-x: scroll;
display: grid;
}
.container.container-wide{
width: 1000px;
}
.row {
display: grid;
grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(200px, 1fr) minmax(100px, 1fr);
background: red;
height: 3rem;
}
.cell {
border: 1px solid black;
}
Scroll to the right inside the box:
<div class="container">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
Wide container:
<div class="container container-wide">
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
<div class="row">
<span class="cell">cell 1</span>
<span class="cell">cell 2</span>
<span class="cell">cell 3</span>
<span class="cell">cell 4</span>
</div>
</div>
The red background should cover the whole row.
If you need to fill grid-template-columns with cell width, you should try:
.row {
display: grid;
grid-template-columns: auto auto auto auto;
background: red;
height: 3rem;
}
For 200px width on each cell, just add:
.cell {
min-width: 200px;
border: 1px solid black;
}
I'm trying to achieve the following:
I'm using float:left to have a span containing the user name floating to the right of the big numbers to the left.
This is what I have so far: https://jsfiddle.net/d00ck/twcmfzo8/2/
body {
font-family: arial;
}
.container {
background-color: white;
padding-bottom: 15px width: 360px;
}
.position {
clear: both;
margin: 10px 0 10px 0;
padding: 0 10px 0 10px;
width: 100%;
}
.ranking-position {
font-size: 25px;
float: left;
}
.ranking-tier {
display: block;
}
.ranking-score {
clear: both;
}
<div class="container">
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">Dorothy Bradley</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
</div>
I'm obviously missing something important since I can't seem to make the span containing the "1000pts" legend to float to the right of the big number. Any help would be greatly appreciated.
You just need to change
.ranking-tier {
display: block;
}
to this:
.ranking-name {
display: block;
}
Something like this:
HTML:
<div class="container">
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">Dorothy Bradley</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
</div>
CSS:
body {
font-family: arial;
}
.container{
background-color: white;
padding-bottom: 15px
width: 360px;
}
.position {
clear: both;
margin: 10px 0 10px 0;
padding: 0 10px 0 10px;
width: 100%;
}
.ranking-position {
font-size: 25px;
float: left;
}
.ranking-score {
clear: both;
}
.ranking-name {
display:block;
}
https://jsfiddle.net/twcmfzo8/5/
First of all add a semicolon in the .container definition in CSS, after the padding-bottom. and add float:right; margin-top:-20px; in .ranking_score
Try this One:
<div class="position">
<div style="display:inline-block; float:left;">
<span class="ranking-position">1</span>
<span class="ranking-name">Dorothy Bradley</span>
<span class="ranking-tier">1rs Team All...</span>
</div>
<div style="float:right; display:inline-block;">
<span class="ranking-score" style="position:relative; top:20px;">1000pts</span>
</div>
</div>
That's because the float is not tall enough to affect the three spans. You can try forcing some height
.container {
font-family: arial;
}
.position {
overflow: hidden;
margin: 10px 0 10px 0;
padding: 0 10px 0 10px;
}
span {
display: block;
font-size: 16px;
line-height: 1.25em;
height: 1.25em;
}
.ranking-position {
font-size: 25px;
height: 60px; /* 16px * 1.25 * 3 */
float: left;
}
<div class="container">
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">Dorothy Bradley</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
<div class="position">
<span class="ranking-position">1</span>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
</div>
Or wrap them inside a flock formatting context root:
.container {
font-family: arial;
}
.position {
overflow: hidden;
margin: 10px 0 10px 0;
padding: 0 10px 0 10px;
}
.ranking-position {
font-size: 25px;
float: left;
}
.position > div {
overflow: hidden;
}
span {
display: block;
}
<div class="container">
<div class="position">
<span class="ranking-position">1</span>
<div>
<span class="ranking-name">Dorothy Bradley</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
</div>
<div class="position">
<span class="ranking-position">1</span>
<div>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
</div>
<div class="position">
<span class="ranking-position">1</span>
<div>
<span class="ranking-name">User Name</span>
<span class="ranking-tier">1rs Team All...</span>
<span class="ranking-score">1000pts</span>
</div>
</div>
</div>
I am trying to align some font element vertically in a list.
I tried a bunch of thing such as playing with the vertical-align property and setting the same font-size / line-height.
I saw an interesting answer here however it seems that the base line of the label is vertically align with the icon and not the whole text itself.
ul {
list-style : none
}
.list-item__content {
padding: 10px;
border: 1px solid black;
}
.icon {
font-size: 14px;
line-height: 14px;
vertical-align: middle;
}
.label {
//vertical-align: middle;
font-size: 14px;
line-height: 14px;
}
<link href="https://file.myfontastic.com/tYAxi8yq9HQugtnVmUJTNm/icons.css" rel="stylesheet">
<ul class="list">
<li class="list-item">
<div class="list-item__content">
<span class="icon icon-bell"></span>
<span class="label">
aaaaaa
</span>
</div>
</li>
<li class="list-item">
<div class="list-item__content">
<span class="icon icon-bookmark"></span>
<span class="label">
bbbbbb
</span>
</div>
</li>
<li class="list-item">
<div class="list-item__content">
<span class="icon icon-briefcase"></span>
<span class="label">
cccccc
</span>
</div>
</li>
</ul>
Here is my clean playground, it is kind of tough because I don't want to use flexbox for compatibility issue, and I can't afford to play with the padding/margin/line-height for each element because I need a generic solution.
Looking forward to any tips or tricks you have!
Try setting the properties directly on the pseudo :before element (which the icon uses).
.icon:before, .label {
vertical-align: middle;
font-size: 14px;
line-height: 1;
}
Updated jsfiddle
ul {
list-style : none
}
.list-item__content {
padding: 10px;
border: 1px solid black;
}
.icon:before, .label {
vertical-align: middle;
font-size: 14px;
line-height: 1;
}
<link href="https://file.myfontastic.com/tYAxi8yq9HQugtnVmUJTNm/icons.css" rel="stylesheet">
<ul class="list">
<li class="list-item">
<div class="list-item__content">
<span class="icon icon-bell"></span>
<span class="label">
aaaaaa
</span>
</div>
</li>
<li class="list-item">
<div class="list-item__content">
<span class="icon icon-bookmark"></span>
<span class="label">
bbbbbb
</span>
</div>
</li>
<li class="list-item">
<div class="list-item__content">
<span class="icon icon-briefcase"></span>
<span class="label">
cccccc
</span>
</div>
</li>
</ul>
I have tried a lot things but not able to get desired format.
HTML:
<div class="usertype">
<div class="type1">
<span class="type-heading">type1 is here</span>
<span class="type-description">10 types have joined</span>
<span class="type-description">35 type will.</span>
</div>
<div class="type2">
<span class="type-heading">type2 is here</span>
<span class="type-description">10 types are there</span>
<span class="type-description">35 type will.</span>
</div>
<div class="type1">
<span class="type-heading">type23 is good</span>
<span class="type-description">50 types are there</span>
<span class="type-description">50 types are there</span>
<span class="type-description">for 2 months</span>
</div>
<div class="type2">
<span class="type-heading">Type4 at last</span>
<span class="type-description">50 types are there</span>
<span class="type-description">makes their first $20</span>
<span class="type-description">50 types are there</span>
<span class="type-description">35 type will.</span>
</div>
</div>
CSS:
div.usertype {
margin-top: 1em;
}
div.type1 {
float: left;
margin-left: 2em;
}
span.type-heading {
font-size: 14px;
color: #f7f7f7;
}
span.type-description {
font-size: 14px;
color:#959595;
display: block;
}
Output:
What I want:
Decrease the vertical distance between spans with class type-description. I tried using line-height and padding-bottom but could not move it. May be some parent div has display:block.
All type description aligned to left which are now center. If I use it float: left, it ruins the format completely.
Please help.
<div class="usertype">
<div class="type1">
<span class="type-heading">type1 is here</span>
<span class="type-description">10 types have joined</span>
<span class="type-description">35 type will.</span>
</div>
<div class="type2">
<span class="type-heading">type2 is here</span>
<span class="type-description">10 types are there</span>
<span class="type-description">35 type will.</span>
</div>
<div class="type1">
<span class="type-heading">type23 is good</span>
<span class="type-description">50 types are there</span>
<span class="type-description">50 types are there</span>
<span class="type-description">for 2 months</span>
</div>
<div class="type2">
<span class="type-heading">Type4 at last</span>
<span class="type-description">50 types are there</span>
<span class="type-description">makes their first $20</span>
<span class="type-description">50 types are there</span>
<span class="type-description">35 type will.</span>
</div>
</div>
<style>
div.usertype {
margin-top: 1em;
}
div.type1 {
float: left;
margin-left: 2em;
}
div.type2 {
float: left;
margin-left: 2em;
}
span.type-heading {
font-size: 14px;
color: #f7f7f7;
}
span.type-description {
font-size: 14px;
color:#959595;
display: block;
line-height:15px;
}
</style>