how to vertically align div opposite to each other - html

I have placed two div opposite to each other using display:inline-block, now i want the div at right side should be centered with respect to left side div.
I have tried using following,
HTML:
<div class="header_first_above">
<div class="first_above">
<div class="logo">
<p><img src="assets/img/logo_new.jpg" /></p>
</div>
<div class="icons">
sd
</div>
</div>
</div>
CSS:
.header_first_above {
width: 90%;
height: 150px;
background: #FFFFFF;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
position: absolute;
left: 5%;
margin: 0 auto;
top: 0;
-moz-box-shadow: 0 0 15px #ccc;
-webkit-box-shadow: 0 0 15px #ccc;
box-shadow: 0 0 15px #ccc;
}
.header_first_above .first_above {
width: 100%;
}
.header_first_above .first_above .logo {
width: 20%;
padding: 10px;
display: inline-block;
}
.header_first_above .first_above .icons {
width: 77%;
display: inline-block;
color: red;
text-align: right;
background: #F1B0B1;
position: absolute;
margin: 0;
top: 10%;
}
current output,
required output,
How to make this. I have tried a lot.

One solution is to use display:table
http://jsbin.com/sulopikuso/1/edit?html,css,output
Another solution is to use display:flex
http://jsbin.com/yififomiso/edit?html,css,output
In case of using Flex version be aware of browser support http://caniuse.com/#search=flexbox and it's vendor prefixes.

You can remove position:absolute and use css calc for calculating the width of .icons and don't forget to remove extra spaces which is occurred by display:inline-block;
Jsfiddle
.header_first_above {
width: 90%;
height: 150px;
background: #FFFFFF;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
position: absolute;
left: 5%;
margin: 0 auto;
top: 0;
-moz-box-shadow: 0 0 15px #ccc;
-webkit-box-shadow: 0 0 15px #ccc;
box-shadow: 0 0 15px #ccc;
}
.header_first_above .first_above {
width: 100%;
}
.header_first_above .first_above .logo {
width: 20%;
padding: 10px;
display: inline-block;
background-color: red;
}
.header_first_above .first_above .icons {
width: calc(100% - 20% - 20px);
display: inline-block;
color: red;
text-align: right;
background: #F1B0B1;
margin: 0;
}
<div class="header_first_above">
<div class="first_above">
<div class="logo">
<p>
<img src="assets/img/logo_new.jpg" />
</p>
</div><!--
--><div class="icons">
sd
</div>
</div>
</div>

If you know the height of the div you want vertically centered, one trick you can use is absolute or relative positioning with a negative top margin as so:
.header_first_above .first_above .icons {
position: relative;
top: 50%;
height: 150px;
margin-top: -75px;
}

Related

Stop the text moving down on hover

