How to align text in the following way using css / html? - html

I've just added one small area on my website which looks like this:
The problem is in the "About me:" section. I need to move text there to look like this:
Can anyone suggest css / html align solution that would position text like in the second example?
Current HTML
<div id="profInfo">
<div id="profImage">
<img src="..." alt="user: ..."/>
</div>
<div id="profDetails">
<ul>
<li><b class="underb" style="color: #7da315;">Name</b><b style="color: #7da315;">:</b> Ilya Knaup </li>
<li><b class="underb" style="color: #1e8bb4;">Country</b><b style="color: #1e8bb4;">:</b> Spain </li>
<li><b class="underb" style="color: #c86c1f;">Stories</b><b style="color: #c86c1f;">:</b></li>
<li><b class="underb" style="color: #af1e83;">About me</b><b style="color: #af1e83;">:</b> Lorem ipsum dummy textum ...</li>
</ul>
</div>
</div>
Current CSS
* {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
#profInfo {
width: 512px;
margin: 10px 4px 0 3px;
}
#profImage {
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
height: 100px;
width: 100px;
padding: 1px;
float: left;
background: #535353;
border: 1px solid #272727;
-khtml--webkit-box-shadow: 0 1px 2px #d6d6d6;
-moz-box-shadow: 0 1px 2px #d6d6d6;
box-shadow: 0 1px 2px #d6d6d6;
}
#profDetails {
float: right;
width: 395px;
line-height: 22px;
}
#profDetails ul {
list-style: none;
font-size: 13px;
}
.underb {
text-decoration: underline;
}
#profImage img {
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
Here is all code together http://jsfiddle.net/8ERvz/7/

You can use float:left (on the “About Me”) and overflow:hidden (on the rest of the text) to achieve the layout you want.
Here’s an implementation with <span> tags and style attributes, just to illustrate what’s going on:
<li>
<span style="float: left;">
<b class="underb" style="color: #af1e83;">About me</b>
<b style="color: #af1e83;">:</b>
</span>
<span style="display:block; overflow:hidden; padding-left:.5em;">
Lorem ipsum dummy textum Lorem ipsum dummy textum Lorem ipsum dummy textum Lorem ipsum dummy textumLorem ipsum dummy textum Lorem ipsum dummy textum Lorem ipsum dummy textum Lorem ipsum dummy textum Lorem ipsum dummy textum
</span>
</li>
http://jsfiddle.net/fpzkx/
My answer to this question used the same technique; reading that might make it a bit clearer.

As crazy as it sounds, you can use a table.
You've got a set of headers with a set of data. Sounds like a table to me.

Update HTML
<div id="profInfo">
<div id="profImage">
<img src="..." alt="user: ..."/>
</div>
<div id="profDetails">
<ul>
<li><b class="underb" style="color: #7da315;">Name</b><b style="color: #7da315;">:</b> Ilya Knaup </li>
<li><b class="underb" style="color: #1e8bb4;">Country</b><b style="color: #1e8bb4;">:</b> Spain </li>
<li><b class="underb" style="color: #c86c1f;">Stories</b><b style="color: #c86c1f;">:</b></li>
<li><div style="float:left; display:block;width:60px;"><b class="underb" style="color: #af1e83;">About me</b>: </div> <p style="display:block;width:300px;padding-left:60px;">Lorem ipsum dummy textum ... Lorem ipsum dummy textum ... Lorem ipsum dummy textum ... Lorem ipsum dummy textum ...<p></li>
</ul>
</div>
</div>
Of course it would be better to store these updates in your stylesheet as opposed to inline styles but this will show you what needs to be done.

Related

CSS Full Height with divs distributing left space

