Place a div next to each other

Asked

Viewed 49,805 times

2

I’m having a little problem with CSS, I wanted a div to side with each other. I’ve tried to float both, but if I do this the footer div goes up. What I do?

#DivRodape{
position: absolute;
top: auto;
height: 35px;
line-height: 35px;
text-align: center;
width: 100%;
background-color:#004085;
}


#DivLateral{
position:relative;
border-width:2px;
width:300px;
height: 700px;
background-color: peachpuff;
}

#DivA{
position: relative;
border-width:2px;
width:auto;
height: auto;
left:300px;

}

3 answers

3


@J.Jones you have to use the clear:both in the group to break the flotation when using Float in the elements. To solve your problem I created a Div on the outside called . group and in it I created a pseudoelement ::after and used the style clear:both to clear the flotation and play the rodape down. Take a look at the code you’ll understand.

OBS I made a few changes to your CSS just to get a better look at what was done.

Click on EXECUTE to see the code working

#DivRodape{
    position: absolute;
    top: auto;
    height: 35px;
    line-height: 35px;
    text-align: center;
    width: 100%;
    background-color:#004085;
}
#DivLateral{
    position:relative;
    border-width:2px;
    width:100px;
    height: 100px;
    background-color: peachpuff;
    float: left;
}
#DivA{
    position: relative;
    border-width:2px;
    width: 100px;
    height: 100px;
    left:0px;
    background-color: red;
    float: left;
}
.group:before,
.group:after {
    content: "";
    display: table;
} 
.group:after {
    clear: both;
}
.group {
     zoom: 1; /* For IE 6/7 (trigger hasLayout) */
}
<div class="group">
    <div id="DivA"></div>
    <div id="DivLateral"></div>
</div>
<div id="DivRodape"></div>

Search on "Clear Fix CSS" and you will see several examples.

Here is a reference source in Portuguese https://edsonjunior.com/entendendo-float-clear-clearfix/

0

You have to float: left on both Ivs.

#DivLateral{
position:relative;
float: left;
border-width:2px;
width:300px;
height: 700px;
background-color: peachpuff;
}

#DivA{
position: relative;
float: left;
border-width:2px;
width:auto;
height: auto;
left:300px;

}

0

Utilize display: inline-block;

Put one on the other side, create a margin, that you can correct with negative margin. Example: Margin: -5px;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.