CSS: prevent item lowering with multiple text lines - css

First of all excuse me if the title is unclear. I dont really know how to describe the problem which also makes it harder for me to google for solutions.
I've inserted my code in a fiddle so I can explain it better:
https://jsfiddle.net/Lzbavyu9/2/
I want the X always to be on the same height as the first line of the text. I've tried things as vertical-align but that doesnt work. It always moves down with the last line of the text.
code is below
<div class="panel-title">
<h3>test sdfjsdf sdjfk sjkdf sdjk fjksd fjskdf jksdfj ksdfjk sfd jksd</h3>
<span class="collapse-button">
<i class="pull-right" aria-hidden="true">X</i>
</span>
</div>
CSS
.panel-title {
width: 200px;
}
.panel-title h3 {
margin: 8px 0 -1em 0;
display: block;
width: calc(100% - 30px);
}
.panel-title span.collapse-button {
padding: 0px;
height: 25px;
margin: 0px;
display: block;
}
.collapse-button i {
width: 25px;
height: 15px;
}
.pull-right {
float: right !important;
}
Does anybody have an idea?
Thanks in advance

div h3{
display: inline-block;
max-width: 10em;
vertical-align: top;
margin: 0;
}
<div>
<h3>test sdfjsdf sdjfk sjkdf sdjk fjksd fjskdf jksdfj ksdfjk sfd jksd</h3>
<i>X</i>
</div>

Flexbox can do that
* {
margin: 0;
padding: 0;
}
.panel-title {
width: 200px;
display: flex;
margin: 1em;
border: 1px solid grey;
}
.panel-title h3 {
display: block;
flex: 1;
}
.panel-title span.collapse-button {
padding: 0px;
height: 25px;
margin: 0px;
display: block;
}
.collapse-button i {
width: 25px;
height: 15px;
}
<div class="panel-title">
<h3>test sdfjsdf sdjfk sjkdf sdjk fjksd fjskdf jksdfj ksdfjk sfd jksd</h3>
<span class="collapse-button">
<i aria-hidden="true">X</i>
</span>
</div>
<div class="panel-title">
<h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem alias est ex, reiciendis expedita natus distinctio quos ipsam cumque soluta, iusto incidunt molestias mollitia, ullam labore aliquid iure inventore voluptate!</h3>
<span class="collapse-button">
<i aria-hidden="true">X</i>
</span>
</div>

You should use position: absolute on your .collapse-button class. Add position: relative in your .panel-title class. If you want to adjust the position of the X, you can change the values of top, right, left and bottom properties in .collapse-button class
.panel-title {
width: 200px;
}
.panel-title h3 {
margin: 8px 0 -1em 0;
display: block;
width: calc(100% - 30px);
position: relative;
}
.panel-title span.collapse-button {
padding: 0px;
height: 25px;
margin: 0px;
display: block;
position: absolute;
top: 10px;
right: 0;
}
.collapse-button i {
width: 25px;
height: 15px;
}
.pull-right {
float: right !important;
}
<div class="panel-title">
<h3>test sdfjsdf sdjfk sjkdf sdjk fjksd fjskdf jksdfj ksdfjk sfd jksd</h3>
<span class="collapse-button">
<i class="pull-right" aria-hidden="true">X</i>
</span>
</div>

Put this:
.panel-title { position: relative; width: 200px; }
and
.collapse-button i { position: absolute; top: 5px; right: 0px; }

Related

How to give a DIV the width of its content?