I am building a message box with title, description, and answers.
I have been struggling for days with that, even played with a Codepen, but can't figure to handle this correctly.
I need:
Title to expand to a maximum of 300px before scrolling
Description to expand to a maximum to left space if no answer (or few), distribute space say 80% of space otherwise (I will add a button to hide this space) before scrolling also
Fixed height for message number title
Messages div to expand to a maximum space left
Input area to stay at bottom and able to size up if any user input (again let's say 20% before scrolling?)
Codepen link
<div class="demoContainer">
<div class="page">
<div class="title">
<h1>My awesome title that is so long i will move everything down</h1>
<button>Some stuff to click</button>
</div>
<div class="row">
<div class="colLeft">
<div class="description">
<h2>Author</h2>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsumipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsumipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsumipsum lorem ipsum lorem ipsum lorem ipsumlorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum </p>
</div>
<div class="between">
<p>Answers</p>
</div>
<div class="messages">
<ul>
<li>
toto
</li>
<li>
tAta
</li>
<li>
tAta
tAta
</li>
<li>
tAta
</li>
<li>
tAta
</li>
<li>
tAta
</li>
>
<li>
tAta
</li>
>
<li>
tAta
</li>
>
<li>
tAta
</li>
>
<li>
tAta
</li>
</ul>
</div>
<div class="input">
<textarea placeholder="Input height adapt to size until a maximum"></textarea>
</div>
</div>
<div class="colRight">
<ul>
<li>
some
</li>
<li>
stuff
</li>
</ul>
</div>
</div>
</div>
<div class="divider"></div>
<div class="page">
<div class="title">
<h1>My awesome short title</h1>
<button>Some stuff to click</button>
</div>
<div class="row">
<div class="colLeft">
<div class="description">
<h2>Author</h2>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum </p>
</div>
<div class="between">
<p>Answers</p>
</div>
<div class="messages">
<ul>
<li>
toto
</li>
<li>
tAta
</li>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</ul>
</div>
<div class="input">
<textarea placeholder="Input height adapt to size until a maximum"></textarea>
</div>
</div>
<div class="colRight">
<ul>
<li>
some
</li>
<li>
stuff
</li>
</ul>
</div>
</div>
</div>
</div>
* {
box-sizing: border-box;
}
.demoContainer {
display: flex;
flex-direction: row;
}
.divider {
width: 8px;
}
.page {
height: 600px;
width: 550px;
background-color: lightgrey;
display: flex;
flex-direction: column;
overflow: auto;
}
.title {
display: inline-flex;
justify-content: space-between;
align-items: center;
max-height: 200px;
}
.title button {
width: 90px;
height: 30px;
}
.row {
display: flex;
/*flex: 1 1 100%;*/
min-height: 0;
height: 100%;
}
.colLeft {
flex: 3 1 auto;
min-height: 0;
height: 100%;
border: 1px solid blue;
display: block;
flex-direction: column;
position: relative;
/*align-items: stretch;
align-content: stretch;*/
}
.description {
border: 1px dashed black;
/*flex: 4 1 100%;*/
max-height: 60%;
overflow: scroll;
}
.between {
border: 1px solid green;
height: 1, 1em;
}
.between>p {
margin: 0;
}
.messages {
border: 1px dashed red;
/*flex: 2 100 auto;*/
overflow: scroll;
}
ul {
max-width: 100%;
}
.input {
width: 100%;
min-height: 1rem;
flex: 1 1 3rem;
display: flex;
border: 1px solid yellow;
position: relative;
bottom: 0;
}
.input>textarea {
width: 100%;
}
.colRight {
flex: 1 1 auto;
border: 1px solid black;
min-width: 150px;
overflow: scroll;
}
The one on the right is a short example of what I would like, but remove <br/> to see the problem.
I tried with display: grid, isplay: block display: flex. I can't seem to find anything satisfying my needs.
My question is: is that even possible? With CSS only?
For everyone wondering, i discovered a few things while digging into css.
First of all is you can set a 100% height on a div to take up the free space if another element is in, but if and only if you set the parent element display: flex; !
With that in mind, it comes easier.
After that, I decided to dive into JS as my problem does not seem to be solvable with CSS only.
I took advantage of the "new" position: sticky; property, and my JS can take care of position it top: 0; or bottom: 0; depending on the scrolling position.
CSS Added :
.stickyBottom{
position: sticky;
bottom: 0;
}
.stickyTop{
position: sticky;
top: 0;
}
JS Code added:
var colLeft = document.getElementsByClassName("messagesInput")[0];
colLeft.onscroll = function(){myFunction()};
// Get the navbar
var between = document.getElementsByClassName("between")[0];
var desc = document.getElementsByClassName("description")[0];
// Get the offset position of the navbar
var sticky = between.offsetTop;
//between.classList.remove("stickyBottom")
function myFunction() {
if (colLeft.scrollTop >= sticky) {
between.classList.remove("stickyBottom")
between.classList.add("stickyTop")
} else {
between.classList.add("stickyBottom")
between.classList.remove("stickyTop");
}
}
It ends up in a way better UX than I initially wanted ! :)
CodePen Link updated accordingly.

