Languages

How to align 2 div tags into left and right without using float?

6 points
Asked by:
Eshaal-Wilkinson
774

I always use float: left and float: right to solve this problem.
Is there a way to solve this in another way?
My code:

This code produce:

How can I get div 1 to left and div 2 to right without using floats?
Example what I want to achieve:

2 answers
8 points
Answered by:
Root-ssh
178290

The best solutions is to use flex.

Put those 2 div's into another div and add to this outer div display flex and justify-content, like this:

Full working example:

If we want to have width of those divs like on your desired example, add width: 100% to both divs.

Note, both classes are the same so we can use only one of them and remove second one. But I understand it is only for better picturing the problem.

0 commentsAdd comment
7 points
Answered by:
Creg
9600

Use display: inline-block with width: calc(50% - 70px).

 

1 comments
Root-ssh
5y
calc(...) is not supported by older browsers so I do not recommend this approach
Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join