I would like to give a DIV the width of the picture in its content.
Here is my HTML :
<div id="container">
<div id="picandtext">
<img src="https://placehold.it/480x320" />
<p>Eodem tempore etiam Hymetii praeclarae indolis viri negotium est actitatum, cuius hunc novimus esse textum. cum Africam pro consule regeret Carthaginiensibus victus inopia iam lassatis, ex horreis Romano populo destinatis frumentum dedit, pauloque postea cum provenisset segetum copia, integre sine ulla restituit mora.</p>
</div>
</div>
Here is my CSS :
#container { height: 600px; display:table; width:1%; background: red; padding:10px; }
#picandtext { height: 400px; display:table; width:1%; background: green; padding:10px; }
#picandtext img { height: 180px; }
#picandtext p { height: 180px; }
I finally found a way to do it with display:table; width:1%; as you can see with this JSFiddle example : https://jsfiddle.net/Ls750c64/2/
But I would like to know if this way is the best one to make it ?
Given your existing markup, you can make #container display: inline-block; and absolutely position the p with text.
#container {
height: 600px;
display: inline-block;
background: red;
padding: 10px;
}
#picandtext {
height: 400px;
background: green;
padding: 10px;
position: relative;
}
#picandtext img {
height: 180px;
}
#picandtext p {
position: absolute;
left: 10px;
right: 10px;
}
<div id="container">
<div id="picandtext">
<img src="https://placehold.it/480x320" />
<p>Eodem tempore etiam Hymetii praeclarae indolis viri negotium est actitatum, cuius hunc novimus esse textum. cum Africam pro consule regeret Carthaginiensibus victus inopia iam lassatis, ex horreis Romano populo destinatis frumentum dedit, pauloque postea cum provenisset segetum copia, integre sine ulla restituit mora.</p>
</div>
</div>
And a less supported way to do it would be using intrinsic sizing. The browser support for it sucks though. http://caniuse.com/#feat=intrinsic-width
#container {
height: 600px;
display: inline-block;
background: red;
padding: 10px;
width: min-content;
}
#picandtext {
height: 400px;
background: green;
padding: 10px;
position: relative;
}
#picandtext img {
height: 180px;
}
<div id="container">
<div id="picandtext">
<img src="https://placehold.it/480x320" />
<p>Eodem tempore etiam Hymetii praeclarae indolis viri negotium est actitatum, cuius hunc novimus esse textum. cum Africam pro consule regeret Carthaginiensibus victus inopia iam lassatis, ex horreis Romano populo destinatis frumentum dedit, pauloque postea cum provenisset segetum copia, integre sine ulla restituit mora.</p>
</div>
</div>

Stacked glyphicons with Font Awesome

I have the fa-circle-thin in which i want to place a glyphicon, so that it looks like there is a round border around my glyphicon. I just want to know if this is even possible?
I've tried following:
<div class="col-md-4">
<span class="circle">
<i class="glyphicon glyphicon-star"></i>
</span>
<h4 class="service-heading">Lorem</h4>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
</div>
However the two icons shows up side by side. I made a class for my FA that looks like this:
.circle:before {
font-family: fontawesome-webfont;
text-decoration: none;
content: "\f1db";
background-color: transparent;
z-index:-1;
}
I'd just use border-radius: 50% instead of trying to position two glyphs (plus you can style the border!). I'm also centering things with text-align: center and by matching the line-height and height values:
.circle {
border: 1px solid black;
border-radius: 50%;
padding: 3px;
width: 25px;
height: 25px;
display: inline-block;
text-align: center;
line-height: 25px;
}
.alt {
border-width: 2px;
border-color: red;
color: red;
width: 15px;
height: 15px;
line-height: 15px;
}
<div class="circle">
🌟
</div>
<div class="circle alt">
🌟
</div>
How about using posiiton:absolute?
.glyphicon{
position: absolute;
top: 3px;
left: 15px;
}
Result: jsfiddle

CSS animation needs correction

