I'm trying to make a layout of blocks, like this:
Pattern design
But I get this: Pattern made with HTML and css
Does someone know what went wrong? You would really help me out!
Plus all the borders and colors for the other blocks
Snippet Below
#blocks {
font-size: 0; /* To prevent white-space from taking space */
}
.horBlock, .verBlock {
display: inline-block;
box-sizing: border-box;
}
.horBlock {
width: 50%;
padding-top: 25%;
vertical-align: top;
}
.verBlock {
width: 25%;
padding-top: 50%;
vertical-align: top;
}
#javaBlock {
border: 10px solid red;
}
#phpBlock {
border: 10px solid green;
}
#objective-CBlock {
border: 10px solid yellow;
}
#CBlock {
border: 10px solid purple;
}
#pythonBlock {
border: 10px solid blue;
}
#jsBlock {
border: 10px solid #FF7F00;
}
<div id="blocks">
<div class="horBlock" id="javaBlock" onclick="launchInfo(); java();">
<img src="javaLogo.svg">
</div>
<div class="verBlock" id="phpBlock" onclick="launchInfo(); php();">
<img src="phpLogo.svg">
</div>
<div class="verBlock" id="objective-CBlock" onclick="launchInfo(); objectiveC();">
<img src="objective-CLogo.svg">
</div>
<div class="verBlock" id="CBlock" onclick="launchInfo(); C();">
<img src="CLogo.svg">
</div>
<div class="verBlock" id="pythonBlock" onclick="launchInfo(); python();">
<img src="pythonLogo.svg">
</div>
<div class="horBlock" id="jsBlock" onclick="launchInfo(); js();">
<img src="jsLogo.svg">
</div>
</div>
This is a situation where you actually want to be using float
properties on specific elements.
Create your own utility classes and assign them to elements as required; like using a specific class to float
an element left or right with corresponding classes .alignLeft
and .alignRight
, e.g:
<div class="horBlock alignLeft nestedBlock" id="javaBlock" onclick="launchInfo(); java();">
<img src="https://placehold.it/200x200">
</div>
<div class="verBlock alignRight nestedBlock" id="phpBlock" onclick="launchInfo(); php();">
<img src="https://placehold.it/200x200">
</div>
Code Snippet Demonstration:
* {
box-sizing: border-box;
}
#blocks {
font-size: 0;
/* To prevent white-space from taking space */
}
.horBlock,
.verBlock {
display: inline-block;
box-sizing: border-box;
}
.horBlock {
width: 50%;
padding-top: 25%;
vertical-align: top;
}
.verBlock {
width: 25%;
padding-top: 50%;
vertical-align: top;
}
#javaBlock {
border: 10px solid red;
}
#phpBlock {
border: 10px solid green;
}
#objective-CBlock {
border: 10px solid yellow;
}
#CBlock {
border: 10px solid purple;
}
#pythonBlock {
border: 10px solid blue;
}
#jsBlock {
border: 10px solid #FF7F00;
}
/* Start Additional */
.alignLeft {
float: left;
}
.alignRight {
float: right;
}
.nestedBlock {
position: relative; /* required to vertically and horizontally align nested img element */
}
.nestedBlock img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
max-width: 100%;
max-height: 100%;
}
/* End Additional */
<div id="blocks">
<div class="horBlock alignLeft nestedBlock" id="javaBlock" onclick="launchInfo(); java();">
<img src="https://placehold.it/200x200">
</div>
<div class="verBlock alignRight nestedBlock" id="phpBlock" onclick="launchInfo(); php();">
<img src="https://placehold.it/200x200">
</div>
<div class="verBlock alignRight nestedBlock" id="objective-CBlock" onclick="launchInfo(); objectiveC();">
<img src="https://placehold.it/200x200">
</div>
<div class="verBlock alignLeft nestedBlock" id="CBlock" onclick="launchInfo(); C();">
<img src="https://placehold.it/200x200">
</div>
<div class="verBlock alignLeft nestedBlock" id="pythonBlock" onclick="launchInfo(); python();">
<img src="https://placehold.it/200x200">
</div>
<div class="horBlock alignLeft nestedBlock" id="jsBlock" onclick="launchInfo(); js();">
<img src="https://placehold.it/200x200">
</div>
</div>