I have a text in the middle of the div block with a font size 80px. When I hover on the div block, it will change the border size from 1px to 5px with a blue color but the text will moves down.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.calendarday-number:hover {
margin: 12px 2px;
}
.calendarday-container:hover {
border: 5px solid #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Jsfiddle: http://jsfiddle.net/f0k6r9nb/
I have tried to change the margin in the calendarday-container:hover .add-day-ico but it didn't help to resolve the issue.
Can you please show me an example how I can stop the text moving down on hover?
Thank you.
Changing the width of the border from 1px to 5px and recalculating the inner parts is not a practical solution. You could use an additional element, which has 5px of transparent border and change it to 5px of colored border on hover.
Another simple solution would be to use outline instead, as it doesn't add to the elements dimensions:
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-container:hover {
outline: 5px solid #2e7ad1;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.add-day-ico {
opacity: 0;
width: 21px;
height: 21px;
position: absolute;
bottom: 0;
right: 0;
}
.calendarday-container:hover img {
opacity: 1;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" class="add-day-ico">
</a>
</div>
A typical approach to showing a border on hover is to have the non-hover state be transparent or a color that matches the background along with the width matching that of the border when hovered.
In this case, there's an existing 1px border. Here, I would change the gray border blue, then use an inset box-shadow to add the additional 4px of the border.
Note: I also removed some margin for .calendarday-number on hover so the number does not shift.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
/*
.calendarday-number:hover {
margin: 12px 2px;
}
*/
.calendarday-container:hover {
border-color: #2e7ad1;
box-shadow: inset 0 0 0 4px #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Add this:
.calendarday-container {
border: 5px solid transparent;
outline: 1px solid #ccc;
outline: none;
}
.calendarday-container:hover {
outline: none;
}
Remove this:
.calendarday-number:hover {
margin: 12px 2px;
}
You can use a pseudo element like this. I also removed lot of unnecessary css that was fighting each other
* { margin: 0; padding: 0; box-sizing: border-box; }
body { margin: 5%; }
/* Normal */
.calendarday-container {
width: 150px; height: 150px;
position: relative;
display: flex; align-items: center; justify-content: center;
}
.calendarday-container:after {
content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
border: 1px solid #ccc; z-index: -1;
}
.caldndarday-add { text-decoration: none; }
.calendarday-number { font-size: 80px; color: #ccc; }
.add-day-ico { width: 24px; height: 24px; position: absolute; bottom: -8px; right: -8px; }
/* Hover FX */
.calendarday-container:hover:after { border: 10px solid navy; }
.calendarday-container:hover .calendarday-number { color: navy; }
<div class="calendarday-container" data-day="0" data-dropable="true">
<a class="caldndarday-add" href="/autoresponder/create_day.php?day=0" data-action="click">
<span class="calendarday-number">0</span>
<img class="add-day-ico" src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png">
</a>
</div>
The text was moving down because, There was increase in border-width from 1px to 5px while hover.
You can either maintain a outline around the box using outline property, and keeping the border: 5px solid transparent to border: 5px solid #2e7ad1 while hovering.
I've created a working fiddle for you, for better understanding: Link to Jsfiddle

:before and :after not showing when site is pushed

I am trying to use :before and :after elements to spice up my page, but when I push it, the live site does not have them. On my local computer, both :before and :after is showing up correctly. My live site is here: https://findingfutures.eu
I am using Netlify and Github to push my site. I have tried adding the code to a codepen, and the elements are being displayed correctly there: https://codepen.io/Barsnes/pen/pKBzrK
Here is my code, with a lot of removed content to make it simpler,
.products_design:before {
content: " ";
display: block;
width: 70%;
height: .3em;
position: absolute;
background: #FFF;
top: -16.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.products_design:after {
content: " ";
display: block;
width: 70%;
height: .3em;
position: absolute;
background: #FFF;
bottom: -10.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.products_design {
position: relative;
height: auto;
width: 80vw;
margin: 25em 10vw 10em 10vw;
display: inline-block;
box-shadow: 0 0 30px #00000030;
background: linear-gradient(to top right, #23232320, #23232305);
}
.products_design h1 {
display: block;
position: absolute;
top: -2em;
line-height: .8em;
text-transform: uppercase;
text-shadow: 0 0 10px #00000060;
}
.products_design span {
display: block;
}
.products_design img {
width: 100%;
height: auto;
padding: 0;
margin: 0;
}
.project_1,
.project_2,
.project_3,
.project_4,
.project_5,
.project_6 {
width: 33.33%;
float: left;
padding: 0;
margin: 0;
position: relative;
display: block;
}
.products_design h2 {
font-size: 1.8em;
padding: .4em .4em 0 .2em;
}
.products_design p {
padding: .4em .4em 2em .4em;
font-size: 1em;
margin-bottom: 3em;
}
.products_design a {
display: block;
color: orange;
margin: auto;
position: relative;
text-decoration: none;
}
.products_design a:hover {
text-shadow: 0 0 10px #000;
color: #FFFFFF
}
<div class="products_design">
<div class="products">
<div class="products_title">
<h1>our past<span>projects</span></h1>
</div>
</div>
<div class="project_1">
<img src="images/projects/project__tobias_barsnes_website.png" />
<h2>Portfolio Website</h2>
<p>LoremClick to view project</p>
</div>
<div class="project_2">
<img src="images/projects/project__portrait_photography.png">
<h2>Portrait Photography</h2>
<p>LoremClick to view project</p>
</div>
<div class="project_3">
<img src="https://source.unsplash.com/1920x1080/?photoshop">
<h2>Design</h2>
<p>LoremClick to view project</p>
</div>
</div>
Pseudo elements does not work well with #import, and can therefor cause problems in the browser.
If you move all your ::before and ::after to the main css wihtout using #import, it should work perfectly.
Correct Example Code
#import url("_styles/header.css");
#import url("_styles/body.css");
.products_design::before {
content: " ";
display: block;
width: 70%;
height: 5px;
position: absolute;
background: #FFF;
top: -16.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.products_design::after {
content: " ";
display: block;
width: 70%;
height: 5px;
position: absolute;
background: #FFF;
bottom: -10.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.about_images::before {
content:" ";
display: block;
width: 50%;
margin-left: 25%;
height: 5px;
background: #FFF;
position: absolute;
top: -13em;
box-shadow: 0 0 20px #00000040
}
Wrong Example Code
#import url("_styles/media_query.css");
#import url("_styles/cookie.css");
#import url("_styles/pseudeo_elements.css");
It's ::before and ::after.
For some environments selectors may work with a single :, but it's not the proper syntax in CSS3.
Update:
:before and ::before will both work, as CSS3 is backwards compatible with CSS2, as CBroe pointed out.

Expanding Divs with text

I have the following. However, I've been trying to get the blue title area to expand with the outter div and the arrow to be aligned in the middle. I have an outer div set at 25% just so the text wraps.
.breakingNewsRec {
width: 100%;
background: #FFF;
position: relative;
border: solid 2px #6A7791;
}
.breakingNewsRec>.bn-rec {
width: auto;
display: inline-block;
background: #6A7791;
position: relative;
margin-right: 20px;
}
.breakingNewsRec>.bn-rec>h2 {
display: inline-block;
margin: 0;
padding: 0 20px;
line-height: 40px;
font-size: 0.8em;
color: #FFF;
box-sizing: border-box;
}
.breakingNewsRec>.bn-rec>span {
position: absolute;
right: -10px;
top: 10px;
height: 0;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #6A7791;
}
.breakingNewsTown {
width: 100%;
height: 40px;
background: #FFF;
position: relative;
border: solid 2px #74936A;
}
.breakingNewsTown>.bn-rec {
width: auto;
height: 40px;
display: inline-block;
background: #74936A;
position: relative;
margin-right: 20px;
}
.breakingNewsTown>.bn-rec>h2 {
display: inline-block;
margin: 0;
padding: 0 20px;
line-height: 40px;
font-size: 0.8em;
color: #FFF;
height: 40px;
box-sizing: border-box;
}
.breakingNewsTown>.bn-rec>span {
width: 0;
position: absolute;
right: -10px;
top: 10px;
height: 0;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #74936A;
}
<div style="width: 25%">
<div class="breakingNewsRec">
<div class="bn-rec">
<h2>Recreation News</h2><span></span>
</div>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj
<img src="imgs/slides/slide2.jpg" width="25%">asdfljas dflkjsdf alskdjf asdfl</div>
<div class="breakingNewsTown">
<div class="bn-rec">
<h2>Town News</h2><span></span>
</div>fareveae vasev</div>
</div>
Using display:table-cell this is very easy to accomplish:
#news {
width: 50%;
}
#news .item {
border-width: 1px;
border-style: solid;
}
#news .item h2 {
color: white;
font-size: 100%;
white-space: nowrap;
position: relative;
border-color: inherit;
}
#news .item h2:after {
content: '';
display: inline-block;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent;
border-left-color: inherit;
vertical-align: middle;
position: absolute;
left: 100%;
}
#news .item h2,
#news .item div {
display: table-cell;
vertical-align: middle;
padding: 0 1.5em;
}
.style1 { border-color: #697791 }
.style1 h2 { background: #697791 }
.style2 { border-color: #74936a }
.style2 h2 { background: #74936a }
<div id="news">
<div class="item style1">
<h2>Recreation News</h2>
<div>
<p>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj asdfljas dflkjsdf alskdjf asdfl</p>
</div>
</div>
<div class="item style2">
<h2>Town News</h2>
<div>
<p>fareveae vasev</p>
</div>
</div>
</div>
I am not sure exactly what you are trying to achieve, but it sounds like something like this:
which would just be applying width:100%; to .bn-rec
EDIT
Regarding your comment - I think I understand then. How about surrounding the text in a <div> and making both <div> tags display:inline-block; and restricting their width by %. Then increasing the margin of the arrow, also by a % like I did here:
https://jsfiddle.net/030y329m/
Is that closer to what you were thinking?

Is it possible to center div with "absolute" parent?

<style type="text/css">
.square {
width:251px;
height:207px;
border: 1px solid #d6d6d6;
-webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.1);
-moz-box-shadow: 1px 1px 3px rgba(0,0,0,.1);
box-shadow: 1px 1px 3px rgba(0,0,0,.1);
margin: 10px;
overflow: hidden;
position: relative;
background-color:#fff;
/*display: inline-block;*/
float: left;
cursor: pointer;
text-align: left;
}
.square img {
display: block;
margin: 0px;
padding: 9px;
width:234px !important;
height:190px !important;
position:absolute;
}
.square .caption {
width:214px;
height:170px;
background:#000;
color:#fff;
padding:10px;
position:absolute;
left:9px;
top:9px;
/*display:none;*/
filter:alpha(opacity=80);
-moz-opacity:0.8;
-khtml-opacity: 0.8;
opacity: 0.8;
}
.square .text{
border:1px dotted #d6d6d6;
margin: 10px;
padding: 5px;
vertical-align: center;
max-height: 100px;
overflow: auto;
}
.square .until {
font-size: 12px;
font-style: italic;
position: absolute;
right: 10px;
bottom: 5px;
}
</style>
<div class="square">
<a href="/" >
<img width="234" height="190" src="files/2011/12/17.jpg" alt="17" title="17"/>
</a>
<a href="/" rel="bookmark">
<div class="caption">
<h2>Half A Beatle</h2>
<div class="text">lol</div>
<div class="until">Until: 01 01 2012</div>
</div>
</a>
</div>
So is it possible to center div in current situation?
It's entirely possible with CSS alone, though you'd need to make some interesting changes that don't work in IE6 / 7.
If your parent container is set to display: table-cell and vertical-align: middle with the child element set to display: inline-block, you'll get a table-like effect where the content is centered in the middle.
See for yourself!
it is little late but here is my answer ...
the trick is to have a helper div besides our text container div like the code below ...
i hope this helps :D
<div style=" position: absolute;
display: inline-block;
top: 20%;
bottom: 20%;
right: 20%;
left: 20%;
background-color: #434154;
text-align: center;">
<div style="display: inline-block;
height: 100%;
vertical-align: middle;"></div>
<div style="position: relative;
color: #FFFFFF;
background-color: #546354;
display: inline-block;
vertical-align: middle;">
THIS IS CENTERED WITHOUT SCRIPTING :D
</div>
</div>
If you know the height of the div you are centering (I'm going to assume it is .text), then you can do:
.square .text {
height: 100px;
top: 50%;
margin-top: -50px; /* This should be half of height */
}
All this does if places the top of the div at 50% of the parent container. The margin-top pushes it up so the center is at the center of the parent.
Edit: Show example using transforms:
.square .text{
border:1px dotted #d6d6d6;
margin: 0 10px;
padding: 5px;
vertical-align: center;
max-height: 100px;
overflow: auto;
position: absolute;
left: 0;
right: 0;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
}
This won't work on browsers that don't support tranforms though. See this http://jsfiddle.net/WEQVK/

make progress bar dynamically change width to size of the rest of the container

I have an audio player that i built with jquery. The markup and css is relatively simple but I cannot get the progress bar to change width with the width of the whole container.
It is set as a percentage but does not behave as a child of the container div. I am guessing it is something to do with the position being absolute but if i change that the whole thing goes wrong.
Here is the markup
<div class="container gradient">
<div style="width:100px; overflow:hidden; display:inline-block;"><img src="" class="artwork" height="100%"></div>
<div class="name">
<p1><br>
<b></b></p1>
</div>
<div class="logo" style="font-size:12px; text-align:right; font-weight:bold;">
<br>
<br>
</div>
<div class="player gradient">
<a class="controls gradient" id="play" href="" title=""></a>
<input type="range" id="seek" value="0" max=""/>
</div><!-- / player -->
</div><!-- / Container-->
And the css
.gradient {
border: 1px solid #C4C4C4;
background: #F2F2F2;
}
.container {
position: absolute;
width: 100%;
height: 122px;
top: 0%;
left: 0%;
padding: 10px;
.artwork {height:100px; overflow:hidden; margin-left:auto; margin-right:auto;}
.containerLarge {
height: 427px;
}
.name {left:120px; position:absolute; top:7px}
.player {
box-sizing: border-box;
position:absolute;
width:91%;
bottom: 10px;
left:120px;
border-radius: 3px;
padding: 5px;
}
.controls {
border-radius:1em;
background-color:#0485bf;
display: block;
width: 34px;
height: 34px;
background-image: url(../player/src/images/sprite.png);
background-repeat: no-repeat;
float: left;
margin-right: 5px;
}
.controls:hover {background-color:#005b85}
#play {
background-position: 6px 5px;
}
#pause {
background-position: -32px 5px;
}
input[type="range"] {
width: 250px;
margin-top: -5px;
}
#close {
float: right;
background-position: -146px 5px;
display: none;
}
.volume {
position: absolute;
height: 100px;
width: 34px;
border: 1px solid black;
background-color: #242323;
top: -97px;
display: none;
}
input{
display:none\9!important;
}
input[type="range"] {
border: 1px solid #C4C4C4;
position: absolute;
top: 18px;
display: block;
width: 95%;
height: 15px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
background-color: #DBDBDB;
left: 50px;
}
input::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border:1px solid #C4C4C4;
-webkit-border-radius: 10px;
border-radius: 10px;
background: #0485bf;
}
input::-webkit-slider-thumb: hover {opacity : 0.3;filter: alpha(opacity=30)}
.logo {float:right; }
.embed {width:100%; background-color:black }
The main elements in question are .container, .controls, .player and the input type range.
Hard to see what's going on from the markup. Which element is the progress bar? If something is positioned absolutely and set to 100% width, it will fill fill the width of the screen, rather than its parent element (unless it's parent is set to position:relative).