I would really appreciate your help if you could check below in the codepen my css animation.
I'm trying to make this work better. I want this underline to start from below the icon, not to be stuck to the window, but to have some space from right just under the first icon.
* {
box-sizing: border-box;
}
body {
font: 300 100% 'Helvetica Neue', Helvetica, Arial;
}
.container {
width: 100%;
margin: 0 auto;
}
ul li {
display: inline;
text-align: center;
}
a {
display: inline-block;
width: 25%;
padding: .75rem 0;
margin: 0;
text-decoration: none;
color: #333;
}
.two:hover ~ hr {
margin-left: 40%;
}
.one:hover ~ hr {
margin-left: 12.5%;
}
.three:hover ~ hr {
margin-left: 66%;
}
.four:hover ~ hr {
margin-left: 75%;
}
hr {
height: .25rem;
width: 20%;
margin: 0;
background: tomato;
border: none;
transition: .3s ease-in-out;
}
.home-content-1{background-color: #F7F8F9; text-align: center;padding:5em 0em 2em;}
.home-content-1 .row{margin-top: 2em;}
.home-content-1 h3{font-weight: 700;text-transform: uppercase;color: #646464;font-size: 1.3125em;}
.hc-icon{width: 150px;height: 150px;border-radius: 50%;margin: 0px auto 2.25em;}
.hc-icon img{padding-top: 30px;}
.hc-icon1{background: #b5d73c;}
.hc-icon2{background: #32aaeb;}
.hc-icon3{background: #ef3f54;}
.circles li { padding: 10px;}
hr {
height: .25rem;
width: 22%;
margin-left: 12.5%;
background: tomato;
border: none;
transition: .3s ease-in-out;
}
<div class="home-content-1">
<div class="container">
<h1>The Blabla Approach</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
<div class="row">
<div class="col span_1_of_4">
<ul class="circles">
<li class="one"><a href="#">
<div class="hc-icon hc-icon1"></div>
<h3>Demand Generation</h3></a></li>
<li class="two"><a href="#"><div class="hc-icon hc-icon1">
</div>
<h3>Demand Generation</h3></a>
</li>
<li class="three">
<a href="#">
<div class="hc-icon hc-icon1"></div>
<h3>Demand Generation</h3></a></li>
<hr />
</ul>
</div>
Please see all my code here -
http://codepen.io/anetk/pen/QyZLNb
Personally, I would do this. I eliminated all the title stuff to isolate what you're trying to do. I substituted your 'hr' element with a 'div'. Changing the div's relative position to the parent container feels a lot safer than changing margins on an 'hr' element that's sized to the body. This responsively sizes the 'highlight' div with the 'li' elements. You can adjust the 'circles' container's margins and widths to your liking.
HTML:
<ul class="circles">
<li class="one">
<a href="#">
<div class="hc-icon hc-icon1"></div>
<h3>Demand Generation</h3>
</a>
</li>
<li class="two">
<a href="#">
<div class="hc-icon hc-icon1"></div>
<h3>Demand Generation</h3></a>
</li>
<li class="three">
<a href="#">
<div class="hc-icon hc-icon1"></div>
<h3>Demand Generation</h3>
</a>
</li>
<div class="highlight"></div>
</ul>
CSS:
body {
font: 300 100% 'Helvetica Neue', Helvetica, Arial;
margin:0;
}
.circles {
display:inline-block;
width:80%;
margin:0 10%;
padding:0;
}
.circles li {
display:inline-block;
list-style-type:none;
text-align:center;
width:33%;
}
.highlight {
position:relative;
left:0;
height:5px;
width:33%;
background: tomato;
transition: .3s ease-in-out;
}
a {
display: inline-block;
width: 100%;
margin: 0;
text-decoration: none;
color: #333;
}
.two:hover ~ .highlight {
left: 33%;
}
.three:hover ~ .highlight {
left: 66%;
}
.circles h3{font-weight: 700;text-transform: uppercase;color: #646464;font-size: 1.3125em;}
.hc-icon{width: 150px;height: 150px;border-radius: 50%;margin: 0px auto 2.25em;}
.hc-icon1{background: #b5d73c;}
.hc-icon2{background: #32aaeb;}
.hc-icon3{background: #ef3f54;}
http://codepen.io/midgitsuu/pen/VeEKgQ
Easiest solution is to put a style on the <hr> to shift it's starting position.
css:
hr {
height: .25rem;
width: 20%;
margin-left: 12.5%;
background: tomato;
border: none;
transition: .3s ease-in-out;
}
The idea is to align the hr with the first circle. You want to use a % and not px so that the align will be responsive with the size of the window.
The change was from margin: 0; to margin-left: 12.5%;

Css z-index not working correctly with bootstrap

I have a block of code that is solid. Works fine. Except for the footer of my site. No idea why but the heading bars are not showing for the footer but they are everywhere else?
here is a pen of the working code
http://codepen.io/VincentStephens/pen/EjyJKP
Here is a screenshot of the not working site:
https://www.dropbox.com/s/y3oxrvzvdvyaai6/Screen%20Shot%202015-05-19%20at%2019.07.47.png?dl=0
This works by creating a :before element. Putting the menu text into a span, then using z-index to position the span on top of the :before.
You can see the element there (see photo), everything is the same but just won't show unless I change the z-index to 0 or higher but then the line is above the heading text in the span???
h1.heading {
color: $light-gold;
text-transform: uppercase;
font-size: 32px;
font-weight: 300;
line-height: 40px;
font-family: SourceSansPro;
span {
background-color: $golden-black;
display: inline-block;
z-index: 1;
padding-right: 10px;
}
}
h1.heading:before {
content: "";
background-color: $light-gold;
display: block;
position: relative;
top: 23px;
width: 100%;
height: 6px;
z-index: -1;
}
HTML - working
<h1 class="heading"><span>The Team</span></h1>
HTML - Footer, not working
<div class="fluid-container footer">
<footer class="container">
<div class="col-lg-4">
<h1 class="heading"><span>About</span></h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quasi vero, inquit, perpetua oratio rhetorum solum, non etiam philosophorum sit. Quae sunt igitur communia vobis cum antiquis, iis sic utamur quasi concessis; De illis, cum volemus. Duo Reges: constructio interrete. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere.</p>
</div>
<div class="col-lg-4">
<h1 class="heading"><span>Address</span></h1>
<p class="address">
address<br>
</p>
<p class="address">
Tell: 0207 374 6141 <br>
Email: enquiries#company.com
</p>
</div>
<div class="col-lg-4">
<h1 class="heading"><span>Connect</span></h1>
<img src="img/social-media.png" width="186" height="46">
<h1>Payment Options</h1>
<img src="img/payment-cards.png" width="267" height="56">
</div>
</footer>
</div>
Thanks for the moment on sanity.... it was indeed a position issue.
The footer also has a background colour. so that entire element needed to have a position: relative; and z-index: -1; added to it.
full code for anyone else in same situation:
SCSS - wil need compiling
.fluid-container.footer {
position: relative;
z-index: -1;
background-color: $light-golden-black;
footer {
h1.heading {
color: $light-gold;
text-transform: uppercase;
font-size: 32px;
font-weight: 300;
line-height: 40px;
font-family: SourceSansPro;
position: relative;
span {
background-color: $light-golden-black;
display: inline-block;
z-index: 1;
padding-right: 10px;
position: relative;
}
}
h1.heading:before {
content: "";
background-color: $light-gold;
display: block;
position: absolute;
top: 23px;
width: 100%;
height: 6px;
z-index: -1;
}
}
}

CSS inline element preventing hover

Using the following markup, I'm creating an image with two floated text overlays, one for the heading and one for the summary text. It's rendering how I wish and I'm able to use the entire image as well as the headline & summary to access the link except for the area immediately to the right of the 'headline' up to the end of the 'summary'. This happens in all browsers (except IE9 and lower). Any ideas why and how I can get around it?
HTML:
<div class="image">
<img src="Assets/Images/Picture.jpg" alt="Picture" />
<div class="overlay">
Headline
Summo eirmod appareat ex mel. Vim odio error labores ex. Mea alii abhorreant et. Ad has nominati constituam. Sit falli nominati suavitate in.
</div>
</div>
CSS:
body {
border: 0;
color: #5B6064;
font-family: Helvetica, Arial, Sans-Serif;
font-size: .75em;
line-height: 1.6em;
margin: 0;
padding: 0;
background-color: #a5a5a5;
}
a {
text-decoration: none;
color: #5B6064;
}
a:visited {
text-decoration: none;
}
img {
border: 0;
}
.image {
position: relative;
width: 100%;
/* For IE6 */
display: block;
overflow: hidden;
}
.overlay {
position: absolute;
bottom: 10px;
left: 0;
display: block;
}
.headline {
color: #FFF;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: #e87b10;
/* Fallback for older browsers */
background: rgba(232,123,16,0.8);
padding: 10px;
float: left;
clear: left;
}
.summary {
max-width: 350px;
margin-top: 3px;
color: #FFF;
font: 14px/14px Helvetica, Sans-Serif;
letter-spacing: 0;
background: #e87b10;
/* Fallback for older browsers */
background: rgba(232,123,16,0.8);
padding: 10px;
float: left;
clear: left;
}
.summary a {
color: #FFF;
}
I'd wrap the whole thing in an a tag (cleaner code). You would need to adjust a bit of your css.
EDIT
I changed the div elements to span so it is syntactically correct (thanks for the reminder Phrogz). Since your css already had display: block for the div elements, changing them to span is not an issue.
<a href="Default.aspx">
<span class="image">
<img src="Assets/Images/Picture.jpg" alt="Picture" />
<span class="overlay">
<span class="headline">Headline</span>
<span class="summary">Summo eirmod appareat ex mel. Vim odio error labores ex. Mea alii abhorreant et. Ad has nominati constituam. Sit falli nominati suavitate in.</span>
</span>
</span>
</a>
The headline is being floated left. If you remove the float and add display:block; to the anchor, it will take up the full image width.

Resources