Prison Break | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Prison Break

I have the following code: //HTML <h2>Personal Information</h2> <div> <form> <h2>Work History</h2> <input type="submit" value="Submit"/> </form> </div> //CSS h2 { background-color:blue; } div{ width:50%; } Problem: When this code is run, the width of the background color of the first h2 tag is 100% and the width of the second h2 is also 100% but 100% to the div tag. The div tag is 50% though. Question: I'd like to find a way to make the second h2 tag's width relative to the body tag instead of the div.

10th Apr 2018, 8:58 AM
Ghauth Christians
Ghauth Christians - avatar
9 Answers
+ 5
Try to create another div with width=100% form div width=100% h2 /h2 /div div width=50% input... /div /form
10th Apr 2018, 9:46 AM
Rull Deef đŸș
Rull Deef đŸș - avatar
+ 3
Why not to put h2 outside div?
10th Apr 2018, 9:39 AM
Rull Deef đŸș
Rull Deef đŸș - avatar
+ 3
Or change div's width to 100%
10th Apr 2018, 9:40 AM
Rull Deef đŸș
Rull Deef đŸș - avatar
+ 2
Use pixels instead of percent
10th Apr 2018, 9:13 AM
Rull Deef đŸș
Rull Deef đŸș - avatar
+ 2
if you want 100% h2, create a 100% div. if you need a 50% element, you will do it. the container can not be smaller than its contents, unless you use "position: absolute", but I do not recommend it.
10th Apr 2018, 10:19 AM
‎‏‎‏‎Federico François
‎‏‎‏‎Federico François - avatar
+ 1
Perfect, it works. Thanks Rull Deef. â˜ș
10th Apr 2018, 10:14 AM
Ghauth Christians
Ghauth Christians - avatar
0
You're right Rull but my question was wrong. Please see code below, I'm trying to make "work history" the same length as "personal information" but changing pixels just makes "work history" go to the right. https://code.sololearn.com/Wcp3Bp0k5DK9/?ref=app
10th Apr 2018, 9:26 AM
Ghauth Christians
Ghauth Christians - avatar
0
It can't be place outside because "work history" will have elements too that will be part of the form. The form will contain elements of "personal information" and "work history". There will only be one form but the h2 tags have to be of same length.
10th Apr 2018, 9:43 AM
Ghauth Christians
Ghauth Christians - avatar
0
The form will need to be in a div that's 50% width of the body.
10th Apr 2018, 9:45 AM
Ghauth Christians
Ghauth Christians - avatar