I have 3 divs with content in them, and the 2 with less content are flush with the bottom of the larger div.
There's no margin or padding, so I'm not sure why is this happening?
body {
width: 100%
}
.container {
margin: 0 auto;
text-align: center;
}
.box {
display: inline-block;
width: 25%;
height: 100%;
border: 3px solid black;
padding: 2%;
}
<div class="container">
<div class="box blue">
<h1>Box 1</h1>
<p>Blub</p>
<div class="remainder"></div>
</div>
<div class="box green">
<h1>Box 2</h1>
<p>I'm working on different ideas for 100% height without using Flexbox, Tables, or a set height on the parent container.</p>
<hr />
<p>That's not my question though, why are boxes 1 & 2 floating so far down?</p>
</div>
<div class="box yellow">
<h1>Box 3</h1>
<p>Here's some more content</p>
<div class="remainder"></div>
</div>
</div>
It is because of the vertical-align property on the .box class is set to bottom. Setting elements to be inline-block will allow the vertical align property to affect their positioning.
Just a note: you didn't set the vertical align property yourself, but it is inheriting it from another rule. Try setting it directly to see the different results.
.box {
vertical-align: top;
/* ... */
}
Since they are inline-level elements, their vertical alignment is given by the vertical-align property.
.box {
vertical-align: /* value */;
}
Some examples:
vertical-align: top
body {
width: 100%
}
.container {
margin: 0 auto;
text-align: center;
}
.box {
display: inline-block;
width: 25%;
height: 100%;
border: 3px solid black;
padding: 2%;
vertical-align: top;
}
<div class="container">
<div class="box blue">
<h1>Box 1</h1>
<p>Blub</p>
<div class="remainder"></div>
</div>
<div class="box green">
<h1>Box 2</h1>
<p>I'm working on different ideas for 100% height without using Flexbox, Tables, or a set height on the parent container.</p>
<hr />
<p>That's not my question though, why are boxes 1 & 2 floating so far down?</p>
</div>
<div class="box yellow">
<h1>Box 3</h1>
<p>Here's some more content</p>
<div class="remainder"></div>
</div>
</div>
vertical-align: middle
body {
width: 100%
}
.container {
margin: 0 auto;
text-align: center;
}
.box {
display: inline-block;
width: 25%;
height: 100%;
border: 3px solid black;
padding: 2%;
vertical-align: middle;
}
<div class="container">
<div class="box blue">
<h1>Box 1</h1>
<p>Blub</p>
<div class="remainder"></div>
</div>
<div class="box green">
<h1>Box 2</h1>
<p>I'm working on different ideas for 100% height without using Flexbox, Tables, or a set height on the parent container.</p>
<hr />
<p>That's not my question though, why are boxes 1 & 2 floating so far down?</p>
</div>
<div class="box yellow">
<h1>Box 3</h1>
<p>Here's some more content</p>
<div class="remainder"></div>
</div>
</div>
vertical-align: bottom
body {
width: 100%
}
.container {
margin: 0 auto;
text-align: center;
}
.box {
display: inline-block;
width: 25%;
height: 100%;
border: 3px solid black;
padding: 2%;
vertical-align: bottom;
}
<div class="container">
<div class="box blue">
<h1>Box 1</h1>
<p>Blub</p>
<div class="remainder"></div>
</div>
<div class="box green">
<h1>Box 2</h1>
<p>I'm working on different ideas for 100% height without using Flexbox, Tables, or a set height on the parent container.</p>
<hr />
<p>That's not my question though, why are boxes 1 & 2 floating so far down?</p>
</div>
<div class="box yellow">
<h1>Box 3</h1>
<p>Here's some more content</p>
<div class="remainder"></div>
</div>
</div>
Related
I am trying to put a text under every image of an album. so I've added 6 photos side by side with float left. I know that the img tag is an inline-block of default so I put a div with class text with text inside and in the CSS I assigned it "display: block" in this way I thought I would make it appear under the image .. why this does not happen? I tried also to assign to the div text... position absolute and to the container position relative but this only works for the first image ...
.conteiner {
width: 100%;
height: 50vh;
margin-top: 50px;
padding: 20px;
}
.box {
background-image: url('xxx.jpg');
background-size: cover;
border: 1px solid black;
width: calc(100% / 6 - 20px);
height: 15vh;
float: left;
margin: 10px;
background-position: center;
}
.clearfix {
content: '';
display: table;
clear: both;
.text {
display: block;
}
<div class="conteiner clearfix">
<div class="box">
</div>
<div class="text">
Recenti
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</div>
enter image description here that's what I have
enter image description here and that's what I want to do
It would be much simpler to use Grid or Flexbox to get such a layout. No need for float and clear.
Using Grid:
.container {
display: grid;
grid-template-columns: repeat(6, 1fr);
width: 100%;
height: 50vh;
margin-top: 50px;
padding: 20px;
}
Then simply place the 6 images first to fill up the first row and the 6 texts second to fill up a second row.
<div class="container">
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="text">
Recenti
</div>
<div class="text">
Recenti
</div>
<div class="text">
Recenti
</div>
<div class="text">
Recenti
</div>
<div class="text">
Recenti
</div>
<div class="text">
Recenti
</div>
</div>
Also, the content of the grid will be sized to fill the grid area so you may not have to explicitly size the box.
.box{
background-image: url('xxx.jpg');
background-size: cover;
border: 1px solid black;
width: 100%;
height: 15vh;
background-position: center;
}
Try this :
https://codepen.io/the-wrong-guy/pen/xxZzBwR
.box {
display: grid;
}
I want to position a div according to the picture:
I'm successful so far by using Bootstrap's row class and using z-index in my CSS. But when I resize the browser, it's not responsive, it just floats off the right side of the page. By the way, I'm using position: absolute (I read online that I have to use this in order to make use of z-index). Is there any other more elegant way to do this? I want it to be responsive but can't seem to find any other workaround than the wonky one I implemented.
Code:
#div2 {
float: inherit;
position: absolute;
top: inherit;
left: 60%;
width: 320px;
height: 1290px;
z-index: 5;
}
<div class="container">
<div class="div-container">
<div class="row">
<div id="div1">
<p>Div 1</p>
</div>
<div id="div2" align='center'>
<p>Div 2</p>
</div>
</div>
<div class="row">
<div id="div3">
<p>Div 3</p>
</div>
</div>
</div>
</div>
You need to make use of the nested rows inside a column. See here - Bootstrap Nesting. Ignore the CSS here as it is for snippet styling and height is used for ignoring the content.
.B {
min-height: 130px;
background: #393276;
margin-bottom: 20px;
}
.A {
min-height: 100px;
margin-bottom: 20px;
background: #393276;
}
.C {
min-height: 250px;
background: #393276;
}
div {
text-align: center;
color: #fff;
font-size: 32px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container mt-4">
<div class="row">
<!-- First Column -->
<div class="col-sm-6">
<!--Rows nested inside a column-->
<div class="row">
<div class="col-12">
<div class="A">A</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="B">B</div>
</div>
</div>
</div>
<!-- Second Column -->
<div class="col-sm-6">
<div class="C">C</div>
</div>
</div>
</div>
I have used flexbox to keep responsive design and some margin positioning to keep the formation together.
.container{
display: flex;
flex-wrap: wrap;
width: 150px;
}
.div1, .div3{
margin-right: 5px;
width: 50px;
height: 50px;
}
.div2{
margin-right: 5px;
width: 50px;
height: 110px;
}
<div class="container">
<div class="div1"> div1 </div>
<div class="div2"> div2 </div>
<br/>
<div class="div3" style="margin-top: -55px;"> div 3 </div>
</div>
I am trying to align two divs beside each other using the inline-block technique. My code is fairly simple, but I am not sure why is it not working, I don't know what the issue might be.
Here's my code:
.content .sidebar, .content .section {
display: inline-block;
border: none;
min-height: 200px;
width: 250px
}
.sidebar {
background: blue;
}
.section {
background: red;
}
<div>
<div class="header-area">
<h3 id="genericpartTitle">Our album</h3>
</div>
<div class="content">
<div class="sidebar"> hello! </div>
<div class="section">
<h5 class="item-title">Welcome to my section</h5>
<p style="white-space: pre" class="description"> Hello, anything will go here </p>
</div>
</div>
</div>
Aren't they supposed to be aligned beside each other? what's going wrong here? any help would be great.
You just need to add vertical-align: top; for both sidebar and section classes. checkout the code below.
.content .sidebar, .content .section{
display: inline-block;
border: none;
min-height: 200px;
width: 250px
}
.sidebar{
background: blue;
vertical-align: top;
}
.section{
background: red;
vertical-align: top;
}
<div>
<div class="header-area">
<h3 id="genericpartTitle">Our album</h3>
</div>
<div class="content">
<div class="sidebar">
hello!
</div>
<div class="section">
<h5 class="item-title">Welcome to my section</h5>
<p style="white-space: pre" class="description">
Hello, anything will go here
</p>
</div>
</div>
</div>
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 6 years ago.
There is some space between #child divs. How can I make them stack perfectly without any gaps? There is no problem when I don't have the <img> in there. Also, there is a blue stripe under the image, which is part of the div, but I don't understand why it's showing.
I am not an expert on HTML or CSS. I am a beginner who is starting to pick it up for marketing reasons. Any help and/or advice is highly appreciated it!
#parent {
max-width: 850px;
margin: 0 auto;
border: 10px solid black;
}
#child {
background-color: blue;
text-align: center;
color: #eee;
font-size: 56px;
}
img {
width: 100%;
}
<div id="parent">
<div id="child">
<img src="http://s3.amazonaws.com/letsrumbl-marketing/images/8c146690-f04b-4e60-89ca-5e2d979f5a16/HowToShare3.png" />
</div>
<div id="child">
<p>Div 2</p>
</div>
<div id="child">
<p>Div 3</p>
</div>
<div id="child">
<p>Div 4</p>
</div>
</div>
Here is an image of my problem.
http://imgur.com/a/sqdpB
Paragraphs have a margin by default, so just remove that. And to get rid of the line below the image, add vertical-align:top to your img rules:
#parent {
max-width: 850px;
margin: 0 auto;
border: 10px solid black;
}
#child {
background-color: blue;
text-align: center;
color: #eee;
font-size: 56px;
}
img {
width: 100%;
vertical-align: top;
}
p {
margin: 0;
}
<div id="parent">
<div id="child">
<img src="http://s3.amazonaws.com/letsrumbl-marketing/images/8c146690-f04b-4e60-89ca-5e2d979f5a16/HowToShare3.png" />
</div>
<div id="child">
<p>Div 2</p>
</div>
<div id="child">
<p>Div 3</p>
</div>
<div id="child">
<p>Div 4</p>
</div>
</div>
try to set margin and padding to 0px in your paragraph
that should solve your problem
I am running into an issue of trying to center children div while keeping the content aligned left. I have four boxes that are inline, the boxes are set to 25% width and are naturally aligned left. My issue is the four boxes does not look like they are centered on the page because of the natural alignment within the boxes. You can see this in the first image.
So what I thought to do was inside of my .contact-connect-box was to make a child div( connect-box-wrap ), somewhat as a wrap for inside of the box and add margin: 0 auto; , however this is not helping at all.
If you look at the second image, that is what I am after. I want the content to still be aligned left, but the margin for everything to be shifted over so that the box positioning appears centered on the page.
#contact-connect {
width: 80%;
height: auto;
margin: 0 10%;
padding: 80px 0;
}
#contact-connect-box-container {
margin: 0 auto;
width: auto;
/*display: flex;
justify-content: space-around;*/
}
.contact-connect-box {
width: 25%;
margin: 60px 0 0 0;
display: inline-block;
/*border: 1px solid black;*/
vertical-align: top;
opacity: 0;
transition:1s; -webkit-transition:1s;
}
.connect-box-wrap {
margin: 0 auto;
}
<div id="contact-connect">
<div id="contact-connect-box-container">
<div class="contact-connect-box">
<div class="connect-box-wrap">
<h2 class="contact-connect-title">Call</h2>
<div class="contact-connect-description">gfdgg</div>
</div>
</div><div class="contact-connect-box">
<div class="contact-connect-box">
<h2 class="contact-connect-title">Write</h2>
<div class="contact-connect-description">
Reach out to us
<br>
<div id="scroll" class="contact-connect-link">Fill out our contact form.</div>
</div>
</div>
</div><div class="contact-connect-box">
<div class="contact-connect-box">
<h2 class="contact-connect-title">Visit</h2>
<div class="contact-connect-description">
gsdfg
</div>
</div>
</div><div class="contact-connect-box">
<div class="contact-connect-box">
<h2 class="contact-connect-title">Connect</h2>
<div class="contact-connect-description">
<div class="contact-connect-link">Visit us on Facebook</div>
<div class="contact-connect-link">See us on Youtube</div>
<div class="contact-connect-link"></div>
</div>
</div>
</div>
</div>
</div>
I would scrap the .content-connect-box-container because you already have the .content-connect-box so that seems redundant. I did this by centre text aligning .content-connect-box and then left text aligning .connect-box-wrap. Also be careful about how you choose to make your spacing. If you're working in % make sure to stick with that, if you mix % with px, certain screen sizes will break your layout. Feel free to play around with different margin %s in my code to see how I spaced everything.
<div id="contact-connect">
<div class="contact-connect-box">
<div class="connect-box-wrap">
<h2 class="contact-connect-title">Call</h2>
<div class="contact-connect-description">gfdgg hgakhglkrjhg kjshfglkjshd flkjgshfd oweir werowheor weriwjeroija
</div>
</div>
</div>
<div class="contact-connect-box">
<div class="connect-box-wrap">
<h2 class="contact-connect-title">Call</h2>
<div class="contact-connect-description">gfdgg
</div>
</div>
</div>
<div class="contact-connect-box">
<div class="connect-box-wrap">
<h2 class="contact-connect-title">Call</h2>
<div class="contact-connect-description">gfdgg
</div>
</div>
</div>
<div class="contact-connect-box">
<div class="connect-box-wrap">
<h2 class="contact-connect-title">Call</h2>
<div class="contact-connect-description">gfdggaksj
</div>
</div>
</div>
</div>
<style type="text/css">
#contact-connect {
width: 80%;
height: auto;
margin: 0 10%;
padding: 80px 0;
display: block;
}
.contact-connect-box {
width: 21%;
margin: 0 0 0 1%;
display: inline-block;
border: 2px solid black;
vertical-align: top;
text-align: center;
}
.connect-box-wrap {
margin: 10% auto;
width: 50%;
text-align: left;
}
</style>