I have a div inside another div and the effect that I'd like to achieve is the classic three products icons next to each other with some explanatory text underneath.
The content of a the text div doesn't push down the following content and overlaps it. I've tried many different solutions but i didn't find anything that works in this case.
I'm afraid that the absolute positioning and negative margin of the inner div makes it harder.
I would appreciate any suggestions. Thanks!
HTML
<div class="icon-group">
<div class="icon">
<i class="fa fa-book fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
<div class="icon">
<i class="fa fa-plane fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
<div class="icon">
<i class="fa fa-quote-right fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
</div>
<div class="clear"></div>
<h3 class="after-icons">What people say about me</h3>
CSS
.icon-group, icon-caption-group {
height: 100px; display: table; width:100%; table-layout: fixed}
.icon, .icon-caption {
display: table-cell;
text-align: center;
vertical-align: middle;
position: relative;}
.icon-caption {
border-bottom: 3px solid #E8EAF6;
vertical-align: middle;
position: absolute;
top: 50%;
left: 50%;
width: 50%;
margin: -15% 0 0 -25%;
margin-top: 20%;
}
.after-icons {
margin-top: 30px
}
You don't need to positioning the content you can simply do like this way, check with the below snippet
.icon-group, icon-caption-group {height: 100px; display: table; width:100%; table-layout: fixed}
.icon, .icon-caption {
display: table-cell;
text-align: center;
vertical-align: middle;
position: relative;}
.icon-caption {
border-bottom: 3px solid #E8EAF6;
vertical-align: middle;
display: block;
margin: 0 auto;
width: 50%;
}
.after-icons {
margin-top: 30px
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="icon-group">
<div class="icon">
<i class="fa fa-book fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
<div class="icon">
<i class="fa fa-plane fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
<div class="icon">
<i class="fa fa-quote-right fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
</div>
<div class="clear"></div>
<h3 class="after-icons">What people say about me</h3>
How about increasing the top margin of the after-icons class? I've increased it to 130, and this pushes the text below the div.
Your css leads to a very difficult situation of trying to expand the parent (icon class) based on an the size of an absolute positioned child which is better avoided Make absolute positioned div expand parent div height
keep you html markup the same and erasing your clear div and your css becomes very simple
All you need to do is apply padding or margin to icon class to space the icons
.icon {
float: left;
width: 33%;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="icon-group">
<div class="icon clearfix">
<i class="fa fa-book fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
<div class="icon clearfix">
<i class="fa fa-plane fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
<div class="icon clearfix">
<i class="fa fa-quote-right fa-4x" aria-hidden="true"></i>
<div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div>
</div>
</div>
<h3 class="after-icons">What people say about me</h3>
NOTE: clearfix is usually needed for older browsers and I chose the simplest implementation of it but if you want to support very old browsers do a search for clearfix
Here is a working jsfiddle https://jsfiddle.net/GiorgosK/x3evnxpn/
Related
This question already has answers here:
CSS grid square layout [duplicate]
(4 answers)
Closed 3 years ago.
I'm trying to build this responsive grid for an image gallery.
I want the grid items to be square-shaped at all times (aspect ratio 1:1), even though the pictures are coming in all sorts of aspect-ratios.
I'll probably display any picture inside the square items, using object-fit: cover.
I'm trying to get a solution that works well across browsers. Nothing too hacky. It's seems like a simple task but so far I couldn't wrap my head around it.
See an example on the code snippet that I've made.
Note: Every image needs to have an icon on top of it, just like the example.
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 10px;
}
.gridItemContainer {
position: relative;
}
.grid img {
display: block;
object-fit: cover;
width: 100%;
}
.grid i {
font-size: 120%;
position: absolute;
top: 10px;
left: 10px;
}
<html>
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
</head>
<body>
<div class="grid"/>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41g1xjf4CpL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/4106U8dHTgL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41cSJCJ%2BSaL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41DpkMbHZZL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41i-GWf875L.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/51LUVEJQbjL.jpg"/>
<i class="fas fa-star"></i>
</div>
</div>
You can use padding-top: 100% to set the height of a grid item - this will make a square as padding in percentages is based on width in CSS.
Now make the image position: absolute so that it will be taken out of the flow and height will be fully dictated by padding-top set on the grid item (gridItemContainer) - see demo below:
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 10px;
}
.gridItemContainer {
position: relative;
padding-top: 100%; /* added */
border: 1px solid;
background: cadetblue;
}
.grid img {
display: block;
object-fit: cover;
width: 100%;
height: 100%; /* image fills the grid item */
position: absolute; /* position absolutely */
top: 0;
left: 0;
}
.grid i {
font-size: 120%;
position: absolute;
top: 10px;
left: 10px;
}
<html>
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
</head>
<body>
<div class="grid"/>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41g1xjf4CpL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/4106U8dHTgL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41cSJCJ%2BSaL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41DpkMbHZZL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41i-GWf875L.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/51LUVEJQbjL.jpg"/>
<i class="fas fa-star"></i>
</div>
</div>
I have a problem with displaying this(check this picture)
I have a link on the left and icons with words under it on the right. What is the right way to display it? and how can I display the words under the icons? I need help with it. Please check the attached picture to see how I need it to look.
<div class="back-to-listing-clinic">
<div>
<a> < back </a>
</div>
<div class="right-icons-part">
<img class="clinic-top-icons"src="./assets/images/icons/forum.png">
<img class="clinic-top-icons" src="./assets/images/icons/forum.png">
<img class="clinic-top-icons" src="./assets/images/icons/forum.png">
</div>
<div>
<p> Icon1 </p>
<p> Icon2 </p>
<p> Icon3 </p>
</div>
</div>
There's a dozen ways to do this. I replaced your images with icons for demonstration purposes.
This method just sets the "left and right" parts to display: inline-block to place them next to each other, and then sets float: right on the right hand ones to separate them.
I'd consider using a CSS Framework of some kind instead - but this would be a simple way to do it with what you have.
No Framework:
* {
box-sizing: border-box;
}
.back-to-listing-clinic > div {
display: inline-block;
}
.right-icons-part {
float: right;
}
.right-icons-part:after {
content: " ";
display: block;
clear: both;
height: 0px;
}
.right-icons-part a {
text-align: center;
display: inline-block;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div class="back-to-listing-clinic">
<div class="left">
<a> < back </a>
</div>
<div class="right-icons-part">
<i class="fas fa-comment-alt"></i><br />Icon 1
<i class="fas fa-comment"></i><br />Icon 2
<i class="fas fa-comments"></i><br />Icon 3
</div>
</div>
Super simple Ungrid framework
#media (min-width: 30em) {
.row { width: 100%; display: table; table-layout: fixed; }
.col { display: table-cell; }
}
.right {
text-align: right;
}
.right-icons-part a {
display: inline-block;
text-align: center;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div class="row back-to-listing-clinic">
<div class="col left">
<a> < back </a>
</div>
<div class="col right right-icons-part">
<i class="fas fa-comment-alt"></i><br />Icon 1
<i class="fas fa-comment"></i><br />Icon 2
<i class="fas fa-comments"></i><br />Icon 3
</div>
</div>
I'm new to CSS and HTML, so I got stuck on a very stupid step. The thing is that fa-list-ul icon is wrong positioned. Without text-align:center it positions fine. Any way to fix it? Thanks for spending your time with my problem.
Here's the JSFiddle
And here is my code :
.player{padding:.75rem 1rem;margin-bottom:1rem;line-height:36px}
.player_play{font-size:36px;vertical-align:middle}
.radio_name{vertical-align:middle}
.radio_icon{padding-right:5px;vertical-align:middle}
.radio_select{font-size:20px;vertical-align:middle}
<nav class="player">
<div class="container">
<div class="float-left">
<i class="fa fa-play-circle player_play action"></i>
</div>
<div class="radio_volume">
<i class="fa fa-volume-down"></i>
<i class="fa fa-music radio_icon accent_color"></i><span class="radio_name"> Anison</span>
</div>
<div class="float-right">
<i class="fa fa-list-ul radio_select action"></i>
</div>
</div>
</nav>
Using display: flex will make every element inside that container have the same horizontal size so this should solve your problem:
.container {
display: flex;
}
.float-left {
flex: 1;
}
.radio_volume {
text-align: center;
flex: 1;
}
.float-right {
flex: 1;
}
.float-right i {
float: right;
margin-top: 10px;
}
also here's the jsfiddle: https://jsfiddle.net/fqkvv8es/3/
You can make use of Bootstrap's classes, which results in less code than what the chosen answer uses:
JSFiddle
HTML
<nav class="player">
<div class="container">
<div class="row justify-content-between align-items-center">
<i class="fa fa-play-circle player_play action"></i>
<div class="radio_volume">
<i class="fa fa-volume-down"></i>
<i class="fa fa-music radio_icon accent_color"></i><span class="radio_name"> Station</span>
</div>
<i class="fa fa-list-ul radio_select action"></i>
</div>
</div>
</nav>
CSS
.player {
padding: .75rem 1rem;
margin-bottom: 1rem;
line-height: 36px
}
.player_play {
font-size: 36px;
}
.radio_icon {
padding-right: 5px;
}
.radio_select {
font-size: 20px;
}
JSFiddle
I'm probably really sleepy and missing something easy here. I've tried every margin and padding available but I'm unable to lift a span (div or any other text containing element for that matter) that contains some text to the right level.
What's the best way to achieve this? In the fiddle below, i want to align it with the font-awesome icon.
.add-cohorts-button > a > i {
padding-top: 5px;
}
.add-cohorts-button > span {
padding-left: 8px;
/*any amount of bottom margin/padding doesn't work. Try it. Height didn't either */
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-xs-3 add-cohorts-button">
<a href="addcohort.form"><i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span></a>
</div>
Way out of this fix?
This Suits you?
Adjust the margin according to your icon height.
.add-cohorts-button > a > i {
padding-top: 5px;
}
.add-cohorts-button span {
position:absolute;
padding-left:8px;
margin-top:10px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-xs-3 add-cohorts-button">
<a href="addcohort.form"><i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span></a>
</div>
Use display: inline-block on your link so that it can fit its height to its contents, then use vertical-align: middle, like this:
.add-cohorts-button a {
display: inline-block;
}
.add-cohorts-button > * {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-xs-3 add-cohorts-button">
<i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span>
</div>
Version with the whole thing as a link:
.add-cohorts-button {
text-decoration: none;
}
.add-cohorts-button i {
display: inline-block;
}
.add-cohorts-button > * {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<a class="col-xs-3 add-cohorts-button" href="addcohort.form">
<i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span>
</a>
I've been looking for a way to make my div be on top of all div's (covering them all). In fact i think i could solve this hiding the other div's but i think there should be another solution.
I'm using bootstrap to make a 3x3 grid. So, i have one row and inside it i have 9 div's with the class "col-md-4" (i just want this to work with this size.)
Z-position isn't working with me.
HTML
<div class="row ">
<div id="cube1" class="col-md-4 ">
<h1>The Company</h1>
<p><i class="fa fa-building-o fa-9x"></i></p>
</div>
<div id="cube2" class="col-md-4">
<h1>Our People</h1>
<p><i class="fa fa-heart fa-9x"></i></p>
</div>
<div id="cube3" class="col-md-4">
<h1>Code</h1>
<p><i class="fa fa-code fa-9x"></i></p>
</div>
<div id="cube4" class="col-md-4">
<h1>Our Brand</h1>
<p><i class="fa fa-barcode fa-9x"></i></p>
</div>
<div id="cube5" class="col-md-4">
<h1>Our Technology</h1>
<p><i class="fa fa-connectdevelop fa-9x"></i></p>
</div>
<div id="cube6" class="col-md-4">
<h1>What Moves Us</h1>
<p><i class="fa fa-cogs fa-9x"></i></p>
</div>
<div id="cube7" class="col-md-4 ">
<h1>Our Clients</h1>
<p><i class="fa fa-exclamation fa-9x"></i></p>
</div>
<div id="cube8" class="col-md-4">
<h1>Contact Us</h1>
<p><i class="fa fa-envelope-o fa-9x"></i></p>
</div>
<div id="cube9" class="col-md-4">
<h1>Address</h1>
<p><i class="fa fa-compass fa-9x"></i></p>
</div>
</div>
CSS
.row {
float: left;
height: 100%;
color: #fff;
width:calc(100% - 250px); /*250px is the size of left menu */
}
.cube {
height: calc(100%/3);
}
.teste {
z-index: 300 !important;
}
js
$(document).ready(function(){
var cores = Please.make_color({
base_color:'aliceblue',
colors_returned:9
})
cores[4]='#32BAD3';
for (i=0; i<10; i++)
{
$('#cube'+ (i+1)).css('background-color',cores[i])
}
$('.cube').click(function() {
$( this ).addClass( "teste", 1000, "easeOutBounce" );
$(this).width($('#rightmenu').width()-280);
$(this).height($('#rightmenu').height());
});
});
What i want to achieve is when a user click on one of the divs, it will expand covering all the viewport.
I read some posts here and they said that Z-index only work when i have a non-static non static positioning scheme. Can i consider that using the bootstrap classes "col-md-4" it makes my website a static scheme?
Sources:
CSS I want a div to be on top of everything
Z-Index with different parents
CSS Z-Index with Gradient Background
I have similiar problems with bootstrap but usually it has to do with the way css files are arranged in your site.
A dirty solution is
z-index: 300 !important;
to make sure other css rules get overwritten but I would avoid that when possible.
Where exactly did you put the z-index rules?