Sometimes we need to combine percentages and fixed values โโto calculate sizes, especially when it comes to creating some flexible layouts. As far as I know, I found only two ways to achieve the desired effect in pure CSS.
Problem
Letโs take a quick look at the problem - we need to create a two-column layout, stretched to the entire width of the page, where one of the columns has a constant width.
<section> <article>I fill out all the available space!</article> <aside>I'm 50px width!</aside> </section>
Solution 1 - Using calc ()
Example: FIDDLE
The calc() function allows us to combine percentage and fixed values, for example:
article { width: calc(100% - 50px); }
Unfortunately, this is not a cross-browser solution ( http://caniuse.com/#search=calc ) and it is recommended to use backups ( http://html5please.com/#calc ).
Solution 2 - fixed layout table for browser
Example: FIDDLE
The width of each column in the table is automatically calculated by default and depends on the contents of the cells. To solve the problem, we need to force the size of the column, so another solution uses a table with the table-layout property set to fixed . It allows you to set the width of any column. I changed the HTML structure, but it can also be achieved by manipulating with the display property ... (ugly example: FIDDLE )
Summary
This is a very common problem in a responsive world, and I am very curious if there are any other ideas on how to resolve it in pure CSS and HTML. Any thoughts on this would be appreciated.
Sincerely.
EDIT
Thank you all for your input! I agree that the problem I showed was too simple :)
You can find further discussion of this subject here .
source share