How to get the section when click on the respective links in the fixed header

Scenario: When I click on the title1 link in the fixed header, it should display title1 section and when I click on title2 link it should display title 2 section on the top like that..but here it's displaying on the top of the page but behind the header, so it's not visible
I have attached the code which I tried, Please help to resolve this
.menu {
height: 165px;
position: fixed;
background-color: lightgrey;
margin-top: -113px;
width: 1090px;
}
#menu-center ul {
margin:35px 0 0px 115px
}
#menu-center ul li {
list-style: none;
margin: 0 30px 0 0;
display: inline;
}
.Avatar1{
background: #ED7D31;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar2{
background: #A5A5A5;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar3{
background: #FFC000;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar4{
background: #5b9bd5;
border-radius:50%;
display:inline-block;
padding:10px;
}
.Avatar5{
background: #70AD47;
border-radius:50%;
display:inline-block;
padding:10px;
}
div.item {
vertical-align: top;
display: inline-block;
text-align: center;
width: 120px;
}
.caption {
display: block;
color:#ffffff;
}
#Title1 {
height: 100%;
width: 100%;
padding-top: 165px;
}
#Title2 {
height: 100%;
width: 100%;
padding-top: 25px;
}
#Title3{
height: 100%;
width: 100%;
padding-top: 25px;
}
#Title4 {
height: 100%;
width: 100%;
padding-top: 25px;
}
#Title5 {
height: 100%;
width: 100%;
padding-top: 280px;
}
.vertical {
border-left: 190px solid #5786c5;
margin-left:900px;
margin-top: -1620px;
height: 1620px;
}
.items-01{
margin-right: 253px;
font-size: 16px;
line-height:1.8;
}
<body>
<table width="1094px" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<div>
<h2 style="
font-size: 28px;
text-align: center;
margin-left: -150px;">Heading</h2>
<div class="m1 menu">
<div id="menu-center">
<ul>
<li><a class="nav-link" href="#Title1"><div class="item"><img src="picture.png" class="Avatar1" width="50" height="50" > <span class="caption">Title1</span></div></a>
</li>
<li><a class="nav-link" href="#Title2"><div class="item"><img src="picture.png" class="Avatar2" width="50" height="50" > <span class="caption">Title2​</span></div></a>
</li>
<li><a class="nav-link" href="#Title3"><div class="item"><img src="picture.png" class="Avatar3" width="50" height="50" > <span class="caption">Title3</span></div></a>
</li>
<li><a class="nav-link" href="#Title4"><div class="item"><img src="picture.png" class="Avatar4" width="50" height="50" > <span class="caption">Title4</span></div></a>
</li>
</li>
<li><a class="nav-link" href="#objective"><div class="item"><img src="picture.png" class="Avatar5" width="50" height="50" > <span class="caption">Title5</span></div></a>
</li>
</ul>
</div>
</div>
<div style="margin-top:0px;">
<div class="content" id="Title1">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title1
</h1>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
</li>
</ul>
</div>
<div class="content" id="Title2" style="margin-top:0px;">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title2
</h1>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text of the printing
</li>
</ul>
</div>
<div class="content" id="Title3" style="margin-top:0px;">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title3
</h1>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type.
</li>
</ul>
</div>
<div class="content" id="Title4" style="margin-top:0px;">
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title4
</h1>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
</ul>
</div>
<div class="content" id="Title5" style="margin-top:0px;" >
<h1 style = "color: #333333;font-weight: bold;font-size: 25px;">
Title5
</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.<br/><br/>
when an unknown printer took a galley of type and scrambled it to make a type specimen book</p>
<ul>
<li class="items-01">Lorem Ipsum is simply dummy text </li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
<li class="items-01">Lorem Ipsum is simply dummy text</li>
</ul>
</div>
</div>
</div>
</td>
</tr>
</table>
</body>
It can be achieved by using javascript and jquery library.
Import jquery library to your code.
use this below code inside a script tag.
$('#menu-center ul').find('a').click(function(e){
e.preventDefault();
var menuHeight = $('.menu').height();
var $href = $(this).attr('href');
var $anchor = $($href).offset(); // Get position of section.
//Scroll particular section to top with adjusting menu height.
window.scrollTo($anchor.left,$anchor.top- menuHeight);
return false;
});

