CSS DIV Layout over Grid - css

Is it possible to get this Layout using div's

You could do this with floats and negative margin-top on .e. With masonry you don't need margin-top DEMO
* {
box-sizing: border-box;
}
.content {
width: 200px;
height: 200px;
border: 1px solid black;
}
.item {
border: 1px solid black;
float: left;
display: flex;
align-items: center;
justify-content: center;
}
.a,
.d {
width: 33.3333333%;
height: 66.67%;
}
.b,
.e {
width: 66.67%;
height: 33.3333333%;
}
.e {
margin-top: -33.3333333%;
}
.c {
width: 33.3333333%;
height: 33.3333333%;
}
<div class="content">
<div class="a item">a</div>
<div class="b item">b</div>
<div class="c item">c</div>
<div class="d item">d</div>
<div class="e item">e</div>
</div>

Yes it is possible.
I made a fast snippet for you. Using position: absolute.
* {
padding: 0;
margin: 0;
}
.container {
width: 150px;
height: 150px;
}
.a {
position: absolute;
height: 100px;
width: 50px;
background-color: #CCC;
}
.b {
position: absolute;
left: 50px;
height: 50px;
width: 100px;
background-color: #C2C2C2;
}
.c {
position: absolute;
left: 50px;
top: 50px;
width: 50px;
height: 50px;
background-color: #EEE;
}
.d {
position: absolute;
left: 100px;
top: 50px;
height: 100px;
width: 50px;
background-color: #F0F0F0;
}
.e {
position: absolute;
left: 0px;
top: 100px;
width: 100px;
height: 50px;
background-color: #DDD;
}
<div class="container">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
<div class="e"></div>
</div>

Try this code using table
table {
border-collapse: collapse;
border: 1px solid black;
}
table, td, th {
border: 1px solid black;
}
td
{
padding:10px;
}
<table >
<tr>
<td rowspan="2">A</td>
<td colspan="2">B</td>
</tr>
<tr>
<td>C</td>
<td rowspan="2">D</td>
</tr>
<tr>
<td colspan="2">E</td>
</tr>
</table>

try this code
<div class="wrapper">
<div class="a"><span>A</span></div>
<div class="b"><span>B</span></div>
<div class="c"><span>C</span></div>
<div class="d"><span>D</span></div>
<div class="e"><span>E</span></div>
</div>
CSS code
span{
position: absolute;
top: 30%;
left: 25%;
}
a {
position: absolute;
height: 100px;
width: 50px;
background-color:#f2f2f2;
border:solid 1px #333;
}
.b {
position: absolute;
left: 50px;
height: 50px;
width: 100px;
background-color:#d9d9d9;
border:solid 1px #333;
}
.c {
position: absolute;
left: 50px;
top: 50px;
width: 50px;
height: 50px;
background-color:#bfbfbf;
border:solid 1px #333;
}
.d {
position: absolute;
left: 100px;
top: 50px;
height: 100px;
width: 50px;
background-color:#a6a6a6;
border:solid 1px #333;
}
.e {
position: absolute;
left: 8px;
top: 100px;
width: 91px;
height: 50px;
background-color:#808080;
border: solid 1px #333;
}
Link for above code here https://jsfiddle.net/romesh60/odo4r5aq/2/

Related

Display div border overlaying another div

I've tried the method showed here, but it aint worked out:
StackOverflow: Display div border on top of another div [duplicate] (my own postage)
I have 2 nested divs, and the above method isn't working for both divs.
Here is the code:
html:
<div className="App">
<div class="box mainClass1" id="1">
<div class="helperClass" />
</div>
<div class="box mainClass2" id="2">
<div class="helperClass" />
</div>
</div>
css:
.box {
width: 100px;
height: 100px;
position: absolute;
}
.mainClass1 {
top: 100px;
left: 100px;
background: teal;
}
.mainClass2 {
top: 150px;
left: 150px;
background: red;
}
.helperClass2 .helperClass {
width: 100%;
height: 100%;
border: 3px solid #4286f4;
box-sizing: border-box;
}
note: helperClass2 should be added to the list of classes of parent (outer) div.
.container {
position: relative;
}
.box1 {
width: 100px;
height: 100px;
position: absolute;
top: 100px;
left: 100px;
box-sizing: border-box;
background: blue;
}
.box1:after {
content: '';
display: block;
width: 95px;
height: 95px;
position: absolute;
border: 3px solid black;
z-index: 3;
}
.box2 {
width: 100px;
height: 100px;
position: absolute;
top: 150px;
left: 150px;
box-sizing: border-box;
background: red;
border: 3px solid black;
}
<div class="container">
<div class="box1"></div>
<div class="box2"></div>
</div>

