/    Sign up×
Community /Pin to ProfileBookmark

Vertical allignment of divs

Hi,

Apologies if this is a basic question but I’m trying to arrange some div elements (of variable heights) on a page depending on the screen width: if enough space, split into 2 columns, if not show full width. I’m pretty much there but when the div is split in two, the third div in this example begins at the position of the base of the second div.

I’d like however many divs there are to start at the bottom of the div above them?

Please can anyone help or suggest the next best way of doing this?

Thanks very much!

Code below:

<%@ Page Language=”C#” AutoEventWireup=”true” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml“>
<head id=”Head1″ runat=”server”>
<title></title>

<script type=”text/javascript”>
function chooselayout()
{
if (document.body.clientWidth > 900){
d1.style.width = “49%”;
d2.style.width = “49%”;
d3.style.width = “49%”;
}
else
{
d1.style.width = “100%”;
d2.style.width = “100%”;
d3.style.width = “100%”;
}

}
window.onload = function()
{
chooselayout();
}
</script>

<style type=”text/css”>
#d1{height:50px; background-color:Aqua; float:left;}
#d2{height:100px; background-color:Fuchsia; float:left;}

#d3{height:150px; background-color:Green; float:left;}

</style>
</head>

<body>
<div id=”d1″></div>
<div id=”d2″></div>
<div id=”d3″></div>
</body>
</html>

to post a comment
CSS

0Be the first to comment 😎

×

Success!

Help @afranklin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...