I'm trying to add navigation (Left - Right) arrows on the center of image.
But somehow I don't have images of fixed sizes. They can be of any height and width.
Here is what I tried http://jsfiddle.net/vh1fp0k0/
#case-example-cover {
width: 100%;
height: 100%;
}
#nav-container {
position: relative;
border: 1px solid red;
}
#nav-container div {
position: absolute;
top: -webkit-calc(50% - 19px);
top: -moz-calc(50% - 19px);
top: -ms-calc(50% - 19px);
top: calc(50% - 19px);
width: 38px;
height: 38px;
background-image: url("http://s7.directupload.net/images/140625/lhmdzrfd.png");
border: 1px solid blue;
}
#case-left {
left: 0;
}
#case-right {
right: 0;
}
<div id="case-example-cover">
<div id="nav-container">
<div id="case-left"></div>
<div id="case-right"></div>
<img src="http://placehold.it/200x299" />
</div>
</div>
<br>
<div id="case-example-cover">
<div id="nav-container">
<div id="case-left"></div>
<div id="case-right"></div>
<img src="http://placehold.it/400x400" />
</div>
</div>
Desired result
How to do achieve this ?
If you make the #case-example-cover div inline-block it shrink wraps to the image size.
JSfiddle Demo
#case-example-cover {
display: inline-block;
}
#nav-container {
position: relative;
border: 1px solid red;
}
#nav-container img {
display: block;
}
#nav-container div {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 38px;
height: 38px;
background-image: url("http://s7.directupload.net/images/140625/lhmdzrfd.png");
border: 1px solid blue;
}
#case-left {
left: 0;
}
#case-right {
right: 0;
}
<div id="case-example-cover">
<div id="nav-container">
<div id="case-left"></div>
<div id="case-right"></div>
<img src="http://placehold.it/200x299" />
</div>
</div>
<div id="case-example-cover">
<div id="nav-container">
<div id="case-left"></div>
<div id="case-right"></div>
<img src="http://placehold.it/400x400" />
</div>
</div>
Related
How can I center this image that I have in this div in a way that it won't move the 'line' div? I want the line to be touching the top of the square too.
.black {
background: black;
}
.square {
width: 200px;
height: 500px;
margin: 37px auto;
border-radius: 2px;
}
.image {
height: 60px;
width: 60px;
}
.line {
width: 4px;
height: 500px;
background-color: red;
}
<div class="container">
<div class="square black">
<img class="image" src="https://c.neh.tw/thumb/f/720/5659673474629632.jpg">
<div class="wrapper">
<div class="line"></div>
<div class="rectangle"></div>
</div>
</div>
Here is one way to prevent it from disrupting the flow layout of your container:
you can make the container a position of relative, and the image a position of absolute, positioned off the top and left by 50%, then transform it so that the center of the image is in the center position.
You could also just make the image a background-image of the div instead of using an image element, which may be easier to manipulate.
.black {
background: black;
}
.square {
position: relative;
width: 200px;
height: 500px;
margin: 37px auto;
border-radius: 2px;
}
.image {
height: 60px;
width: 60px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.line {
width: 4px;
height: 500px;
background-color: red;
}
<div class="container">
<div class="square black">
<img class="image" src="https://c.neh.tw/thumb/f/720/5659673474629632.jpg">
<div class="wrapper">
<div class="line"></div>
<div class="rectangle"></div>
</div>
</div>
</div>
I'm not sure I understand your exact desired end goal. But, if I understand correctly, you could create a flex parent to justify the image, and then position the line absolutely within that. See -
.black {
background: black;
}
.square {
width: 200px;
height: 500px;
margin: 37px auto;
border-radius: 2px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.image {
height: 60px;
width: 60px;
}
.line {
width: 4px;
background-color: red;
position: absolute;
left: 0;
top: 0;
bottom: 0
}
<div class="square black">
<div class="line"></div>
<img class="image" src="https://c.neh.tw/thumb/f/720/5659673474629632.jpg">
</div>
You can just use these css for .square and .image
.square {
width: 200px;
height: 500px;
margin: 37px auto;
border-radius: 2px;
position: relative;
}
.image {
height: 60px;
width: 60px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
You can easily center a image by using CSS position absolute. By making the position of square black class "absolute" and apply to properties "top: 45%;" and "left: 47%" . By applying this your problem will be definitely solve.
.black {
background: black;
}
.square {
display: flex;
align-item: center;
justify-content: center;
width: 200px;
height: 500px;
border-radius: 2px;
}
.image {
height: 60px;
width: 60px;
}
<div class="container">
<div class="square black">
<img class="image" src="https://c.neh.tw/thumb/f/720/5659673474629632.jpg">
</div>
</div>
.black {
background: black;
}
.square {
position: absolute;
top: 45%;
left: 47%;
width: 200px;
height: 500px;
margin: 37px auto;
border-radius: 2px;
}
.image {
height: 60px;
width: 60px;
position: absolute;
top:50%;
left:50%;
}
.line {
width: 4px;
height: 500px;
background-color: red;
}
<div class="container">
<div class="square black">
<img class="image" src="https://c.neh.tw/thumb/f/720/5659673474629632.jpg">
<div class="wrapper">
<div class="line"></div>
<div class="rectangle"></div>
</div>
</div>
.black {
background: black;
}
.square {
width: 200px;
height: 500px;
margin: 37px auto;
border-radius: 2px;
}
.image {
height: 60px;
width: 60px;
}
.line {
width: 4px;
height: 500px;
background-color: red;
}
<div class="container">
<div class="square black">
<img class="image" src="https://c.neh.tw/thumb/f/720/5659673474629632.jpg">
<div class="wrapper">
<div class="line"></div>
<div class="rectangle"></div>
</div>
</div>
I am trying to do a vertical bar chart like this
But I am getting like this
At bottom of my vertical bar chart, both lines are attached together, I am trying to fix that.
I am trying to set that 0 line down but it's attached
And for example, bar height should get increase 25% if we give height: 25%; on inline CSS.
.barchart-Wrapper {
display: table;
position: relative;
margin: 20px 0;
height: 252px;
}
.barChart-Container {
display: table-cell;
width: 100%;
height: 100%;
padding-left: 15px;
}
.barchart {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
border-bottom: 3px solid tomato;
}
.barchart-Col {
position: relative;
vertical-align: bottom;
display: table-cell;
height: 100%;
}
.barchart-Col + .barchart-Col {
border-left: 4px solid transparent;
}
.barchart-Bar {
position: relative;
height: 0;
transition: height 0.5s 2s;
width: 66px;
margin: auto;
}
.barchart-Bar:after {
content: attr(attr-height);
color: white;
position: absolute;
text-align: center;
width: 100%;
}
.barchart-BarFooter {
position: absolute;
text-align: center;
height: 10%;
width: 100%;
}
.barchart-BarFooter h3 {
color: darkred;
}
.barchart-TimeCol {
position: absolute;
top: 0;
height: 100%;
width: 100%;
}
.barchart-Time {
height: 25%;
vertical-align: middle;
position: relative;
}
.barchart-Time:after {
border-bottom: 3px solid black;
content: "";
position: absolute;
width: 100%;
left: 0;
top: 0em;
}
.barchart-TimeText {
position: absolute;
top: -8px;
z-index: 1;
background: white;
padding-right: 5px;
color: #4d4d4d;
font-size: 15px;
font-family: 'Avenir Medium';
}
.html-bar {
background-color: deepskyblue;
}
.css-bar {
background-color: greenyellow;
}
.js-bar {
background-color: peachpuff;
}
.python-bar {
background-color: darkolivegreen;
}
.java-bar {
background-color: cornflowerblue;
}
<div class="barchart-Wrapper">
<div class="barchart-TimeCol">
<div class="barchart-Time">
<span class="barchart-TimeText">125</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">100</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">75</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">50</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">25</span>
</div>
</div>
<div class="barChart-Container">
<div class="barchart">
<div class="barchart-Col">
<div class="barchart-Bar html-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>HTML</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar css-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>CSS</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar js-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>JS</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar python-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>PYTHON</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar java-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>JAVA</h3>
</div>
</div>
</div>
</div>
</div>
I guess doing a small change will help. Updated barchart-Time height to be 20%. Given 100% as 125. I believe this makes sense
.barchart-Wrapper {
display: table;
position: relative;
margin: 20px 0;
height: 252px;
}
.barChart-Container {
display: table-cell;
width: 100%;
height: 100%;
padding-left: 15px;
}
.barchart {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
border-bottom: 3px solid tomato;
}
.barchart-Col {
position: relative;
vertical-align: bottom;
display: table-cell;
height: 100%;
}
.barchart-Col+.barchart-Col {
border-left: 4px solid transparent;
}
.barchart-Bar {
position: relative;
height: 0;
transition: height 0.5s 2s;
width: 66px;
margin: auto;
}
.barchart-Bar:after {
content: attr(attr-height);
color: white;
position: absolute;
text-align: center;
width: 100%;
}
.barchart-BarFooter {
position: absolute;
text-align: center;
height: 10%;
width: 100%;
}
.barchart-BarFooter h3 {
color: darkred;
}
.barchart-TimeCol {
position: absolute;
top: 0;
height: 100%;
width: 100%;
}
.barchart-Time {
height: 20%;
vertical-align: middle;
position: relative;
}
.barchart-Time:after {
border-bottom: 3px solid black;
content: "";
position: absolute;
width: 100%;
left: 0;
top: 0em;
}
.barchart-TimeText {
position: absolute;
top: -8px;
z-index: 1;
background: white;
padding-right: 5px;
color: #4d4d4d;
font-size: 15px;
font-family: 'Avenir Medium';
}
.html-bar {
background-color: deepskyblue;
}
.css-bar {
background-color: greenyellow;
}
.js-bar {
background-color: peachpuff;
}
.python-bar {
background-color: darkolivegreen;
}
.java-bar {
background-color: cornflowerblue;
}
<div class="barchart-Wrapper">
<div class="barchart-TimeCol">
<div class="barchart-Time">
<span class="barchart-TimeText">125</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">100</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">75</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">50</span>
</div>
<div class="barchart-Time">
<span class="barchart-TimeText">25</span>
</div>
</div>
<div class="barChart-Container">
<div class="barchart">
<div class="barchart-Col">
<div class="barchart-Bar html-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>HTML</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar css-bar" style="height: 50%;"></div>
<div class="barchart-BarFooter">
<h3>CSS</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar js-bar" style="height: 75%;"></div>
<div class="barchart-BarFooter">
<h3>JS</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar python-bar" style="height: 25%;"></div>
<div class="barchart-BarFooter">
<h3>PYTHON</h3>
</div>
</div>
<div class="barchart-Col">
<div class="barchart-Bar java-bar" style="height: 100%;"></div>
<div class="barchart-BarFooter">
<h3>JAVA</h3>
</div>
</div>
</div>
</div>
</div>
Have you tried padding/ margin on the h3 element?
Try this:
h3 {
margin-top: 10px;
}
If this doesn't work there wil be a run around like this:
h3 {
position: relative;
top: 10px
}
If neither of these solutions work, feel free to command below.
I would like to add a grey lines that will separated red divs, the final result should be:
enter image description here
I have a problem with eliminate the line after last red div, my code is:
<html>
<head>
<style>
.authorsContainer{
padding-right: 15px;
padding-left: 15px;
}
.authorIconVisibility, .authorName{
float:left;
}
.booksContainer{
display: flex;
clear: both;
}
.bookContainer{
float: left;
flex: 1;
}
.bookInfo{
position: relative;
background: green;
}
.bookInfo:after{
position: absolute;
content: "";
background: #ccc;
height: 2px;
left: 25%;
right: 25%;
margin-top: 5px;
}
.bookName, .bookYear{
text-align: center;
}
.bookDescription{
position: relative;
background: red;
min-height: 100px;
margin: 10px;
}
.bookDescription:after{
position: absolute;
content: "";
background: #ccc;
width: 2px;
top: 25%;
bottom: 25%;
right: -10px;
}
</style>
</head>
<body>
<div class="authorsContainer">
<div class="authorContainer">
<div class="authorInfo">
<div class="authorIconVisibility">icon</div>
<div class="authorName">name</div>
</div>
<div class="booksContainer">
<div class="bookContainer">
<div class="bookInfo">
<div class="bookName">n1</div>
<div class="bookYear">y1</div>
</div>
<div class="bookDescription">
</div>
</div>
<div class="bookContainer">
<div class="bookInfo">
<div class="bookName">n2</div>
<div class="bookYear">y2</div>
</div>
<div class="bookDescription">
</div>
</div>
<div class="bookContainer">
<div class="bookInfo">
<div class="bookName">n3</div>
<div class="bookYear">y3</div>
</div>
<div class="bookDescription">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
I tried to change the last css selector to
.bookContainer .bookDescription:not(:last-child):after{
position: absolute;
content: "";
background: #111;
width: 2px;
top: 25%;
bottom: 25%;
right: -10px;
}
but it does not work (there is no lines at all).
What should I change?
i have a div that i want to place below another div.But i think its getting overlapped and is not visible. I'm trying to get a div below the div that split into 2.
<body>
<div class="split left">
<div class="centered">
<img src="assets/img/tms1.png" alt="Avatar woman" />
<h2>our solution</h2>
</div>
</div>
<div class="split right">
<div class="centered">
<img src="assets/img/logo.jpg" alt="Avatar man" />
<h2>our cause</h2>
</div>
</div>
<div class="page2"><img src="assets/img/logo.png" /></div>
the <div class="page2"><img src="assets/img/logo.png" /></div> is not visible.
css:
body {
font-family: sans-serif;
font-size: 30px;
color: white;
height: 100%;
}
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: #111;
}
.right {
right: 0;
background-color: white;
color: black;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.centered img {
width: 250px;
border-radius: 50%;
}
css for the div that is not getting displayed.
.page2 {
position: relative;
margin-top: 100%;
top: 100%;
width: 100%;
background-color: #111;
}
https://jsfiddle.net/uxfynrmj/
There are a few issues. Most importantly, you need to remove the position: fixed if you want another element statically positioned below your .split divs.
Most notably I removed the fixed position and absolute positioned child and added a wrapping div width display: flex.
Code snippet below:
html {
scroll-behavior: smooth;
/*height: 100%;*/
}
body {
font-family: sans-serif;
font-size: 30px;
color: white;
height: 100%;
}
.splits {
display: flex;
}
.split {
flex: 1 1 50%;
background: black;
}
.right {
right: 0;
background-color: white;
color: black;
}
.centered {
position: relative;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
.centered img {
width: 100px;
height: 100px;
border-radius: 50%;
}
.page2 {
width: 100%;
background-color: pink;
}
.page2 img {
width: 100%;
background-color: pink;
}
<html>
<head>
<title>THS</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="splits">
<div class="split">
<div class="centered">
<img src="http://lorempixel.com/400/200" alt="Avatar woman" />
<h2>our solution</h2>
</div>
</div>
<div class="split right">
<div class="centered">
<img src="http://lorempixel.com/400/400" alt="Avatar man" />
<h2>our cause</h2>
</div>
</div>
</div>
<div class="page2"><img src="http://lorempixel.com/400/400" /></div>
</body>
</html>
I have written the following code to auto fit image in DIV. It is perfectly working in JSFIDDLE but not working in my blog http://roadroute.blogspot.in/2015/08/flipkart.html
Please find the code below
.responsive-container1 {
position: relative;
width: 250px;
height: 415px;
border: 1px solid red;
margin-right: 10px;
margin-top:10px;
float: left;
}
.dummy {
padding-top: 100%; /* forces 1:1 aspect ratio */
}
.img-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align:center; /* Align center inline elements */
font: 0/0 a;
}
.img-container:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.img-container img {
max-width: 100%;
max-height: 100%;
margin: auto;
vertical-align: middle;
display: inline-block;
}
<div class="responsive-container1">
<div class="dummy"></div>
<div class="img-container">
<img src="https://googledrive.com/host/0BxPZgr7ebTBdTkowMFVRTDJTS00/01.jpg" alt="" />
</div>
</div>
<div class="responsive-container1">
<div class="dummy"></div>
<div class="img-container">
<img src="https://googledrive.com/host/0BxPZgr7ebTBdTkowMFVRTDJTS00/02.png" alt="" />
</div>
</div>
<div class="responsive-container1">
<div class="dummy"></div>
<div class="img-container">
<img src="https://googledrive.com/host/0BxPZgr7ebTBdTkowMFVRTDJTS00/03.jpg" alt="" />
</div>
</div>
Please help.
just add
width:100%; height:100%;
in your image container class.
.responsive-container1 {
position: relative;
width: 250px;
height: 415px;
border: 1px solid red;
margin-right: 10px;
margin-top:10px;
float: left;
}
.dummy {
padding-top: 100%;
max-width:100%;
max-height:100%; /* forces 1:1 aspect ratio */
}
.img-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align:center; /* Align center inline elements */
font: 0/0 a;
max-width:100%;
max-height:100%;
}
.img-container:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
max-width:100%;
max-height:100%;
}
.img-container img {
width: 100%;
height: 100%;
margin: auto;
vertical-align: middle;
display: inline-block;
}
<div class="responsive-container1">
<div class="dummy"></div>
<div class="img-container">
<img src="https://googledrive.com/host/0BxPZgr7ebTBdTkowMFVRTDJTS00/01.jpg" alt=""/>
</div>
</div>
<div class="responsive-container1">
<div class="dummy"></div>
<div class="img-container">
<img src="https://googledrive.com/host/0BxPZgr7ebTBdTkowMFVRTDJTS00/02.png" alt="" />
</div>
</div>
<div class="responsive-container1">
<div class="dummy"></div>
<div class="img-container">
<img src="https://googledrive.com/host/0BxPZgr7ebTBdTkowMFVRTDJTS00/03.jpg" alt="" />
</div>
</div>
You should remove following css:
.dummy {
padding-top: 100%;
}
.img-container {
bottom: 0;
font: 0px/0 a;
left: 0;
position: absolute;
right: 0;
text-align: center;
top: 0;
}
And .post-body img have have padding: 8px; will put/display your image outside div. Either remove that Or make image max-width: 90%;.
It will wok for you.
Edit:
Give: text-align:center to .responsive-container1.
.responsive-container1 {
border: 1px solid red;
float: left;
height: 415px;
margin-right: 10px;
margin-top: 10px;
position: relative;
text-align: center;
width: 250px;
}
And max width and height 90% and give position and top value And also give transform.
.post-body img {
background: #222222 none repeat scroll 0 0;
border: 1px solid transparent;
border-radius: 0;
box-shadow: 0 0 0 rgba(0, 0, 0, 0.2);
max-height: 90%;
max-width: 90%;
padding: 8px;
position: relative;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
}
It will do the trick.