HTML Canvas align DIV at bottom right-hand corner

I have a Canvas and want to add a Div/Button in the bottom right-hand corner relative to Canvas. My current code looks as follows:
#container {
margin-top: 5px;
width: 96%;
margin: auto;
background-color: blue;
height: 300px;
}
#viewer {
width: 40%;
background-color: red;
height: 100%;
}
#button {
height: 40px;
width: 40px;
background-color: green;
position: absolute;
bottom: 0;
right: 0;
}
canvas {
border: 3px solid black;
width: 100%;
height: 100%;
}
<div id="container">
<div id="viewer">
<canvas></canvas>
<div id="button" onclick="myFunction();"></div>
</div>
</div>
But so far I couldn't manage to find a proper solution for this. It would be great if someone could help me with this.
Is this what you are looking for?
I recommand you checking out this article: CSS Layout - The position Property
#container{
margin-top: 5px;
width: 96%;
margin: auto;
background-color: blue;
height: 300px;
}
#viewer{
width: 40%;
background-color: red;
height: 100%;
position:relative;
}
#button{
height: 40px;
width: 40px;
background-color: green;
position: absolute;
bottom: 0;
right: 0;
}
canvas{
border: 3px solid black;
width: 100%;
height: 100%;
}
<div id="container">
<div id="viewer">
<canvas></canvas>
<div id="button" onclick="myFunction();"></div>
</div>
</div>
I think Temani was right — this puts the button at the bottom right of the canvas, is this not what you wanted?
#container{
margin-top: 5px;
width: 96%;
margin: auto;
background-color: blue;
height: 300px;
}
#viewer{
width: 40%;
background-color: red;
height: 100%;
position: relative;
}
#button{
height: 40px;
width: 40px;
background-color: green;
position: absolute;
bottom: 0;
right: 0;
}
canvas{
border: 3px solid black;
width: 100%;
height: 100%;
}
<div id="container">
<div id="viewer">
<canvas></canvas>
<div id="button" onclick="myFunction();"></div>
</div>
</div>
Like Temani Afif said.
position:relative
on #viewer worked for me.

Can anyone tell me how to make borders on the image using bootstrap/CSS?

This is the image. I have made the UI but need help in making the border as it is given in image
<div>
<img class='image1' src='https://www.w3schools.com/w3css/img_lights.jpg' />
<img class='image2' src='https://www.w3schools.com/w3css/img_lights.jpg' />
</div>
Css
div {
text-align: center
}
.image1 {
border: 15px solid seagreen;
outline: 15px solid green;
width:'150px';
height:'150px';
border-radius: 75%
}
.image2 {
border: 15px solid seagreen;
position: relative;
right:25px;
width:'150px';
height:'150px';
border-radius: 75%
}
The code you provided is modified a bit.
.parent-div {
margin-top: 100px;
}
div {
text-align: center;
}
.image1 {
border: 15px solid seagreen;
width: 150px;
height: 150px;
border-radius: 75%;
border-right-color: transparent;
}
.image2 {
border: 15px solid seagreen;
position: relative;
right: 80px;
width: 150px;
height: 150px;
border-radius: 75%;
border-left-color: transparent;
}
.imageH {
width: 150px;
height: 150px;
border-radius: 75%;
}
.ib {
display: inline-block;
}
.left-img {
position: relative;
z-index: -15;
width: 175px;
height: 175px;
border: 20px solid seagreen;
border-radius: 75%;
top: -200px;
left: 17px;
opacity: 0.3;
}
.right-img {
left: -100px;
opacity: 0.3;
position: relative;
z-index: -15;
width: 175px;
height: 175px;
border: 20px solid seagreen;
border-radius: 75%;
top: -200px;
}
<div class="parent-div">
<img class="image1" src="https://www.w3schools.com/w3css/img_lights.jpg" />
<img class="image2" src="https://www.w3schools.com/w3css/img_mountains.jpg" />
<div class="">
<div class="left-img ib">
<img class="imageH" src="https://www.w3schools.com/w3css/img_lights.jpg" />
</div>
<div class="right-img ib">
<img class="imageH" src="https://www.w3schools.com/w3css/img_lights.jpg" />
</div>
</div>
</div>
The class names and the images can be modified as required.

How to make an element positioned into right:0, if it already has left:0 style in one of it's class

