I am fairly new to CSS, but I want to know if there's an easier way to order these boxes, as I need something like a treemap, which links to a certain page, as you can see, have some animations. Currently I want to order this third box below the second one, and I don't know how, I'm trying with float and clear, but doesn't work for me. Excuse my beginner knowledge, but I'm learning. Also, if there's an easier way to do this, except manually like I'm doing, let me know please.
.cbox1 {
border:solid 2.5px white;
position:relative;
float:left;
z-index: 10;
}
.cboxtext {
text-align:center;
height:50%;
margin-top: 200px;
color:#fff;
}
.cboxpercentage {
text-align:center;
font-size:80px;
font-weight: bold;
color:#fff;
margin-top: -300px;
}
<a href="#">
<div class="cbox1 hvr-bounce-out" style="width:400px; height:400px;background-color:steelblue;">
<h2 class="cboxtext"> Company 1 </h2>
<h1 class="cboxpercentage"> 62,5% </h1>
</div></a>
<a href="#">
<div id="wrapper">
<div class="cbox1 hvr-sink" style="width:200px; height:200px; background-color:dodgerblue;">
<h2 class="cboxtext" style="font-size:24px; margin-top:90px;"> Company 2 </h2>
<h1 class="cboxpercentage"> 32,5% </h1>
</div></a>
<a href="#">
<div class="cbox1 hvr-float" style="width:200px; height:200px; background-color:blue;">
<h2 class="cboxtext"> Company 3 </h2>
<h1 class="cboxpercentage"> 5% </h1>
</div>
</a>
</div>
It's a new version of your code:
.cbox1,#wrapper {
position: relative;
}
.cbox1 a,#wrapper a {
text-decoration: none;
display: block;
width: 400px;
height: 400px;
}
.cbox1 a span,#wrapper a span {
display: block;
position: absolute;
width: 100%;
line-height: 400px;
}
.cbox1 a span.cboxtext,#wrapper a span.cboxtext {
line-height:30px;
}
.cbox1 {
width: 400px;
height: 400px;
float: left;
}
a .cboxtext {
top: 10px;
text-align:center;
color:#fff;
}
.cboxpercentage {
text-align:center;
font-size:80px;
font-weight: bold;
color:#fff;
}
#wrapper {
float: left;
width: 200px;
}
#wrapper a span {
line-height: 200px;
}
#wrapper .cbox1 {
width: 200px;
height: 200px;
}
#wrapper .cbox1 a {
width: 200px;
height: 200px;
}
#wrapper .cboxpercentage {
font-size:40px;
}
<div class="cbox1 hvr-bounce-out" style="background-color:steelblue;">
<a href="#">
<span class="cboxtext">Company 1</span>
<span class="cboxpercentage"> 62,5% </span>
</a>
</div>
<div id="wrapper">
<div class="cbox1 hvr-sink" style="background-color:dodgerblue;">
<a href="#">
<span class="cboxtext">Company 2</span>
<span class="cboxpercentage">32,5%</span>
</a>
</div>
<div class="cbox1 hvr-float" style="background-color:blue;">
<a href="#">
<span class="cboxtext">Company 3</span>
<span class="cboxpercentage">5%</span>
</a>
</div>
</div>
Related
This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 2 years ago.
I'm trying to align multiple inline-blocks at the top of my page, but for reasons that are baffling to me, it's not working. The CSS could hardly be cleaner or less, but the top isn't aligning properly. I thought it could be a floating issue, but even after applying a clear:both it doesn't fix this.
Please see the program here:
https://jsfiddle.net/yezwocta/
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>
Add vertical-align: top; to your .article CSS (the default is baseline):
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
vertical-align:top;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>
While I hover Div tag, Another Div tag will appear in front of the prev Div. When i didn't put any words, it works. but when i put h3 tag, the div goes down.
here is the HTML
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<a href="#">
<div class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
</div>
here is CSS
#content{
width:50%;
}
.line{
border-top: 5px solid black;
}
.list-content{
display:inline-block;
width:25%;
height:200px;
background-color: black;
margin-top: 10px;
}
.detail-content{
display: none;
}
.list-content:hover .detail-content{
display: block;
width:100%;
height:75%;
background-color: rgba(255,255,255,0.6);
}
thank you before
Update below css part
.list-content:hover .detail-content {
display: table;
width: 100%;
height: 75%;
background-color: rgba(255, 255, 255, 0.6);
}
#content {
width: 50%;
}
.line {
border-top: 5px solid black;
}
.list-content {
display: inline-block;
width: 25%;
height: 200px;
background-color: black;
margin-top: 10px;
}
.detail-content {
display: none;
}
.list-content:hover .detail-content {
display: table;
width: 100%;
height: 75%;
background-color: rgba(255, 255, 255, 0.6);
}
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<a href="#">
<div class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
</div>
#James Please find following code. I hope you are expecting the same. Just replaced "display:inline-block;" with "float:left;" and took class "list-content" in anchor tag itself.
#content{
width:50%;
}
.line{
border-top: 5px solid black;
}
.list-content{
float:left;
width:25%;
height:200px;
background-color: black;
margin-top: 10px;
margin-right:10px;
}
.detail-content{
display: none;
}
.list-content:hover .detail-content{
display: block;
width:100%;
height:75%;
background-color: rgba(255,255,255,0.6);
}
.clearfix{
clear:both;
}
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<div class="clearfix">
<a href="#" class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</a>
<a href="#" class="list-content">
<div class="detail-content">
</div>
</a>
<a href="#" class="list-content">
<div class="detail-content">
</div>
</a>
</div>
</div>
Because the .list-content items are inline blocks, when you add a text content you have to vertically align them. Add vertical-align: top to .list-content:
.list-content {
display: inline-block;
width: 25%;
height: 200px;
background-color: black;
margin-top: 10px;
vertical-align: top;
}
And remove the top margin from :
h3 {
margin-top: 0;
}
{
width: 50%;
}
.line {
border-top: 5px solid black;
}
.list-content {
display: inline-block;
width: 25%;
height: 200px;
background-color: black;
margin-top: 10px;
vertical-align: top;
}
.detail-content {
display: none;
width: 100%;
height: 75%;
background-color: rgba(255, 255, 255, 0.6);
}
.list-content:hover .detail-content {
display: block;
}
h3 {
margin-top: 0;
}
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<a href="#">
<div class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
</div>
hi I'm assigned to do a basic profile page for class, but for one of the html pages I am unable to put the text in front of each individual image, i removed my attempts at it to help ease confusion.
<div class="aboutmeprofile">
<h2 id="h2">Portfolio</h2>
<hr></hr>
<img src="assets/images/gym.jpg" alt="gym">Gym
<img src="assets/images/hiking.jpg" alt="hiking">Hiking
<img src="assets/images/overwatch.jpg" alt="overwatch">Overwatch
<img src="assets/images/running.jpg" alt="running">Running
<img src="assets/images/programming.jpg" alt="programming">Programming
</div>
.aboutmeprofile {
float: left;
background-color: white;
width: 650px;
margin: 10px;
line-height: 150%;
padding: 10px;
margin-top: 30px;
}
You'll need to absolute position your text in front of the image with css. It helps to wrap each image and text item into a block to apply the css.
<div class="aboutmeprofile">
<h2 id="h2">Portfolio</h2>
<hr/>
<div class="item">
<img src="assets/images/gym.jpg" alt="gym">
<span>Gym</span>
</div>
<div class="item">
<img src="assets/images/hiking.jpg" alt="hiking">
<span>Hiking</span>
</div>
<div class="item">
<img src="assets/images/overwatch.jpg" alt="overwatch">
<span>Overwatch</span>
</div>
<div class="item">
<img src="assets/images/running.jpg" alt="running">
<span>Running</span>
</div>
<div class="item">
<img src="assets/images/programming.jpg" alt="programming">
<span>Programming</span>
</div>
</div>
css:
.item {
position: relative;
}
.item span {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Edit: Added a simplified fiddle example
* {
box-sizing: border-box;
}
.aboutmeprofile {
float: left;
background-color: white;
margin: 10px;
line-height: 150%;
padding: 10px;
margin-top: 30px;
}
.item {
position: relative;
width: 100%;
}
.item span {
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0;
text-align: center;
width: 100%;
}
<div class="aboutmeprofile">
<h2 id="h2">Portfolio</h2>
<hr/>
<div class="item">
<img src="https://placehold.it/400x300/ddd/ddd" alt="gym">
<span>Gym</span>
</div>
<div class="item">
<img src="https://placehold.it/400x300/ddd/ddd" alt="hiking">
<span>Hiking</span>
</div>
<div class="item">
<img src="https://placehold.it/400x300/ddd/ddd" alt="overwatch">
<span>Overwatch</span>
</div>
<div class="item">
<img src="https://placehold.it/400x300/ddd/ddd" alt="running">
<span>Running</span>
</div>
<div class="item">
<img src="https://placehold.it/400x300/ddd/ddd" alt="programming">
<span>Programming</span>
</div>
</div>
The best way to do this is to create a div for the label and use the image as the background-image for the div.
background-image: image.png
jsfiddle
this is what I came up with. Just add the other images and its respective label:
#h2, #h3 {
color: #4aaaa5;
text-align: left;
font-size: 30px;
font-weight: bold;
font-family: 'Georgia', Times, Times New Roman, serif;}
#linebreak {
clear: both;
border: 1px solid gray;
width: 100%;
margin: 0;
padding: 0;}
.aboutmeprofile {
float: left;
background-color: white;
width: 650px;
margin: 10px;
line-height: 150%;
padding: 10px;
margin-top: 30px;
}
.aboutmeprofile {
float: left;
background-color: white;
width: 650px;
margin: 10px;
line-height: 150%;
padding: 10px;
margin-top: 30px;
}
.container {
height: 100%;
width: 100%;
position: relative;
}
.image {
width:100%;
height:100%;
}
.text {
position: absolute;
color: white;
left: 50%;
top: 50%;
}
<div class="aboutmeprofile">
<h2 id="h2">Portfolio</h2>
<hr>
<div class="container">
<img class="image" src="http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg" />
<span class="text">
Gym
</span>
</div>
<div class="container">
<img class="image" src="http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg" />
<span class="text">
Hiking
</span>
</div>
</div>
Hope it helps!
You can simply do this with position:absolute property , first you need to create a relative div , then call the image and h2 inside the div , then set absolute position to h2
Check with the snippet
.content_div {
position:relative;
}
.content_div h2 {
position:absolute;
bottom:25px;
color:#fff;
font-size:18px;
}
.content_div h2 span {
background:rgba(0,0,0,0.8);
padding:10px;
display:block;
border-bottom:2px solid #000;
}
.content_div h2 span:last-child{
border-bottom:none;
}
<div class="content_div">
<img src="http://www.picgifs.com/graphics/c/cute/graphics-cute-160852.jpg" alt="image" />
<h2>
<span>A Movie in the Park:</span>
<span>Kung Fu Panda</span>
</h2>
</div><!-- /.content_div -->
I need 2 divs inside a big one:
the first will float left and second will float right
i gave the 1st div width of 75% and the 2nd 25%, it seems that the 2nd div is not finding its right place so it keeps coming under the left div on the right side
this is my code:
<div class="centerDiv2">
<span class="title2">LATEST BULLETIN</span>
<hr>
<div class="divLeft">
<img src="images/5891.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divLeft">
<img src="images/42St.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divRight">
<span class="title">RECENTLY</span>
<hr>
</div>
</div>
CSS:
.divLeft {
width:70%;
margin: 30 0;
}
.title2 {
font-size: 20px;
font-weight:bolder;
font-family: courier;
float: left;
width: 100%;
}
.centerDiv2 {
width: 1000px;
margin: 30 auto;
}
.divRight {
width:25%;
height:400px;
background-color: lightgray;
float:right;
margin: 30 0;
}
HTML:
<div class="centerDiv2">
<span class="title2">LATEST BULLETIN</span>
<hr>
<div class="leftDiv">
<div class="divLeft">
<img src="images/5891.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divLeft">
<img src="images/42St.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
</div>
<div class="divRight">
<span class="title">RECENTLY</span>
<hr>
</div>
</div>
CSS:
.title2 {
font-size: 20px;
font-weight:bolder;
font-family: courier;
width: 100%;
}
.leftDiv{
width: 70%; display: inline-block;
}
.divRight {
display: inline-block; vertical-align: top; height: 400px; width: 25%;background-color: lightgray;
}
hi dude the issue is with width 75% and 25% using with the margin because you are giving margin though you have already 100% of you canvas means(body)
.wrapper{
margin: 30px 0;
}
.divLeft {
width:70%;
background-color:red;
}
.title2 {
font-size: 20px;
font-weight:bolder;
font-family: courier;
float: left;
width: 100%;
}
.centerDiv2 {
width: 1000px;
margin: 30px auto;
}
.divRight {
width:25%;
height:400px;
background-color: lightgray;
float:right;
margin: 30px 0;
background-color:black;
}
<div class="centerDiv2">
<span class="title2">LATEST BULLETIN</span>
<hr>
<div class="wrapper">
<div class="divLeft">
<img src="images/5891.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divLeft">
<img src="images/42St.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
</div>
<div class="divRight">
<span class="title">RECENTLY</span>
<hr>
</div>
</div>
I'm currently trying to do this.
This is the code I got so far,
Html
<a class="home" href="home.php">
<i id="icon" class="fa fa-home"></i>
<p id="tag">Home</p>
</a>
Css for .home
width: 25%;
height: 25%;
overflow: hidden;
float: left;
background: #ea7b7b;
color: #fff;
text-decoration: none;
And the height:25%; does not work. I found some fixes like adding position:absolute;
but that messes up everything when resizing. I'm trying to find a work around to this and help would be much appreciated!
Try putting the elements inside a container div with an explicit height.
<div class="header"></div>
<div class="container">
<a class="home" href="home.php">
<i id="icon" class="fa fa-home"></i>
<p id="tag">Home</p>
</a>
<a class="contact" href="contact.php">
<i id="icon" class="fa fa-home"></i>
<p id="tag">Contact</p>
</a>
</div>
<div class="footer"></div>
CSS
.header, .footer
{
height: 50px;
background: black;
}
.home
{
background: #ea7b7b;
}
.container > a
{
width: 25%;
height: 50%;
overflow: hidden;
float: left;
color: #fff;
text-decoration: none;
}
.container
{
height: 600px;
width: 100%;
}
Sorry I'm a bit late but I made this FIDDLE
Hope it can help you, here is the code:
HTML:
<div id="top"></div>
<div id="content">
<div class="box">
<a class="home" href="home.php">
<i id="icon" class="fa fa-home"></i>
<p id="tag">Home</p>
</a>
</div>
<div class="box"></div>
...
</div>
<div id="bottom"></div>
CSS :
html, body {
width:100%;
height:100%;
margin:0;
padding:0;
}
#top, #bottom {
position:absolute;
height:80px;
width:100%;
background:grey;
left:0;
}
#top {
top:0;
}
#bottom {
bottom:0;
}
#content {
position:absolute;
top:80px;
left:0;
right:0;
bottom:80px;
}
.box {
box-sizing:border-box;
border:1px solid red;
float:left;
width:25%;
height:50%;
}
.home {
width:100%;
height:100%;
margin:0;
padding:0;
overflow: hidden;
float: left;
background: #ea7b7b;
color: #fff;
text-decoration: none;
}