2018-09-30 23:01:58 +01:00
---
id: 587d78ae367417b2b2512afd
title: Use the flex-basis Property to Set the Initial Size of an Item
challengeType: 0
videoUrl: 'https://scrimba.com/p/pVaDAv/c3d9nCa'
2019-08-05 09:17:33 -07:00
forumTopicId: 301108
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
The < code > flex-basis< / code > property specifies the initial size of the item before CSS makes adjustments with < code > flex-shrink< / code > or < code > flex-grow< / code > .
The units used by the < code > flex-basis< / code > property are the same as other size properties (< code > px< / code > , < code > em< / code > , < code > %< / code > , etc.). The value < code > auto< / code > sizes items based on the content.
< / section >
## Instructions
< section id = 'instructions' >
Set the initial size of the boxes using < code > flex-basis</ code > . Add the CSS property < code > flex-basis</ code > to both < code > #box -1</ code > and < code > #box -2</ code > . Give < code > #box -1</ code > a value of < code > 10em</ code > and < code > #box -2</ code > a value of < code > 20em</ code > .
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
2018-10-20 21:02:47 +03:00
- text: The < code > #box -1</ code > element should have a < code > flex-basis</ code > property.
2019-07-24 03:54:35 -07:00
testString: assert($('#box -1').css('flex-basis') != 'auto');
2018-10-20 21:02:47 +03:00
- text: The < code > #box -1</ code > element should have a < code > flex-basis</ code > value of < code > 10em</ code > .
2019-07-24 03:54:35 -07:00
testString: assert(code.match(/#box -1\s*?{\s*?.*?\s*?.*?\s*?flex-basis:\s*?10em;/g));
2018-10-20 21:02:47 +03:00
- text: The < code > #box -2</ code > element should have the < code > flex-basis</ code > property.
2019-07-24 03:54:35 -07:00
testString: assert($('#box -2').css('flex-basis') != 'auto');
2018-10-20 21:02:47 +03:00
- text: The < code > #box -2</ code > element should have a < code > flex-basis</ code > value of < code > 20em</ code > .
2019-07-24 03:54:35 -07:00
testString: assert(code.match(/#box -2\s*?{\s*?.*?\s*?.*?\s*?flex-basis:\s*?20em;/g));
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'html-seed' >
```html
< style >
#box -container {
display: flex;
height: 500px;
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
#box -1 {
background-color: dodgerblue;
height: 200px;
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
#box -2 {
background-color: orangered;
height: 200px;
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
}
< / style >
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< div id = "box-container" >
< div id = "box-1" > < / div >
< div id = "box-2" > < / div >
< / div >
```
< / div >
< / section >
## Solution
< section id = 'solution' >
2018-11-05 19:09:44 +03:00
2018-11-03 18:21:22 -04:00
```html
< style >
#box -container {
display: flex;
height: 500px;
}
#box -1 {
background-color: dodgerblue;
height: 200px;
flex-basis: 10em;
}
2018-09-30 23:01:58 +01:00
2018-11-03 18:21:22 -04:00
#box -2 {
background-color: orangered;
height: 200px;
flex-basis: 20em;
}
< / style >
< div id = "box-container" >
< div id = "box-1" > < / div >
< div id = "box-2" > < / div >
< / div >
2018-09-30 23:01:58 +01:00
```
2018-11-03 18:21:22 -04:00
2018-09-30 23:01:58 +01:00
< / section >