I have an element with class A, with rules:
.A {
left: 0px;
}
For some reason, I need to make the element at the right position inside the container and I cannot exclude A class.
Specificity is your friend here:
Here's a couple of options....
Override the class using additional specificity such as another class (or ID)
.container {
height: 50vh;
position: relative;
width: 50%;
bordeR: 1px solid grey;
margin: auto;
}
.A {
position: absolute;
height: 25px;
width: 25px;
left: 0;
background: #000;
margin-bottom: 1em;
}
.A.right {
left: auto;
right: 0;
background: red;
}
<div class="container">
<div class="A"></div>
<div class="A right"></div>
</div>
or a nth-child selector
.container {
height: 50vh;
position: relative;
width: 50%;
bordeR: 1px solid grey;
margin: auto;
}
.A {
position: absolute;
height: 25px;
width: 25px;
left: 0;
background: #000;
margin-bottom: 1em;
}
.A:nth-child(2) {
left: auto;
right: 0;
background: red;
}
<div class="container">
<div class="A"></div>
<div class="A"></div>
</div>

CSS3 fluid arcs + some text

Is there a way to make such thing fluid so that it scales along with its parent or, what would it take to achieve it..
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Demo</title>
<style type="text/css">
#circle-container {
position: relative;
width: 200px;
height: 200px;
border: solid 0px #333;
}
.dimmensions {
width: 100px;
height: 100px;
}
.dimmensions2 {
width: 113px;
height: 113px;
}
.dimmensions3 {
width: 105px;
height: 105px;
}
.left {
position: relative;
border-top-left-radius: 100px;
border-bottom-left-radius: 100px;
background: #09f;
float: left;
height: 199.5px;
top: 0;
}
.left-inner {
position: relative;
border-top-left-radius: 100px;
border-bottom-left-radius: 100px;
background: #444;
height: 175px;
width: 90px;
top: 12px;
left: 15px;
}
.left-inner-small {
position: relative;
border-top-left-radius: 100px;
border-bottom-left-radius: 100px;
background: #4cff00;
height: 145px;
width: 85px;
top: 15px;
left: 15px;
}
.top-right {
position: relative;
border-top-right-radius: 100px;
background: #666;
float: right;
}
.top-right-inner {
position: relative;
border-top-right-radius: 100px;
background: #ffd800;
float: right;
height: 90px;
width: 85px;
top: 12px;
right: 15px;
}
.top-right-inner-small {
position: relative;
border-top-right-radius: 100px;
background: #808080;
float: right;
height: 75px;
width: 70px;
top: 15px;
right: 15px;
}
.bottom-right {
position: relative;
border-bottom-right-radius: 100px;
background: #333;
float: right;
}
.bottom-right-inner {
position: relative;
border-bottom-right-radius: 100px;
background: #ff6a00;
float: right;
height: 87px;
width: 85px;
top: 0px;
right: 15px;
}
.bottom-right-inner-small {
position: relative;
border-bottom-right-radius: 100px;
background: #fff;
float: right;
height: 72px;
width: 70px;
top: 0px;
right: 15px;
}
.center-small {
position: absolute;
border-radius: 125px;
background: #ff6a36;
top: 44px;
left: 44px;
z-index: 999;
}
.center-small-inner {
position: absolute;
border-radius: 125px;
background: #333;
top: 4px;
left: 4px;
z-index: 9999;
}
.center-text {
z-index: 99999;
position: absolute;
text-shadow: #000 0px 2px 1px;
color: #555;
font-size: 18px;
top: -12px;
left: -47px;
font-family: 'Impact';
text-transform: uppercase;
}
</style>
</head>
<body>
<div id="circle-container">
<div class="dimmensions2 center-small">
<div class="dimmensions3 center-small-inner"></div>
</div>
<div class="dimmensions left">
<div class="dimmensions left-inner">
<div class="dimmensions left-inner-small"></div>
</div>
</div>
<div class="dimmensions top-right">
<div class="dimmensions top-right-inner">
<div class="dimmensions top-right-inner-small"></div>
</div>
</div>
<div class="dimmensions bottom-right">
<div class="dimmensions bottom-right-inner">
<div class="dimmensions bottom-right-inner-small">
<span class="center-text">
CSS3<span style="color:#ffd800">+</span>HTML5
</span>
</div>
</div>
</div>
</div>
</body>
</html>
Every element is subordinated to the #circle-container. You have defined fixed width's and height's in all elements. You could calculate those values as a proportional value to the actual 200px of width and height of the #circle-container, and change it to the percentual result.
Example:
#circle-container {
position: relative;
width: 200px;
height: 200px;
border: solid 0px #333;
}
.dimmensions {
width: 100px;
height: 100px;
}
Would turn into:
#circle-container {
position: relative;
width: 200px;
height: 200px;
border: solid 0px #333;
}
.dimmensions {
width: 50%; //Proportional
height: 50%; //Proportional
}
Then, resizing the #circle-container would resize the entire arc.

Resources