Simple question, but I'm struggling with solution.
Jsfiddle here.
How can I get the title and date to both align to the bottom of the container, while ensuring that:
The length of the title will push the date across (but doesn't need to wrap)
The blue button is always centrally aligned between the date and the red icon
The titleBar container is always the same fixed height
Need a CSS-only solution if possible - I already know how to do this with JS if needed
HTML:
div class="titlebar bgEarth0">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
<div class="icon"></div>
<div class="buttonArea">
<div class="button"></div>
</div>
</div>
CSS:
.titlebar { height: 50px; border:1px solid #000}
#title {font-size: 20px; font-weight: normal; float: left; margin:0}
#date { font-size: 12px; font-weight: normal; float: left; margin-left: 30px; margin:0 12px}
.buttonArea {position:relative; overflow:auto; height:40px; margin-top:5px}
.button {margin:0 auto; width:60px; height:40px; background:#0000ff}
.icon {float:right; background:#ff0000; height:40px; width:60px; margin-top:5px}
http://jsfiddle.net/hC236/
You can use absolute position.
Wrap title and date with a div and set its position to absolute.
HTML:
<div class="titlebar bgEarth0">
<div class="bleh">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
</div>
<div class="icon">ddd</div>
<div class="buttonArea">
<div class="button"></div>
</div>
</div>
CSS:
.titlebar {
height: 50px;
border:1px solid #000;
position: relative;
}
.bleh {
position: absolute;
bottom: 0px;
left: 0px;
}
#title {
font-size: 20px;
font-weight: normal;
float: left;
margin:0
}
#date {
font-size: 12px;
font-weight: normal;
float: left;
margin-left: 30px;
margin:0 12px
}
.buttonArea {
position: absolute;
overflow:auto;
height:40px;
top:5px;
right: 0px;
}
.button {
margin:0 auto;
width:60px;
height:40px;
background:#0000ff
}
.icon {
background:#ff0000;
height:40px;
width:60px;
margin-top: 5px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
OR Table Example:
http://jsfiddle.net/hjM56/
HTML:
<div class="titlebar">
<div class="col-1">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
</div>
<div class="col-2">
<div class="icon"></div>
</div>
<div class="col-3">
<div class="button"></div>
</div>
</div>
CSS:
.titlebar {
display: table;
height: 50px;
border: 1px solid #000;
width: 100%;
}
.col-1,
.col-2,
.col-3 { display: table-cell; }
.col-1 {
white-space: nowrap;
vertical-align: bottom;
width: 1%;
}
.col-2 {
text-align: center;
width: auto;
}
.col-3 {
text-align: right;
width: 1%;
}
#title {
font-size: 20px;
font-weight: normal;
display: inline-block;
margin: 0px;
padding: 0px;
}
#date {
font-size: 12px;
font-weight: normal;
margin-left: 12px;
margin-top: 0px;
margin-right: 12px;
margin-bottom: 0px;
display: inline-block;
padding: 0px;
}
.button {
width: 60px;
height: 40px;
background: #0000ff;
margin-top: 5;
display: inline-block;
}
.icon {
background: #ff0000;
height: 40px;
width: 60px;
margin-top: 5px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
Here is one way to do it but it involves some extra mark-up.
I added some wrappers around the title and date as follows:
<div class="titlebar">
<div id="titleArea">
<div id="table-wrap">
<div id="table-cell">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
</div>
</div>
</div>
<div class="icon"></div>
<div class="buttonArea">
<div class="button"></div>
</div>
</div>
Apply the following CSS:
.titlebar {
height: 50px;
border:1px solid #000
}
#titleArea {
height:40px;
margin-top:5px;
float: left;
}
#table-wrap {
display: table;
height: 100%;
}
#table-cell {
display: table-cell;
height: 100%;
vertical-align: bottom;
}
#title {
font-size: 20px;
font-weight: normal;
padding:0;
display: inline;
}
#date {
font-size: 12px;
font-weight: normal;
padding-left: 12px;
display: inline;
}
.buttonArea {
position:relative;
overflow:auto;
height:40px;
margin-top:5px;
border: 1px dotted blue;
}
.button {
margin:0 auto;
width:60px;
height:40px;
background:#0000ff
}
.icon {
float:right;
background:#ff0000;
height:40px;
width:60px;
margin-top:5px;
border: 1px dotted blue; /* for demo only */
}
See demo at: http://jsfiddle.net/audetwebdesign/5NDDQ/
I created an outer wrapper #titleArea that has the same height and top margin as the #buttonArea.
Within #titleArea, I created a CSS table/table-cell (two nested div's) so that I can get the vertical alignment to be at the bottom.
Finally, I set display: inline to #title and #date.
A detail that may need adjustment involves the base line of the title and time. The bottom leading causes the text to sit slightly above the bottom edge of the button.
It seems like a lot of work for what appears to be a relatively simple requirement.
To make this a bit more bullet-proof, I would add a min-width to the .titlebar to prevent the .buttonArea to develop a horizontal scroll bar and the .icon from wrapping to a second line.
You shouldn't use floating unless necessary. See this JSFiddle Live Demo
Basically if you remove the floats and display:inline-block; instead, they will align. I also removed the overflow:auto, as that would limit the icon area.
Also, adding left:15%; will align the blue area between the date and the red area.
EDIT: Example with max-width specifications to contain the div inside the title bar. Live Demo
Related
I've got three DIVs that I've put into a container DIV.
What I want is as follows:
Here's where I'm up to:
#light-table {
background-color: #e2e2e2;
width: 100%;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 40px;
padding-right: 40px;
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
}
#leftdiv {
float: left;
padding: 0 20px;
/*margin:20px 0;*/
position: relative;
width: 25%;
flex-basis: 25%;
}
#leftdivcontainer {
vertical-align: middle;
width: 100%;
text-align: center;
}
#light-table-paragraph {
font-family: 'Droid Serif';
font-size: 20px;
color: #2e2e2e;
text-align: left;
line-height: 40px;
}
<div id="light-table">
<h3 id="light-table-head-style">content.</h3>
<div id="leftdivcontainer">
<div id="leftdiv">
<p id="light-table-paragraph">Left</p>
</div>
<div id="leftdiv">
<p id="light-table-paragraph">Middle</p>
</div>
<div id="leftdiv">
<p id="light-table-paragraph">Right</p>
</div>
</div>
</div>
Please can someone help tell me where I'm going wrong?
Thanks!
Scott
set the div the contains the three small divs display:flex and give it 75% width of the container, then set space around the content as follow:
#leftdiv {
/*float: left;*/
padding:0 20px;
/*margin:20px 0;*/
position:relative;
/* edits */
width:33.33%;
flex-basis: 25%;
}
#leftdivcontainer {
vertical-align:middle;
text-align: center;
/* edits */
width:75%;
display: flex;
margin: 0px auto;
justify-content: space-around;
}
#light-table-paragraph {
font-family: 'Droid Serif';
font-size: 20px;
color: #2e2e2e;
text-align: left;
line-height:40px;
}
#light-table {
background-color: #e2e2e2;
width: 100%;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 40px;
padding-right: 40px;
text-align: left;
margin-top:30px;
margin-bottom: 30px;
}
<div id="light-table">
<h3 id="light-table-head-style">content.</h3>
<div id="leftdivcontainer">
<div id="leftdiv"><p id="light-table-paragraph">Left</p></div>
<div id="leftdiv"><p id="light-table-paragraph">Middle</p></div>
<div id="leftdiv"><p id="light-table-paragraph">Right</p></div>
</div>
</div>
Here's how I would do it.
Give each .leftdiv (indeed this should be a class, id's are unique) 33% of total viewport width:
.leftdiv {
float: left;
width: 33%;
}
and center each paragraph inside these divs, give it 75% width:
.leftdiv p {
display: block;
width: 75%;
margin: 0 auto !important; /* you won't need !important if your code is well structured */
}
This is a cleaner solution, as you'll notice there is no horizontal scroll present.
Here is a codepen.
Also, you need to clear your parent div #leftdivcontainer (did that as well).
Hope this helps.
I have two DIVs, one is left floated with bigger font size and the other one is right floated with smaller fonts. I want to align the smaller fonted DIV to the bottom aligned with the bigger sized text. Not able to achieve it.
and the css
.floatLeft {
float: left;
}
.floatRight {
float: right;
}
.font12 {
font-size: 12px;
}
<div class="floatLeft">Activity</div>
<div class="floatRight font12 ">View timeline / Filter activities</div>
Answer changed to allow for float as per your request.
Please see FIDDLE.
HTML
<div class="big">Activity</div>
<div class="small">
<a href="javascript:void(0);">View timeline / Filter activities
</a>
</div>
CSS
.big {
float: left;
font-size: 2em
}
.small {
float: right;
position: relative;
font-size: 1em;
top: 13px;
}
Demo page
CSS needed:
.big {
display:inline-block;
vertical-align:bottom;
/* just for demo: */
font-size: 2em;
height:200px;
background:#FADDFF;
}
.small {
display:inline-block;
vertical-align:bottom;
/* just for demo: */
font-size: 1em;
background:#D2E9F7;
height:120px;
}
so making the two elements inline-block displayed, and vertical-align with value of bottom, they will be on the same level, and they're line of reference will be the bottom of them both
Additional to the above response, you can use display: table-cell to fit both div's to the same height:
.floatLeft {
border: 1px solid black;
font-size: 30px;
width: 200px;
display: table-cell;
vertical-align: text-bottom;
}
.floatRight {
border: 1px solid black;
font-size: 12px;
display: table-cell;
vertical-align: text-bottom;
width: 200px;
}
<div class="floatLeft">Activity</div>
<div class="floatRight font12 ">View timeline / Filter activities</div>
Here is the jsfiddle: https://jsfiddle.net/x3m72kqh/
JSFiddle: Solution in JSFiddle
Here is a solution with inline-block :
.big {
display:inline-block;
width: 50%;
float: left;
font-size: 2em
}
.small {
display:inline-block;
width: 50%;
font-size: 1em
}
a {
float:right;
}
I've been trying to find a solution to this for days, but haven't found anything that works.
I thought I'd finally make an account on this great website, so here goes:
I am trying to have a div expand from left to right, with 170px of clearance on both sides.
However, when there is no content on the page, or only a few words, the div doesn't expand.
I've tried to add width: 100% in several different divs to try and have them take up the full space, but that either does nothing, or completely busts the page layout. for example, instead of filling out the page, the div that's supposed to hold the content moves off the right side of the screen, and also doesn't leave the 170px margin.
I hope you can be of help, my code is posted below:
Thanks in advance,
Chris
the html:
<html>
<body>
<div id="wrapper">
<div id="pagetopwrap">
</div>
<div id="pagemainliquid">
<div id="pagemainwrap">
<div id="content">
<div id="headerwrap">
<div id="header_left">
</div>
<div id="header_main">
<div id="logo_row">
<p id="logotext">Site Title</p>
</div>
<div id="menu_row">
<!-- irrelevant menu button code -->
</div>
</div>
<div id="header_right">
</div>
</div>
<div id="contentbody">
<div id="contenttext">
<p id="contenttextmakeup">Lorum Ipsum Dolor Sit Amet</p>
</div>
</div>
</div>
</div>
</div>
<div id="leftcolumnwrap">
<div id="leftcolumn">
</div>
</div>
<div id="rightcolumnwrap">
<div id="rightcolumn">
</div>
</div>
<div id="footerwrap">
<div id="footer">
</div>
</div>
</div>
</body>
</html>
the css:
It is not ordered too well, the uninteresting sides, top and footer are first, and the main part of the website at the bottom
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
background-color: #0f0f0f; /* is normally an image */
}
#wrapper {
width: 100%;
min-width: 960px;
max-width: 1920px;
margin: 0 auto;
height: 100%
}
#pagetopwrap {
height: 50px;
width: 100%;
float: left;
margin: 0 auto;
}
#pagemainliquid {
float: left;
}
#pagemainwrap {
margin-left: 170px;
margin-right: 170px;
float: left;
}
#leftcolumnwrap {
width: 170px;
margin-left:-100%;
float: left;
}
#leftcolumn {
margin: 5px;
}
#rightcolumnwrap {
width: 170px;
margin-left: -150px;
float: left;
}
#rightcolumn {
margin: 5px;
}
#footerwrap {
width: 100%;
float: left;
margin: 0 auto;
clear: both;
bottom:50px;
}
#footer {
height: 0px;
margin: 5px;
}
#headerwrap {
width: 100%;
margin: 0 auto;
}
#header_left {
background-color: #ff0000; /* is normally an image */
width:25px;
height:200px;
float:left;
}
#header_right {
background-color: #ff0000; /* is normally an image */
width:25px;
height:200px;
margin-left: 0px;
float:right;
position:relative; top:-200px;
}
#header_main {
background-color: #00ff00; /* is normally an image */
margin-left: 25px;
margin-right: 25px;
height:200px;
background-size: 100% 200px;
}
#contentbody {
background-color: #E2E2E2;
border-radius: 10px;
margin-top:10px;
border: 1px solid #A7A7B2;
}
#contenttext {
margin-left:10px;
margin-right:10px;
}
#logo_row {
height:150px;
width:100%;
float:left;
}
#logotext {
margin-top:20px;
margin-left:10px;
vertical-align: middle;
font-size: 55px;
font-family: "Arial Black", Arial;
}
#contenttextmakeup {
margin-top:12px;
margin-left:10px;
vertical-align: middle;
}
#menu_row {
width:100%;
}
button.menubutton {
/* irrelevant button markup */
}
http://jsfiddle.net/w9qLh6tp/ if that helps, I've seen it a lot around here :)
Instead of using !important, save yourself a headache in figuring out why important works.
CSS = cascading style sheets. You have a selector with more specificity which is why your width property isnt changing. Figuring out the route of the problem will save you time in the future when this happens again (and it will)
For example, if I styled something like so
#container .red { width: 50% }
updating the style using .red without the #container in front of it has less specificity. So if they are both modifying the same property, the one with more prevalence will take effect. This is true for media queries as well.
Fixed here http://jsfiddle.net/w9qLh6tp/1/
#pagemainwrap {
margin-left: 170px;
margin-right: 170px;
float: left;
width: 100% !important; // set it highest priority
border: 3px red solid; // border is set just for demonstration
}
set the width to be 100% with priority (!important) that will override any other css styling.
How do I make two (or more) floating divs appear like "big buttons" and let them float and be leveled? My problem is that the boxes are "partially leveled"... with one slightly lower than the other. I have tried to use float: left on the adminBox, but then they grow outside the container. Can anyone help me?
I have used this HTML code:
(http://jsfiddle.net/jf936/13/)
<div class="container">
<div class="adminBox">
<h2>Manage users</h2>
<div class="adminBoxLargeContent" data-bind="text: usersCount"></div>
<div class="adminBoxSmallContent">Registered users</div>
</div>
<div class="adminBox">
<h2>Manage templates</h2>
<div class="adminBoxLargeContent" data-bind="text: templateCount"></div>
</div>
and this style:
.container{
background-color: light-blue;
}
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
}
.adminBox h2{
color:white;
font-size:20px;
text-align:center;
}
.adminBoxLargeContent{
font-size: 70px;
text-align:center;
padding: 0;
margin: 0;
line-height: 1;
}
.adminBox .adminBoxSmallContent{
float: none;
text-align:center;
}
This has nothing to do with float, the issue is that you are using display: inline-block; and hence the element are aligned to the baseline, inorder to fix this, you need to use vertical-align: top;
Demo
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
vertical-align: top; /* Add this here */
}
Note: You don't have to use float: none; as nothing is floated here, so you can get rid of those unused properties.
Here you go.
WORKING DEMO
The CSS Code Change:
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
float:left;
}
Hope this helps.
Maybe this code will be helpful for you:
jsfiddle
.container{
background-color: light-blue;
overflow:hidden;
}
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: block;
margin: 5px;
float:left;
}
.adminBox h2{
color:white;
font-size:20px;
text-align:center;
}
.adminBoxLargeContent{
font-size: 70px;
text-align:center;
padding: 0;
margin: 0;
line-height: 1;
}
.adminBox .adminBoxSmallContent{
text-align:center;
}
<div class="container">
<div class="adminBox">
<h2>Manage users</h2>
<div class="adminBoxLargeContent" data-bind="text: usersCount"></div>
<div class="adminBoxSmallContent">Registered users</div>
</div>
<div class="adminBox">
<h2>Manage templates</h2>
<div class="adminBoxLargeContent" data-bind="text: templateCount"></div>
</div>
</div>
Having trouble centering some logos. I tried to used margin: auto as well as text-align: center but can't seem to get it working.
JSfiddle
would you like something like this?
I add this class
#footer-container {
width: 100%;
display: inline-block;
text-align: center;
}
and made some changes in this class ( ex: remove the float )
.button-circle {
display: inline-block;
width: 66px;
height: 50px;
padding: 0px;
margin-top: 20px;
margin-right: 50px;
}
It will looks like this .I think that it is your desire result!
Try:
#footer-container{
text-align:center;
}
.button-circle:last-of-type{ /*remove right margin from last div*/
margin-right:0;
}
.button-circle {
display: inline-block;
}
NOTE:
inline-block adds white-space between elements. Write elements on same line to remove white-space.
Write:
<div class="button-circle">.........</div><div class="button-circle">...
Instead of:
<div class="button-circle">
.......
</div>
<div class="button-circle">
.......
</div>
DEMO here.
I have given both the code html and css check it
<div id="footer-container">
<div id="followicon">
<div class="button-circle">
<div class="bild"><img src="http://i.imgur.com/1faoLxr.jpg" style="width: 66px"></div>
<div class="block">facebook</div>
</div>
<div class="button-circle">
<div class="bild"><img src="http://i.imgur.com/hVdiFAx.jpg" style="width: 66px"></div>
<div class="block">twitter</div>
</div>
<div class="button-circle">
<div class="bild"><img src="http://i.imgur.com/WJGtp0A.jpg" style="width: 66px"></div>
<div class="block">vimeo</div>
</div>
</div><!--end of the followicon -->
</div>
<div>
//css code
#footer-container {
width:100%;
height:200px;
border:1px solid #000;
}
#followicon {
position:relative;
width:350px;
height:200px;
margin:0px auto;
}
.block{
position:relative;
width: 66px;
height: 25px;
top:0px;
z-index:100;
opacity: 0;
margin-top: -5px;
text-align: center;
text-transform:uppercase;
}
.button-circle {
display: inline;
float: left;
width: 66px;
height: 50px;
padding: 13px;
margin-top: 20px;
margin-right: 10px;
margin-left:13px;
}
.bild {
position:relative;
height: 100%;
top: 0px;
}