I am building functionality to select text with "handles". These handles need to be positioned on either the left or right side of the inline span. An image:
As you can see I've come a long way in styling this in CSS. The one problem I have is that I can't seem to position the right handle on the text itself.
The following code is being used:
.text {
display: inline;
background-color: #4d82f2;
color: white;
padding: 1px;
border-radius: 2px;
margin: 0;
position: relative;
}
.text>.handle-left {
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
left: -30px;
top: -25px;
font-size: 10px;
border-radius: 15px;
border-bottom-right-radius: 4px;
}
.text>.handle-right {
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
right: -30px;
top: -25px;
font-size: 10px;
border-radius: 15px;
border-bottom-left-radius: 4px;
}
<div>All the other text
<div class="text">
<span>blue text</span>
<div class="handle-left">plus icon</div>
<div class="handle-right">plus icon</div>
</div>
Maybe some more text, who knows?
</div>
This JSFiddle displays my problem well:
JSFiddle
I would probably transform the element to inline and make one at the beginning and the other one at the end then I will use pseudo element. Doing this I will be sure they will be in the right place:
.all-text {
width: 400px;
margin: 40px;
}
.text {
display: inline;
background-color: #4d82f2;
color: white;
padding: 1px;
border-radius: 2px;
margin: 0;
position: relative;
}
.text>.handle-left,
.text>.handle-right {
position: relative;
}
.text>.handle-left:before {
content: "+";
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
left: -30px;
top: -25px;
display: inline-flex;
justify-content: center;
font-size: 24px;
border-radius: 15px;
border-bottom-right-radius: 4px;
}
.text>.handle-right:before {
content: "+";
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
right: -30px;
bottom: 18px;
display: inline-flex;
justify-content: center;
font-size: 24px;
border-radius: 15px;
border-bottom-left-radius: 4px;
}
<div class="all-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum corporis enim doloremque perspiciatis, doloribus nemo commodi, consectetur
<div class="text">
<span class="handle-left"></span>
<span> quaerat verit</span>
<span class="handle-right"></span>
</div>
autem laboriosam est alias aspernatur deserunt quae, fugit eos? Lorem ipsum dolor sit amet,
<div class="text">
<span class="handle-left"></span>
<span> quaerat verit consectetur adipisicing elit. Laborum corporis enim </span>
<span class="handle-right"></span>
</div>
consectetur adipisicing elit. Laborum corporis enim doloremque perspiciatis, doloribus nemo commodi, consectetur
<div class="text">
<span class="handle-left"></span>
<span> quaerat veritatis at unde</span>
<span class="handle-right"></span>
</div>
autem laboriosam est alias aspernatur deserunt quae, fugit eos?</div>
Related
while I am making a responsive site with bootstrap, I give min-height 100vh for both the home and about section. it looks nice for the large screen, but for the small screen, there is more space between the home section and the about section. how can I control that space for the small screen? I tried media queries to control the space between the home and about section for the small screen. I can't fix this. so tell me how to control that.
.row {
display: flex !important;
justify-content: flex-end !important;
align-items: center;
min-height: 100vh;
}
.first__para {
font-size: 1.5rem;
}
.landing__btn {
text-decoration: none;
color: #0275d8;
font-size: 1.5rem;
}
.landing__btn::after {
content: "";
height: 2px;
width: 0px;
opacity: ;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
}
.landing__btn:hover::after {
content: "";
height: 2px;
width: 105px;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
transform-origin: 0%;
z-index: 10;
}
.about__head {
color: #0275d8
}
.about__para {
font-size: 1.5rem;
}
.about__btn {
text-decoration: none;
color: #0275d8;
font-size: 1.5rem;
}
.about__btn::after {
content: "";
height: 2px;
width: 0px;
opacity: ;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
}
.about__btn:hover::after {
content: "";
height: 2px;
width: 130px;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
transform-origin: 0%;
z-index: 10;
}
<!--landing page-->
<div class="container">
<div class="row">
<div class="col-12 col-md-12 col-lg-12">
<h1 class="text-primary">the vollmonds</h1>
<p class="first__para">Businesses get blinded by the allure of a large subscription list, <br>but unengaged subscribers aren't just not interested in what you're sending, they're actually harming your deliverability</p>
for more<span></span>
</div>
</div>
</div>
<!--landing-page-->
<!--about-->
<div class="container">
<div class="row">
<div class="col-12 col-lg-6">
<img src="https://cdni.iconscout.com/illustration/premium/thumb/startup-business-1460503-1234533.png" alt="marketting">
</div>
<div class="col-12 col-lg-6">
<h1 class="about__head">about</h1>
<p class="about__para">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consequuntur, nisi dicta voluptatem cumque eius, <br>facere veritatis beatae rerum maxime ea accusamus, cum dolore ipsam quasi fugiat sit ullam error quas!</p>
<p class="about__para">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consequuntur, nisi dicta voluptatem cumque eius, <br>facere veritatis beatae rerum maxime ea accusamus, cum dolore ipsam quasi fugiat sit ullam error quas!</p>
learn more
</div>
</div>
</div>
<!--about-->
I recommend adding some CSS that will increase margin on top of additional .container elements (or any class you name them), and then a media query to remove the margin if you desire. Code below for reference
.row {
display: flex !important;
justify-content: flex-end !important;
align-items: center;
min-height: 100vh;
}
.first__para {
font-size: 1.5rem;
}
.landing__btn {
text-decoration: none;
color: #0275d8;
font-size: 1.5rem;
}
.landing__btn::after {
content: "";
height: 2px;
width: 0px;
opacity: ;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
}
.landing__btn:hover::after {
content: "";
height: 2px;
width: 105px;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
transform-origin: 0%;
z-index: 10;
}
.about__head {
color: #0275d8
}
.about__para {
font-size: 1.5rem;
}
.about__btn {
text-decoration: none;
color: #0275d8;
font-size: 1.5rem;
}
.about__btn::after {
content: "";
height: 2px;
width: 0px;
opacity: ;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
}
.about__btn:hover::after {
content: "";
height: 2px;
width: 130px;
background: #0275d8;
display: block;
position: absolute;
transition: .3s;
transform-origin: 0%;
z-index: 10;
}
/* New CSS */
.container + .container {
margin-top: 50px;
}
#media screen and (min-width: 768px) {
.container + .container {
margin-top: 0;
}
}
<!--landing page-->
<div class="container">
<div class="row">
<div class="col-12 col-md-12 col-lg-12">
<h1 class="text-primary">the vollmonds</h1>
<p class="first__para">Businesses get blinded by the allure of a large subscription list, <br>but unengaged subscribers aren't just not interested in what you're sending, they're actually harming your deliverability</p>
for more<span></span>
</div>
</div>
</div>
<!--landing-page-->
<!--about-->
<div class="container">
<div class="row">
<div class="col-12 col-lg-6">
<img src="https://cdni.iconscout.com/illustration/premium/thumb/startup-business-1460503-1234533.png" alt="marketting">
</div>
<div class="col-12 col-lg-6">
<h1 class="about__head">about</h1>
<p class="about__para">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consequuntur, nisi dicta voluptatem cumque eius, <br>facere veritatis beatae rerum maxime ea accusamus, cum dolore ipsam quasi fugiat sit ullam error quas!</p>
<p class="about__para">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consequuntur, nisi dicta voluptatem cumque eius, <br>facere veritatis beatae rerum maxime ea accusamus, cum dolore ipsam quasi fugiat sit ullam error quas!</p>
learn more
</div>
</div>
</div>
<!--about-->
I'm trying to show message within a div with icon on the left.
Expected result is icon should always adjacent to text and together they need to be aligned at bottom-center of div.
I'm using :after pseudo element. Keeping position: absolute of icon didn't help since that needs manually adjusting the icon position relative to text.
Here is the CSS.
.parent{
font-weight: 500;
height: 65px;
text-align: center;
padding: 15px 0 10px;
margin: auto;
display: block;
width: 80%;
font-size: 12px;
overflow: hidden;
position: relative;
}
.parent > div {
float: none;
/* display: table-cell; */
vertical-align: middle;
position: absolute;
bottom: 0;
width: 100%;
}
.msg:after {
content: '';
background: url(data:image/...);
height: 16px;
width: 16px;
display: block;
position: absolute;
top: 0;
padding-right: 5px;
left: 108px;
}
And markup:
<div class="parent">
<div class="msg">text goes here</div>
</div>
Flexbox can do that:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
::before,
::after {
box-sizing: inherit;
}
.parent {
font-weight: 500;
margin: auto;
padding: 1em;
width: 80%;
font-size: 12px;
overflow: hidden;
position: relative;
border: 1px solid red;
}
.msg {
display: flex;
}
.msg p {
padding-left: 1em;
}
.msg:before {
content: "";
height: 16px;
flex: 0 0 16px;
background: red;
border-radius: 100%;
}
<div class="parent">
<div class="msg">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae numquam unde, eum sequi expedita fugiat ipsa exercitationem nesciunt libero repellendus aperiam excepturi, dolorem repudiandae eveniet alias perspiciatis, vero veniam tempora natus magnam
itaque quos. Nemo sit nisi, veniam mollitia fugit eaque reiciendis ex doloribus rem et suscipit debitis commodi sapiente.</p>
</div>
</div>
I need to create the following shape on the image. Where is the photo there will variable content as a slider. What I tried so far is create it with border-width, but the problem is that I'm not able to put the small triangle under photo because of the bigger triangle.
What I've done you can find here on live demo. Maybe I have to use other approaches? Does someone how to solve it?
.header {
float: left;
width: 100%;
background: red;
padding-top: 50px;
padding-bottom: 200px; }
.content {
float: left;
width: 100%;
background: blue;
padding: 50px 0; }
.shape {
position: relative;
float: left;
width: 100%; }
.shape--1:before {
border-top-color: yellow;
border-right-color: transparent;
border-left-color: transparent;
border-bottom-color: transparent;
border-style: solid;
border-width: 160px 330px 0 0;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 30; }
.shape--2:before {
background: transparent;
border-bottom-color: transparent;
border-left-color: blue;
border-right-color: transparent;
border-style: solid;
border-top-color: transparent;
border-width: 130px 0 0 100vw;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 20; }
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod? - There will be slider with different background, same color should be also in the shape.
</div>
<div class="shape">
<div class="shape--1"></div>
<div class="shape--2"></div>
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
What I did is first create the element that holds the photo, then I created a rectangular shape in the body background color, rotated it and made it overflown. Then inside of it I placed another rectangular block that I rotated in the opposite way of the original triangle:
HTML:
<div class="photo"></div>
<div class="triangle"></div>
CSS:
body {
background: #fff;
overflow:hidden;
padding: 0;
margin: 0;
}
.photo {
width: 100%;
height: 200px;
background: red;
}
.triangle {
position: absolute;
background: #fff;
left: -100px;
right: -100px;
height: 300px;
transform: rotate(5deg);
transform-origin: 100% 100%;
overflow: hidden;
}
.triangle:after {
content: "";
display: block;
width: 400px;
height: 200px;
position: absolute;
background: orange;
left: 0;
top: -180px;
transform: rotate(-20deg)
}
And here is a working fiddle:
https://jsfiddle.net/62o7wqom/2/
Edit: Added overflow:hidden to the body tag to avoid having a horizontal scrollbar because of the absolutely positioned element...overflowing the body.
The easiest way of doing it would be setting a background-color on a containing div and use clip-path on the actual image. That would give you the effect you're looking for.
If you don't want the triangle to move with the slider you can either create another wrapper div or just create a pseudo after-element and position it on top of the image.
you may use some Pythagore stuff to calculate more precisely angles and sizes, but the idea is here.
.shape {
width: 100%;
height: 5em;
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0, 25% 0, 0 100%);
}
.header {
text-align: center;
font-variant: small-caps;
font-size: 2em;
}
<div class=header>
<div class=shape style="background-image: url('http://backgrounds.mysitemyway.com/wp-content/uploads/2009/03/bamboo-001126-asparagus-fern-green.jpg')"></div>
awesome header
</div>
<div class=content>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
One posibility using an inner element to contain the image.
This element is rotated, and inside a pseudo there is the image, counter-rotated.
.test {
font-size: 30px;
width: 400px;
height: 200px;
border: solid blue 1px;
background-size: 200px 200px;
background-repeat: no-repeat;
position: relative;
}
.inner {
position: absolute;
width: 140%;
height: 140%;
bottom: 0px;
right: 0px;
z-index: -1;
transform: rotate(26.4deg);
transform-origin: right bottom;
overflow: hidden;
}
.inner:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-image: url(http://lorempixel.com/800/400);
background-size: cover;
transform: rotate(-26.4deg);
transform-origin: right bottom;
}
.triangle {
position: absolute;
width: 200px;
height: 200px;
top: 0px;
left: 0px;
background-image: linear-gradient(to right bottom, red 50%, transparent 50%);
z-index: -2;
}
<div class="test">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..
<div class="inner"></div>
<div class="triangle"></div>
</div>
Here I made a jsfiddle take a look just with your answer I made some css changes. Hope it helps.
.shape-1{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 160px solid transparent;
border-left: 0vw solid green;
border-right: 97vw solid green;
position:relative;
top: -130px;
}
.shape-2{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 130px solid transparent;
border-left: 42vw solid yellow;
border-right: 0vw solid yellow;
position:relative;
top:0px;
}
.header{
position: absolute;
z-index: 1;
}
<div class="shape">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam
accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod?
</div>
<div class="shape-2"></div>
<div class="shape-1"></div>
</div>
I noticed that you have already accepted an answer, but I figured I would still post some code that could help. This would require some fine tuning given what else you may have going on in your project, but it could get the job done.
.LeftT {
position: absolute;
top: 0rem;
left: 0rem;
border-left: 30rem solid #02A698;
border-right: 6rem solid transparent;
border-bottom: 8rem solid transparent;
border-top: 0rem solid transparent;
}
.RightT {
position: absolute;
top: 0rem;
left: -5rem;
border-top: 0rem solid #004F49;
border-left: 0rem solid transparent;
border-bottom: 8rem solid transparent;
border-right: 45rem solid #004F49;
}
p{
position: absolute;
top: 0rem;
left: 15rem;
z-index: 1;
}
<div class="LeftT"></div>
<div class="RightT"></div>
<p style="color:white;text-align:right;padding-right:1rem;font-size:1.1rem;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in turpis velit.
</p>
I need to create a layout like the below image.I tried like the below code,but it's difficult to add an text to the right side of fa-circle-thin class.How can I achieve it?
.test {
height: 100px;
margin-top: 21px;
margin-left: 9px;
position: relative;
padding-left: 20px;
border-left: 2px solid #b5b3b5;
}
.modal-body {
margin: 20px;
}
<div class="modal-body">
<i class="fa fa-circle-thin" style="font-size:24px;color:#b5b3b5; position: absolute;"></i>
<div class="test"></div>
<i class="fa fa-circle-thin" style="font-size:24px;color:#b5b3b5; position: absolute;"></i>
<div class="test"></div>
<i class="fa fa-circle-thin" style="font-size:24px;color:#b5b3b5; position: absolute;"></i>
</div>
This is a great use case for css pseudo-selectors. Take a look at this (updated) fiddle or snippet below and let me know if you have an specific questions.
.modal-body{
margin: 20px;
}
.circle-wrapper {
position: relative;
}
.circle-wrapper::after {
height: 50px;
border-left: 2px solid #b5b3b5;
content: '';
display: block;
position: absolute;
left: 10px;
top: 21px;
}
.circle-wrapper::before {
height: 46px;
border-left: 2px solid #b5b3b5;
content: '';
display: block;
position: absolute;
left: 10px;
top: -44px;
}
.circle-wrapper:last-child::after {
display: none;
}
.circle-wrapper:first-child::before {
display: none;
}
.modal-body .fa {
font-size: 24px;
color: #b5b3b5;
display: inline;
vertical-align: middle;
}
.modal-body .text {
vertical-align: middle;
margin-left: 10px;
}
.inner-circle .fa {
font-size: 16px;
}
.inner-circle {
font-size: 12px;
margin-left: 50px;
position: relative;
height: 35px;
}
.inner-circle::before {
height: 22px;
border-left: 1px solid #b5b3b5;
content: '';
display: block;
position: absolute;
left: 6px;
top: 2px;
}
.inner-circle:last-child::after {
height: 18px;
border-left: 1px solid #b5b3b5;
content: '';
display: block;
position: absolute;
left: 6px;
top: 36px;
}
.inner-circle:last-child {
height: 50px;
margin-bottom: 5px;
}
.inner-contents {
position: relative;
top: 22px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/fontawesome/4.6.3/css/font-awesome.min.css">
<div class="modal-body">
<div class="circle-wrapper">
<div class="outer-circle">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code</span>
</div>
<div class="inner-circle">
<div class="inner-contents">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code inner</span>
</div>
</div>
<div class="inner-circle">
<div class="inner-contents">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code inner 2</span>
</div>
</div>
</div>
<div class="circle-wrapper">
<div class="outer-circle">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code 2</span>
</div>
<div class="inner-circle">
<div class="inner-contents">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code inner</span>
</div>
</div>
<div class="inner-circle">
<div class="inner-contents">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code inner 2</span>
</div>
</div>
</div>
<div class="circle-wrapper">
<div class="outer-circle">
<i class="fa fa-circle-thin"></i>
<span class="text">Test code 3</span>
</div>
</div>
</div>
Can you edit this code.........
/* -------------------------------------
* For horizontal version, set the
* $vertical variable to false
* ------------------------------------- */
/* -------------------------------------
* General Style
* ------------------------------------- */
#import url(http://fonts.googleapis.com/css?family=Noto+Sans);
body {
max-width: 1200px;
margin: 0 auto;
padding: 0 5%;
font-size: 100%;
font-family: "Noto Sans", sans-serif;
color: #eee9dc;
background: #48b379;
}
h2 {
margin: 3em 0 0 0;
font-size: 1.5em;
letter-spacing: 2px;
text-transform: uppercase;
}
/* -------------------------------------
* timeline
* ------------------------------------- */
#timeline {
list-style: none;
margin: 50px 0 30px 120px;
padding-left: 30px;
border-left: 8px solid #eee9dc;
}
#timeline li {
margin: 40px 0;
position: relative;
}
#timeline p {
margin: 0 0 15px;
}
.date {
margin-top: -10px;
top: 50%;
left: -158px;
font-size: 0.95em;
line-height: 20px;
position: absolute;
}
.circle {
margin-top: -10px;
top: 50%;
left: -44px;
width: 10px;
height: 10px;
background: #48b379;
border: 5px solid #eee9dc;
border-radius: 50%;
display: block;
position: absolute;
}
.content {
max-height: 20px;
padding: 50px 20px 0;
border-color: transparent;
border-width: 2px;
border-style: solid;
border-radius: 0.5em;
position: relative;
}
.content:before,
.content:after {
content: "";
width: 0;
height: 0;
border: solid transparent;
position: absolute;
pointer-events: none;
right: 100%;
}
.content:before {
border-right-color: inherit;
border-width: 20px;
top: 50%;
margin-top: -20px;
}
.content:after {
border-right-color: #48b379;
border-width: 17px;
top: 50%;
margin-top: -17px;
}
.content p {
max-height: 0;
color: transparent;
text-align: justify;
word-break: break-word;
hyphens: auto;
overflow: hidden;
}
label {
font-size: 1.3em;
position: absolute;
z-index: 100;
cursor: pointer;
top: 20px;
transition: transform 0.2s linear;
}
.radio {
display: none;
}
.radio:checked+.relative label {
cursor: auto;
transform: translateX(42px);
}
.radio:checked+.relative .circle {
background: #f98262;
}
.radio:checked~.content {
max-height: 180px;
border-color: #eee9dc;
margin-right: 20px;
transform: translateX(20px);
transition: max-height 0.4s linear, border-color 0.5s linear, transform 0.2s linear;
}
.radio:checked~.content p {
max-height: 200px;
color: #eee9dc;
transition: color 0.3s linear 0.3s;
}
/* -------------------------------------
* mobile phones (vertical version only)
* ------------------------------------- */
#media screen and (max-width: 767px) {
#timeline {
margin-left: 0;
padding-left: 0;
border-left: none;
}
#timeline li {
margin: 50px 0;
}
label {
width: 85%;
font-size: 1.1em;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: block;
transform: translateX(18px);
}
.content {
padding-top: 45px;
border-color: #eee9dc;
}
.content:before,
.content:after {
border: solid transparent;
bottom: 100%;
}
.content:before {
border-bottom-color: inherit;
border-width: 17px;
top: -16px;
left: 50px;
margin-left: -17px;
}
.content:after {
border-bottom-color: #48b379;
border-width: 20px;
top: -20px;
left: 50px;
margin-left: -20px;
}
.content p {
font-size: 0.9em;
line-height: 1.4;
}
.circle,
.date {
display: none;
}
}
<h2>CSS3 Timeline</h2>
<ul id='timeline'>
<li class='work'>
<input class='radio' id='work5' name='works' type='radio' checked>
<div class="relative">
<label for='work5'>Lorem ipsum dolor sit amet</label>
<span class='date'>12 May 2013</span>
<span class='circle'></span>
</div>
<div class='content'>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio ea necessitatibus quo velit natus cupiditate qui alias possimus ab praesentium nostrum quidem obcaecati nesciunt! Molestiae officiis voluptate excepturi rem veritatis eum aliquam qui laborum
non ipsam ullam tempore reprehenderit illum eligendi cumque mollitia temporibus! Natus dicta qui est optio rerum.
</p>
</div>
</li>
<li class='work'>
<input class='radio' id='work4' name='works' type='radio'>
<div class="relative">
<label for='work4'>Lorem ipsum dolor sit amet</label>
<span class='date'>11 May 2013</span>
<span class='circle'></span>
</div>
<div class='content'>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio ea necessitatibus quo velit natus cupiditate qui alias possimus ab praesentium nostrum quidem obcaecati nesciunt! Molestiae officiis voluptate excepturi rem veritatis eum aliquam qui laborum
non ipsam ullam tempore reprehenderit illum eligendi cumque mollitia temporibus! Natus dicta qui est optio rerum.
</p>
</div>
</li>
<li class='work'>
<input class='radio' id='work3' name='works' type='radio'>
<div class="relative">
<label for='work3'>Lorem ipsum dolor sit amet</label>
<span class='date'>10 May 2013</span>
<span class='circle'></span>
</div>
<div class='content'>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio ea necessitatibus quo velit natus cupiditate qui alias possimus ab praesentium nostrum quidem obcaecati nesciunt! Molestiae officiis voluptate excepturi rem veritatis eum aliquam qui laborum
non ipsam ullam tempore reprehenderit illum eligendi cumque mollitia temporibus! Natus dicta qui est optio rerum.
</p>
</div>
</li>
<li class='work'>
<input class='radio' id='work2' name='works' type='radio'>
<div class="relative">
<label for='work2'>Lorem ipsum dolor sit amet</label>
<span class='date'>09 May 2013</span>
<span class='circle'></span>
</div>
<div class='content'>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio ea necessitatibus quo velit natus cupiditate qui alias possimus ab praesentium nostrum quidem obcaecati nesciunt! Molestiae officiis voluptate excepturi rem veritatis eum aliquam qui laborum
non ipsam ullam tempore reprehenderit illum eligendi cumque mollitia temporibus! Natus dicta qui est optio rerum.
</p>
</div>
</li>
<li class='work'>
<input class='radio' id='work1' name='works' type='radio'>
<div class="relative">
<label for='work1'>Lorem ipsum dolor sit amet</label>
<span class='date'>08 May 2013</span>
<span class='circle'></span>
</div>
<div class='content'>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio ea necessitatibus quo velit natus cupiditate qui alias possimus ab praesentium nostrum quidem obcaecati nesciunt! Molestiae officiis voluptate excepturi rem veritatis eum aliquam qui laborum
non ipsam ullam tempore reprehenderit illum eligendi cumque mollitia temporibus! Natus dicta qui est optio rerum.
</p>
</div>
</li>
</ul>
Well basically I'm creating some forums, and for example we're looking at a thread and the user information is on the left, and the content of the thread is on the right, and then under is the user's signature.
Now, I'm trying to get the user information on the left to stretch down to the height of its container...
http://prntscr.com/7dbdww
.topic {
width: 100%;
display: inline-block;
border: 1px solid #444;
margin-bottom: 20px;
position: relative;
}
.topic-header {
width: 100%;
height: 40px;
display: block;
background-color: #CD422B;
border-left: 1px solid #CD422B;
border-right: 1px solid #CD422B;
}
.topic-header h4 {
color: #fff;
font-family: 'Titillium Web', sans-serif;
font-size: 18px;
font-weight: 700;
padding-left: 10px;
line-height: 40px;
margin: 0;
}
.topic-userinfo {
width: 20%;
min-height: 200px;
display: inline-block;
position: relative;
float: left;
left: 0;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
.topic-usersig {
width: 80%;
height: 150px;
max-height: 300px;
display: inline-block;
overflow-y: auto;
position: relative;
float: right;
right: 0;
background-color: #323232;
border-top: 1px dashed #444;
}
.topic-body {
width: 80%;
min-height: 200px;
display: inline-block;
position: relative;
float: right;
right: 0;
background-color: #323232;
color: #fff;
}
That's css ^ here's html
<div class="topic">
<div class="topic-header">
<h4><i class="fa fa-fw fa-comment"></i> Test</h4>
</div>
<div class="topic-userinfo">
<div class="userinfo-box">
<center>
<span class="userinfo-name admin-color">
deaL
</span>
<span class="userinfo-rank">
Administrator
</span>
<img src="http://www.skruffysdeveloper.com/assets/img/user_img_default.png" style="border: 1px solid #333; width: 90px; height: 90px;">
</center>
</div>
<center>
Joel Evans
</center>
</div>
<div class="topic-body">
<div class="topic-content">test2</div>
</div>
<div class="topic-usersig">
<div style="margin: 10px"></div>
</div>
</div>
use these css for parent
.parent {
overflow: hidden;
position: relative;
width: 100%;
}
use these css for child
.child {
background:blue;
height: 100%;
width: 50%;
position: absolute;
right: 0;
top: 0;
}
Just setting the height alone to 100% didn't work for me. I also changed the position to absolute for that div.
CSS
.topic-userinfo {
width: 20%;
height: 100%;
display: inline-block;
position: absolute;
float: left;
left: 0;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
JSFiddle
Some serious issues with this code, and most of the answers as well:
The <center> tag has been deprecated for a very, very long time. Use the CSS text-align property.
Using float: right / left and display: inline-block together doesn't make sense. The computed value of display will be block, regardless.
Using float and then position: absolute also makes no sense. The computed value of float will be none.
Using display: inline-block on elements that are clearly intended as block level elements.
Percentage width on a sidebar that contains elements with a fixed width. That won't scale down nicely.
Rogue inline styles.
Your CSS is muddled, because your markup is structured poorly. By balancing your markup and styles, you can achieve the intended look without so much hacking about on either side. Sometimes more is less.
Here's a simple example where the .topic-user-info will always match the height of the .topic-message and .topic-signature elements combined. No floats, only one position: absolute, and some nice, semantic markup.
DEMO
.topic {
width: 100%;
border: 1px solid #444;
}
.topic-header {
width: 100%;
height: 40px;
background-color: #CD422B;
}
.topic-content {
padding-left: 180px;
position: relative;
box-sizing: border-box;
width: 100%;
color: white;
}
.topic-user-info {
position: absolute;
width: 180px;
height: 100%;
left: 0;
background-color: #444;
text-align: center;
}
.topic-body {
width: 100%;
background-color: #323232;
}
.topic-message,
.topic-signature {
padding: 10px;
box-sizing: border-box;
}
.topic-message {
min-height: 180px;
}
.topic-signature {
min-height: 120px;
border-top: 1px dashed #444;
}
<div class="topic">
<header class="topic-header">Header</header>
<section class="topic-content">
<div class="topic-user-info">User Info</div>
<article class="topic-body">
<div class="topic-message">
<p>Message</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sed et deleniti rem, odio sit perspiciatis quasi dignissimos repellat inventore sequi cupiditate vel quam, asperiores nisi magni, quaerat at autem id dolorem! Dolor, nobis! Fuga nisi aut deserunt in delectus nam quidem ea asperiores, animi nihil. Delectus, ab nisi. Possimus, laborum quos impedit atque eius ex ab enim a amet omnis ullam totam facere sed necessitatibus aut nihil reprehenderit sequi optio doloremque rerum voluptatum ea adipisci minus, molestias modi. Numquam iste, ducimus consequatur deleniti dolores explicabo. Doloremque odio placeat deleniti ipsam consequatur beatae eius doloribus reiciendis ut sit unde distinctio modi voluptates expedita sint ad, earum asperiores aliquid est architecto autem in, quibusdam officiis! Distinctio, eos quaerat, id illum aliquam aut.</p>
</div>
<aside class="topic-signature">
<p>Signature</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti delectus laudantium minima magni temporibus distinctio, aut modi saepe deserunt praesentium eligendi qui quod, ratione omnis exercitationem officiis repellendus adipisci eum molestias vitae, sed. Atque dicta in veniam ducimus voluptatem quasi accusantium, temporibus esse, aliquid itaque explicabo omnis, delectus expedita rem.</p>
</aside>
</article>
</section>
</div>
Use height:100%
.topic-userinfo {
width: 20%;
min-height: 200px;
display: inline-block;
height:100%;
position: relative;
float: left;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
Marks Answer is almost perfect, except that it stretches a bit to far because of the header. If we offset for the header, it's perfect.
.topic-userinfo {
width: 20%;
height: calc(100% - 40px);
display: inline-block;
position: absolute;
float: left;
left: 0;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
https://jsfiddle.net/1pntme1x/1/
The main issue at hand is that you need the left-floated child .topic-user-info to take 100% height of the parent. But the parent's height is auto by default, meaning it will adjust its height to fit the children. And that is why simply putting height:100% on the floated left child won't work.
The solution is to absolutely position the left child, and float the thread content and signature to the right. If your markup is done properly, it becomes very easy to do. I personally think the HTML is pretty poor - non-semantic tags, use of deprecated tag <center>, plenty of inline styles. The best thing to do would actually be to rewrite them.
* {
box-sizing: border-box;
}
.topic {
width: 100%;
display: inline-block;
border: 1px solid #444;
margin-bottom: 20px;
position: relative;
}
.topic-header {
display: block;
width: 100%;
height: 40px;
background-color: #CD422B;
border-left: 1px solid #CD422B;
border-right: 1px solid #CD422B;
}
.topic-header h4 {
color: #fff;
font-family: 'Titillium Web', sans-serif;
font-size: 18px;
font-weight: 700;
padding-left: 10px;
line-height: 40px;
margin: 0;
}
.topic-user-info {
position: absolute;
padding: 0 10px;
height: calc(100% - 40px);
width: 20%;
min-width: 130px;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
text-align: center;
}
.topic-user-info > .public-profile {
position: relative;
margin: 10px auto;
background-color: #fff;
}
.topic-user-info > .public-profile > .screen-name {
color: red;
}
.topic-user-info > .public-profile > .rank {
color: #000;
}
.topic-user-info > .public-profile > .avatar {
width: 90px;
height: 90px;
border: 1px solid #333;
}
.topic-body {
float: right;
width: 80%;
min-height: 500px;
background-color: #323232;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
.topic-content {
padding: 20px;
min-height: 200px;
}
.topic-usersig {
padding: 20px;
height: 150px;
max-height: 300px;
background-color: #323232;
border-top: 1px dashed #444;
}
<article class="topic">
<header class="topic-header">
<h4>Test</h4>
<!-- maybe other things in header -->
</header>
<section class="topic-user-info">
<article class="public-profile">
<div class="screen-name">deaL</div>
<div class="rank">Administrator</div>
<img class="avatar" src="http://www.skruffysdeveloper.com/assets/img/user_img_default.png" alt="" />
</article>
<div class="user-real-name">Joel Evans</div>
</section>
<section class="topic-body">
<section class="topic-content">
<h3>Test2</h3>
</section>
<section class="topic-usersig">
Some signature here
</section>
</section>
</article>
height 100% some times doesn't seem to work as it should . We can use a small Js function to handle this.
We have added same class 'EqHeightDiv' to both the divs which we want to have same heights. then add following code in document ready js .
function equalHeight(group) {
var tallest = 0;
group.each(function() {
var thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
equalHeight($(".EqHeightDiv"));
the Function will return the height of tallest div from the two divs and append that height to the shorter div.