Hide / Show panel on click inside complex shape container

Just trying to figure out the layout to make this work. I have to show and hide a menu when you click on the arrow shape at the bottom of the icon panel and then show the panel when i click the same shape again. The part that is troubling me is how to shape the arrow container, should i use css3 shapes or just a backgound img for that part (which seems unlikely to me since it have to fit perfectly with the icons container) or just make the whole thing (tne container and the bottom shape a css3 shape).
I know how to make the toggle up / down work but just trying to layout this the best way possible, any ideas will be really appreciated. I can use css3 shapes, flex, etc, crossbrowsing is not an issue for this one.
Here's the images:
Here's the html that i have so far:
<nav class="l-apps l-container">
<ul>
<li>
<img src="assets/img/icons/google.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/word.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/file.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/network.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/powerpoint.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/diamond.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/other.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/pencil.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/excel.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/triangle.png">
Lorem Ipsum
</li>
</ul>
</nav>
Well i figure it out in case somebody else needs to do this someday:
Basically same html but adding some containers for the css3 shaped div with the toggle trigger:
<nav class="l-apps l-container">
<ul>
<li>
<img src="assets/img/icons/google.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/word.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/file.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/network.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/powerpoint.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/diamond.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/other.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/pencil.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/excel.png">
Lorem Ipsum
</li>
<li>
<img src="assets/img/icons/triangle.png">
Lorem Ipsum
</li>
</ul>
<div class="shape-container">
<div class="base">
<i class="icon-toogle fa fa-angle-double-up"></i>
</div>
</div>
</nav>
Then this is the scss for the shape:
.base {
background: $blue;
display: inline-block;
height: 105px;
margin-top: 50px;
position: relative;
width: 150px;
.icon-toogle {
position:absolute;
color: $white;
font-size:1.8em;
bottom:-.35em;
left:0;
right:0;
margin:auto;
text-align:center;
}
&:before {
border-top: 20px solid $blue;
border-left: 75px solid transparent;
border-right: 75px solid transparent;
content: "";
height: 0;
left: 0;
position: absolute;
bottom: -20px;
width: 0;
}
}
Now i have other problem, the whole shape have a pattern background image (the icon container and the css shape at the bottom), i can't get to put a background image to the shape, maybe because i use borders to make the css shape. Is there a way to put a background image on the shape ?
my idea is
$('div').on('click', function(){
var _class = $(this).hasClass('a-top') ? 'b-top' : 'a-top';
$(this).attr('class',_class);
});
.a-top {
background: #f00;
height: 50px;
top:0px;
transition: all .3s ease-out;
}
.b-top {
background: #f00;
height: 100px;
transition: all .3s ease-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="a-top">
menu click me.
</div>

Flexbox - "space-between" - Zero width elements cause unwanted spaces

I am trying to create a kind of "glossary" with flexbox elements. I have a navigation to scroll to the right letter.
There is my Problem:
I placed anchor-links before the first element of each letter. This causes unwanted spaces even if the elements has got width:0px; visibility:hidden; etc. I guess I've tried nearly everything... Hope you've got a solution.
Notice: In this case it is not an option to set the anchor-link to position:absolute!
*, *:before, *:after {
padding: 0;
margin: 0;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.letters {
background: #fff;
border-bottom: 1px solid #ccc;
text-align: center;
padding: 10px;
margin-bottom: 20px
}
.letters ul li {
display: inline-block;
height: 34px;
line-height: 34px;
list-style: outside none none;
text-align: center;
width: 34px;
margin: 0 .27em;
}
.letters ul li a {
background: #ad1800 none repeat scroll 0 0;
border: 1px solid #ad1800;
color: #fff;
display: block;
line-height: 32px;
text-decoration: none;
}
.letter_around {
list-style: none;
padding: 20px 50px;
position: relative;
-webkit-flex-flow: row wrap;
-moz-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-justify-content: space-between;
-moz-justify-content: space-between;
justify-content: space-between;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.glossary_item {
padding: 15px 20px 20px;
width: 22%;
background: #fff;
border: 1px solid #ccc;
transition: 0.4s all;
overflow: hidden;
margin-bottom: 20px;
}
.glossary_letter {
width: 0px;
height: 0px;
overflow: hidden;
position: relative;
visibility: hidden;
}
<div class="wrapper glossary_wrapper">
<div class="content clearfix">
<div class="letters clearfix">
<ul class="letters_ul">
<li class="glossarylink">
A
</li>
<li class="glossarylink">
B
</li>
<li class="glossarylink">
C
</li>
<li class="glossarylink">
D
</li>
<li class="glossarylink">
E
</li>
</ul>
</div>
<div class="letter_around">
<a class="glossary_letter" id="A" name="A"></a>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="B" name="B"></a>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="C" name="C"></a>
<div class="glossary_item"><span class="glossary-title">C - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="D" name="D"></a>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="E" name="E"></a>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
</div>
</div>
</div>
This solution is not particularly clean. Ideally, someone with more knowledge will provide a better solution.
Remove justify-content property from .letter-around
Add margin-right: auto to glossary-item to create space between the items.
Target the last item in each grid using nth-of-type selector, and remove the margin.
I have changed the glossary-letter from a to a span, I think it makes more sense semantically. I have also moved some of the css rules from .glossary-item to the span.
*,
*:before,
*:after {
padding: 0;
margin: 0;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.letters {
background: #fff;
border-bottom: 1px solid #ccc;
text-align: center;
padding: 10px;
margin-bottom: 20px
}
.letters ul li {
display: inline-block;
height: 34px;
line-height: 34px;
list-style: outside none none;
text-align: center;
width: 34px;
margin: 0 .27em;
}
.letters ul li a {
background: #ad1800 none repeat scroll 0 0;
border: 1px solid #ad1800;
color: #fff;
display: block;
line-height: 32px;
text-decoration: none;
}
.letter_around {
list-style: none;
padding: 20px 50px;
position: relative;
-webkit-flex-flow: row wrap;
-moz-flex-flow: row wrap;
flex-flow: row wrap;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.glossary_item {
transition: 0.4s all;
overflow: hidden;
margin-bottom: 20px;
width: 22%;
margin-right: auto;
}
.glossary_item span {
padding: 15px 20px 20px;
background: #fff;
border: 1px solid #ccc;
display: block;
}
.glossary_item:nth-of-type(4n) {
margin-right: 0;
}
<div class="wrapper glossary_wrapper">
<div class="content clearfix">
<div class="letters clearfix">
<ul class="letters_ul">
<li class="glossarylink">
A
</li>
<li class="glossarylink">
B
</li>
<li class="glossarylink">
C
</li>
<li class="glossarylink">
D
</li>
<li class="glossarylink">
E
</li>
</ul>
</div>
<div class="letter_around">
<span class="glossary_letter" id="A" name="A"></span>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<span class="glossary_letter" id="B" name="B"></span>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<span class="glossary_letter" id="C" name="C"></span>
<div class="glossary_item"><span class="glossary-title">C - Lorem ipsum dolor </span></div>
<span class="glossary_letter" id="D" name="D"></span>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<span class="glossary_letter" id="E" name="E"></span>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
</div>
</div>
</div>
The most simple solution is to add
.glossary_letter {
display: none;
}
So it fisically will be but your extra space will disappear.
Ok, try another way, it keeps the anchor link working:
.glossary_letter {
flex: 0 0 100%;
}
Found the solution for my own. It's not the best solution I guess, but it works fine.
I filled the spaces calculated by flexbox itself with a margin-left minus value of the percentage that is left. So in my Case the widht of the elements was 22%. This 4x is 88% of the whole container width. That means that the calculated margin of the elements is about 4% of the container width. So if you reduce the margin of the anchor-element by 4% you get the right position of the boxes.
I know that is not the best solution, but it works. If you've got a better one, please show me. :)
*, *:before, *:after {
padding: 0;
margin: 0;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.letters {
background: #fff;
border-bottom: 1px solid #ccc;
text-align: center;
padding: 10px;
margin-bottom: 20px
}
.letters ul li {
display: inline-block;
height: 34px;
line-height: 34px;
list-style: outside none none;
text-align: center;
width: 34px;
margin: 0 .27em;
}
.letters ul li a {
background: #ad1800 none repeat scroll 0 0;
border: 1px solid #ad1800;
color: #fff;
display: block;
line-height: 32px;
text-decoration: none;
}
.letter_around {
list-style: none;
padding: 20px 10px;
position: relative;
-webkit-flex-flow: row wrap;
-moz-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-justify-content: space-between;
-moz-justify-content: space-between;
justify-content: space-between;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.glossary_item {
padding: 15px 20px 20px;
width: 22%;
background: #fff;
border: 1px solid #ccc;
transition: 0.4s all;
overflow: hidden;
margin-bottom: 20px;
}
.glossary_letter {
width: 0px;
height: 0px;
overflow: hidden;
position: relative;
visibility: hidden;
margin-left: -4%;
}
<div class="wrapper glossary_wrapper">
<div class="content clearfix">
<div class="letters clearfix">
<ul class="letters_ul">
<li class="glossarylink">
A
</li>
<li class="glossarylink">
B
</li>
<li class="glossarylink">
C
</li>
<li class="glossarylink">
D
</li>
<li class="glossarylink">
E
</li>
</ul>
</div>
<div class="letter_around">
<a class="glossary_letter" id="A" name="A"></a>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="B" name="B"></a>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="C" name="C"></a>
<div class="glossary_item"><span class="glossary-title">C - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="D" name="D"></a>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="E" name="E"></a>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
</div>
</div>
</div>
Setting justify-content: space-around is basically the same as setting auto to left and right margins to all flex items (the available space will be distributed equally on the left and on the right of each of them). So, to exclude some items from available space distribution, you can remove justify-content and set the equivalent margins only to the needed items:
*, *:before, *:after {
padding: 0;
margin: 0;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.letters {
background: #fff;
border-bottom: 1px solid #ccc;
text-align: center;
padding: 10px;
margin-bottom: 20px
}
.letters ul li {
display: inline-block;
height: 34px;
line-height: 34px;
list-style: outside none none;
text-align: center;
width: 34px;
margin: 0 .27em;
}
.letters ul li a {
background: #ad1800 none repeat scroll 0 0;
border: 1px solid #ad1800;
color: #fff;
display: block;
line-height: 32px;
text-decoration: none;
}
.letter_around {
list-style: none;
padding: 20px 50px;
position: relative;
-webkit-flex-flow: row wrap;
-moz-flex-flow: row wrap;
flex-flow: row wrap;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.glossary_item {
padding: 15px 20px 20px;
width: 22%;
background: #fff;
border: 1px solid #ccc;
transition: 0.4s all;
overflow: hidden;
margin: auto;
margin-bottom: 20px;
}
.glossary_letter {
width: 0;
margin: 0;
}
<div class="wrapper glossary_wrapper">
<div class="content clearfix">
<div class="letters clearfix">
<ul class="letters_ul">
<li class="glossarylink">
A
</li>
<li class="glossarylink">
B
</li>
<li class="glossarylink">
C
</li>
<li class="glossarylink">
D
</li>
<li class="glossarylink">
E
</li>
</ul>
</div>
<div class="letter_around">
<a class="glossary_letter" id="A" name="A"></a>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">A - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="B" name="B"></a>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">B - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="C" name="C"></a>
<div class="glossary_item"><span class="glossary-title">C - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="D" name="D"></a>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">D - Lorem ipsum dolor </span></div>
<a class="glossary_letter" id="E" name="E"></a>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
<div class="glossary_item"><span class="glossary-title">E - Lorem ipsum dolor </span></div>
</div>
</div>
</div>

HTML/CSS the same div lengths

I have 3 divs (example below):
<ul>
<div class="parent">
<li>
<div>
Lorem Ipsum is simply dummy
</div>
</li>
</div>
<li>
<div class="parent">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting
</div>
</li>
</div>
</div>
</ul>
And I want to all of them to have the same widths as the longest. The width of the longest should be the same as the text inside it plus some pixel (f.e. + 15px). The text will be changing so width should dynamically changing. Display has to be inline-table.
Is it possible to do something like that in the HTML/CSS?
Yes it is possible using HTML/CSS. Here is the code snippet.
.parent {
display: inline-block;
width: auto;
}
.parent div {
border: 1px solid black;
padding-right: 15px;
}
<div class="parent">
<div>
Lorem Ipsum is simply dummy
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting
</div>
<div>
Lorem Ipsum is simply dummy text of the print
</div>
</div>
As per below code...
ul {
display: inline-block;
}
ul li {
list-style: none;
}
li div {
border: 1px solid black;
padding-right: 15px;
}