This question has been asked a bunch and I've looked at them all (seemingly). I have a div with some floating content that won't expand to the size of the content. I've added clear:both (to literally every possible line, which has effects, but doesn't solve it), and I've tried every permutation of overflow:hidden or overflow:auto on pretty much every element in here. Just for good measure I have also tried changing the divs to spans.
Whatever I do, if you make the window skinny enough eventually the buttons fall below the area of the div. Why and how can I fix it?
JSFiddle
.confirmation-modal {
z-index: 1; /* Sit on top */
width: 100%; /* Full width */
height: 4rem;
max-height:18rem;
overflow: auto;
text-align: center;
border-radius:5px;
}
.confirmation-raised-panel{
background-color: #ffed83;
padding: 0px;
text-align: center;
height: 4rem; /* Full height */
max-height:18rem;
overflow: auto;
}
.buttons{
float:right;
}
.confirmation-message {
overflow: auto;
margin: 20px 0 0 30px;
font-size: 1.2rem;
font-weight: 400;
float:left;
}
.clear{
clear:both;
}
<div class="confirmation-modal">
<div class="confirmation-raised-panel">
<div class="confirmation-message">
This is a big message that takes up a bunch of space. Yes indeed. Do you like it?
</div>
<div>
<div class="buttons">
<button>Yes, I'm Sure</button>
<button>Cancel</button>
</div>
<br class="clear"/>
</div>
</div>
</div>
Well, you have height: 4rem; in the outer two containers - this prevents them from getting any higher. Delete that or make that min-height, and you are all set:
.confirmation-modal {
z-index: 1;
/* Sit on top */
width: 100%;
/* Full width */
min-height: 4rem;
max-height: 18rem;
overflow: auto;
text-align: center;
border-radius: 5px;
}
.confirmation-raised-panel {
background-color: #ffed83;
padding: 0px;
text-align: center;
min-height: 4rem;
max-height: 18rem;
overflow: auto;
}
.buttons {
float: right;
}
.confirmation-message {
overflow: auto;
margin: 20px 0 0 30px;
font-size: 1.2rem;
font-weight: 400;
float: left;
}
.clear {
clear: both;
}
<div class="confirmation-modal">
<div class="confirmation-raised-panel">
<div class="confirmation-message">
This is a big message that takes up a bunch of space. Yes indeed. Do you like it?
</div>
<div>
<div class="buttons">
<button>Yes, I'm Sure</button>
<button>Cancel</button>
</div>
<br class="clear" />
</div>
</div>
</div>
You have a fixed height for your modal (height: 4rem), he can't expand.
.confirmation-modal {
width: 100%;
text-align: center;
border-radius: 5px;
background-color: #ffed83;
overflow: hidden;
}
.confirmation-message {
margin: 1rem;
font-size: 1.2rem;
font-weight: bold;
}
.buttons{
float: right;
margin: 0 1rem 1rem;
}
<div class="confirmation-modal">
<p class="confirmation-message">This is a big message that takes up a bunch of space. Yes indeed. Do you like it?</p>
<div class="buttons">
<button>Yes, I'm Sure</button>
<button>Cancel</button>
</div>
</div>
Related
I am new to HTML and CSS and am having trouble positioning and aligning simple text. I am trying to put the text on the right half of the page and have the text be lined up vertically along the first letter of every line. Right now, the header is all the way on the right side of the page, half cut off. The rest of the the rest of the text is not stacked up on top of one another. Rather, there is one block of text on the left, with the other two stacked on top of each other on the right. I have been stuck on this for hours and have read every article on positioning and alignment, but I can't seem to get it. Thanks for the help!
<div class="aboutme"><h3 id="hello">Header</h3></div>
<div class="aboutme"><p id="school">text</p>
</div>
<div class="aboutme"><p id="personal">
text</p>
</div>
<div class="aboutme"><p id="thanks">
text</p>
</div>
.aboutme > *{
font-family: Avenir Next;
display: inline-block;
text-align:left;
float:left;
margin: 0.5em 0.5em 0.5em 0.5em;
position:relative;
left:4em;
}
#hello{
font-size: 3em;
color: #282828;
right: 3.47em;
font-weight: lighter;
position:relative;
text-align: left;
float: right;
margin: 1em 1em 0em 1em;
}
#school {
width: 30em;
clear:right;
}
#personal {
width: 30em;
clear:right;
}
#thanks {
width: 30em;
clear:right;
}
You need to add margin-left: 50% to the about me class and delete the other positioning you have added.
.aboutme > *{
font-family: Avenir Next;
display: block;
margin-left: 50%
}
#hello{
font-size: 3em;
color: #282828;
font-weight: lighter;
}
#school {
width: 30em;
}
#personal {
width: 30em;
}
#thanks {
width: 30em;
}
<div class="aboutme"><h3 id="hello">Header</h3></div>
<div class="aboutme"><p id="school">text</p>
</div>
<div class="aboutme"><p id="personal">
text</p>
</div>
<div class="aboutme"><p id="thanks">
text</p>
</div>
Link to JSFiddle: https://jsfiddle.net/dLy932Lh/
EDIT: Adding a div to the left side
#leftHalf {
display: inline-block;
width: 50%;
height: 200px;
padding: 0;
margin: 0;
}
#rightHalf {
display: inline-block;
width: calc(50% - 10px);
height: auto;
padding: 0;
margin: 0;
background-color: #FFF;
}
.aboutme > *{
font-family: Avenir Next;
display: block;
}
#hello{
font-size: 3em;
color: #282828;
font-weight: lighter;
}
#school {
width: 30em;
}
#personal {
width: 30em;
}
#thanks {
width: 30em;
}
<div id="container">
<div id="leftHalf">
</div>
<div id="rightHalf">
<div class="aboutme">
<h3 id="hello">Header</h3>
</div>
<div class="aboutme"><p id="school">text</p>
</div>
<div class="aboutme">
<p id="personal">text</p>
</div>
<div class="aboutme">
<p id="thanks">text</p>
</div>
</div>
</div>
It is important to have the display set to inline-block for the left and right divs so that they can both be on the same line (hence the inline) and they can have heights and widths (hence the block).
Put any content you want on the left side of the page in the left div and make sure that it's width is not more than 50%.
I hope this solution works for you!
I am creating a web page with 2 <div>s side by side. Each <div> will have 2 sections.
I want to center them (bring them to the middle of the <div>). I am trying to make this <div> responsive. In the website, 2 <div>s will be in one line, while in mobile one <div> will appear on one line and the other <div> will appear on a second line. I am trying to center the image and text of each section.
How can I accomplish that?
.wrapper {
width: 100%;
overflow: hidden;
}
.wrapper div {
min-height: 45px;
padding: 1px;
}
#one {
background-color: gray;
float: left;
width: 50%;
}
#two {
background-color: red;
overflow: hidden;
min-height: 45px;
}
#media screen and (max-width: 400px) {
#one {
float: none;
margin-right: 0;
width: auto;
border: 0;
}
}
<div class="wrapper">
<div id="one">
<img src="http://livebodybuilding.com/images/fast-delivery.png" height="26" width="55" style="float:left; margin-top: 6px;" />
<p style=" font-size:13px; color:#fff; line-height:1.5; font-family: 'Montserrat',sans-serif;"><strong> FREE DELIVERY </strong>ORDERS OVER $100</p>
</div>
<div id="two">
<img src="http://livebodybuilding.com/images/free-gift.png" height="26" width="31" style="float:left; margin-top: 6px;" />
<p style="font-size:13px; color:#fff; line-height:1.5; font-family: 'Montserrat',sans-serif;"><strong> FREE GIFT</strong> ORDERS OVER $100</p>
</div>
</div>
My fiddle: https://jsfiddle.net/4okxw32v/
First of all, the use of floats in layout design is discouraged. It is generally not a good way of doing things, and usually if you're having a layout issue it comes down to a float problem. Instead you should use the display: inline-block setting. When using inline-block there are a couple of things to take into consideration.
Any white space between elements will be shown. To combat this you can set font-size: 0 on the wrapper and then set font-size: 1rem on the children. This will set the font size in the content to the same size as that of the html selector.
You can prevent line-breaking if you set white-space: nowrap on the parent and then set white-space: initial on the children.
Next instead of adding an image and floating it inside the child you can use the css pseudo element ::before (or css2 :before) on the text container inside the element.
Finally to center the contents use text-align: center on the parent
*, *::before, *::after {
box-sizing: border-box;
}
html,
body {
padding: 0px;
margin: 0px;
}
.wrapper {
font-size: 0;
}
.wrapper div {
font-size: 1rem;
min-height: 45px;
padding: 1px;
text-align: center;
font-size: 13px;
color: #fff;
line-height: 1.5;
font-family: 'Montserrat', sans-serif;
overflow: hidden;
display: inline-block;
width: 50%;
}
#one {
background-color: gray;
}
#one p:before {
content: "";
display: inline-block;
width: 4em;
height: 2em;
background-image: url(http://livebodybuilding.com/images/fast-delivery.png);
background-size: cover;
vertical-align: middle;
margin-right: 5px;
}
#two {
background-color: red;
overflow: hidden;
min-height: 45px;
}
#two p:before {
content: "";
display: inline-block;
width: 2.5em;
height: 2em;
background-image: url(http://livebodybuilding.com/images/free-gift.png);
background-size: cover;
vertical-align: middle;
margin-right: 5px;
}
#media screen and (max-width: 620px) {
.wrapper div {
width: 100%;
}
}
<div class="wrapper">
<div id="one">
<p><strong>FREE DELIVERY</strong> ORDERS OVER $100</p>
</div>
<div id="two">
<p><strong>FREE GIFT</strong> ORDERS OVER $100</p>
</div>
</div>
I've a footer styled with CSS which floats at the bottom of the page but when I re-size browser window my footer overlaps my page contents footer is quit big though but it should not overlay the page content.
body {
padding: 0;
margin: 0;
font-family: 'Open Sans', sans-serif;
}
a {
text-decoration: none;
color: #64aba7;
}
strong {
color: #fff
}
.container {
min-height: 500px;
}
.header {
margin-top: 60px;
}
.header,
img {
display: block;
margin-right: auto;
margin-left: auto;
}
.content {
display: block;
margin-right: auto;
margin-left: auto;
text-align: center;
width: 500px;
}
.green-color {
color: #25b04b;
}
.dark-green {
color: #016838;
}
.footer {
width: 100%;
background: #00756f;
position: absolute;
bottom: 0;
}
.footer-container {
display: block;
margin-right: auto;
margin-left: auto;
width: 500px;
padding-top: 20px;
}
.font-size-12px {
font-size: 12px;
color: #64aba7;
font-weight: 50;
}
.one-third {
width: 30%;
float: left;
margin-right: 3%;
padding-bottom: 40px;
}
<div class="container">
<div class="header">
<img src="images/logo-large.png" alt="LegalHQ">
</div>
<div class="content">
<h3 class="green-color">We are redevloping our website and will be back shortly</h3>
<h4 class="dark-green"><i>In the meantime don't hesitate to call or email us</i></h4>
<p class="dark-green">0330 999 1213
<br />hello#legal-hq.co.uk
</p>
</div>
<div class="footer">
<div class="footer-container">
<div class="one-third img-div">
<img src="images/small-logo.gif" alt="LegalHQ">
</div>
<div class="one-third font-size-12px">
<strong>Legal HQ Limited</strong>
<br />Virginia House
<br />Floor 2
<br />5-7 Great Ancoats Street
<br />Manchester
<br />M4 5AD
<br />0161 974 0500
<br />
support#legal-hq.co.uk
<br />
www.legal-hq.co.uk
</div>
<div class="one-third font-size-12px">
<strong>Legal HQ Limited</strong> is regulated by the Ministry of Justice in respect of regulated claims management activities. <strong>Authorisation Number: CRM30929</strong>
www.claimsregulation.gov.uk
</div>
</div>
</div>
</div>
Here is link if you want to experience it yourself. Try and re-size the browser window to the point where you would see footer overlapping the main content.
give the html,body height of 100%, get the footer out of the container, remove position absolute, remove floats from the div-children, and add display:inline-block to them and give them widths of 28% (or remove whitespaces between them) (or otherwise you should use text-align:center for container...but that's another story)
This is driving me crazy. I am relatively new to this stuff so trying to figure this one out for the past hour. I'll be really thankful if someone can help me with this.
I have the following code:
<div class="middle_box">
<div class="box left">
Some large text
</div>
<div class="box right">
Some large text as well
</div>
</div>
CSS:
.middle_box {
height: 260px;
margin: 0 auto;
width: 960px;
}
.box {
float: left;
font-size: 21px;
margin-right: 50px;
margin-top: 25px;
padding-top: 25px;
width: 390px;
}
As you can tell the width of the container is 960px. Now, I want to center the two .box elements within the 960px container and that's where I am lost.
What did I try?
I tried using margin: 0px auto; and I tried faking it by adding margin-left on both sides but it just didn't work. How can I achieve this?
You need to clear ".middle_box", as its children elements are floated.
.middle_box:before, .middle_box:after {
content: "";
display: table;
}
.middle_box:after { clear: both; }
should do the trick
best way to use this hack calls clearfix :
.middle_box:after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0;
}
When you are using fixed widths anyway, 960px and 390px, why not set the margin as well? Easy to calculate, no need for advanced CSS "magic" here in such setup.
.middle_box {
height: 260px;
margin: 0 auto;
width: 960px;
background-color: red;
}
.box {
float: left;
font-size: 21px;
margin-left: 60px; /* <--- */
margin-top: 25px;
padding-top: 25px;
width: 390px;
background-color: yellow;
}
Here's a Fiddle
HTML
With floating - different dimensions
<div class="middle_box">
<div class="box0 left">
Some large text
</div>
<div class="box0 right">
Some large text as well
</div>
</div>
Without floating - same dimensions
<div class="middle_box">
<div class="box1">
Some large text
</div>
<div class="box1">
Some large text as well
</div>
</div>
With clear - one on the top of another
<div class="middle_box">
<div class="box2 clear">
Some large text
</div>
<div class="box2 clear">
Some large text as well
</div>
</div>
CSS
.middle_box {
margin: 0 auto 10px;
width: 960px;
height: 260px;
text-align: center;
text-transform: uppercase;
border: 1px solid #333;
}
.box0 {
font-size: 21px;
padding-top: 25px;
height: 65px;
border: 1px solid #333;
}
.left {
float: left;
width: 585px;
margin: 24px 6px 0 24px;
}
.right {
float: right;
width: 300px;
margin: 24px 24px 0 6px;
}
.box1 {
float: left;
font-size: 21px;
margin-top: 25px;
margin-left: 25px; /* margin-left | calculate 960px - boxes width - borders */
padding-top: 25px;
height: 65px;
width: 438px;
border: 1px solid #333;
}
.box2 {
font-size: 21px;
margin: 25px auto 25px;
padding-top: 25px;
width: 442px;
height: 65px;
border: 1px solid #333;
}
.clear {
clear: both;
}
Centring floats is tough, but do you need to use float? Why not use:
display: inline-block
There are advantages/disadvantages to using both float and inline-block and both have their quirks but ultimately I find inline-block much more useful and easier to develop with. Here is a fiddle for the solution to your problem using inline-block
DEMO FIDDLE
Also a heads up about its white-space quirk if you do use it (but an easy one to fix):
http://css-tricks.com/fighting-the-space-between-inline-block-elements/
I have a problem creating a decent header in CSS. What I want is a <h1> header that aligns its content in the center of its parent <div>. Sometimes though there might be an additional logo displayed as a regular <img /> which should be aligned to the left.
This is my example code:
<div class="container">
<div class="logo">
<img src="http://www.oldfirestation.co.uk/logo_brand_example_86.jpg" />
<h1>Not center?</h1>
</div>
<div class="more">
This is the center
</div>
</div>
And my CSS:
body {
background-color: #161616;
}
div.container {
background-color: #fff;
width: 70%;
margin: auto;
}
div.logo img {
width: 200px;
float: left;
}
h1 {
text-align: center;
font-size: 1.4em;
margin: 0px auto;
padding: 0px 0px 5px 0px;
width: 50%;
}
div.more {
text-align: center;
margin-top: 50px;
clear: left;
}
The problem is that when I show an <img />, my <h1> text is NOT centered. If I remove this <img /> it is... How can I fix it??
I have made an example on JSFiddle here: http://jsfiddle.net/8B9ZF/
You do like this:
div.logo img {
width: 200px;
vertical-align:middle;
}
h1 {
text-align: center;
font-size: 1.4em;
margin: 0px auto;
padding: 0px 0px 5px 0px;
width: 50%;
display:inline-block;
}
http://jsfiddle.net/8B9ZF/8/
May be you can change your mark-up
http://jsfiddle.net/8B9ZF/24/
If you make the image absolutely positioned at 0,0 instead of floating it then it won't push the H1 out of center alingment. But you then run the danger of the image overlapping the text if the image is too wide, or the container of the heading too small. To counter this, you probably want to add some padding to the left/right of the container
http://jsfiddle.net/8B9ZF/27/
this should always work as far as i know! basically this just adds overflow hidden, which makes the h1 aware of the space taken by the floated element so it takes up the remaining area!
body {
background-color: #161616;
}
div.container {
background-color: #fff;
width: 70%;
margin: auto;
}
div.logo{
overflow:hidden
}
div.logo img {
width: 200px;
float: left;
}
h1 {
text-align: center;
font-size: 1.4em;
padding: 0px 0px 5px 0px;
}
div.more {
text-align: center;
margin-top: 50px;
clear: left;
}