After trying to add clamping to my headers, my result does not turn out the way I wanted.
I made a fiddle of the code that I am using to achieve my result: https://jsfiddle.net/73kerhsn/
h3
{
margin: 0;
font-size: 13px;
}
ul
{
list-style: none;
padding: 0;
margin: 0;
}
li
{
display: inline-block;
margin: 2px;
padding: 0;
}
.acontainer
{
background-color: yellow;
width: 500px;
padding: 15px;
}
.background
{
background-color: grey;
width: 196px;
}
.block1
{
height: 110px;
width: 195px;
background-color: red;
}
.clamp
{
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
<div class="acontainer">
<ul>
<li class="background">
<div class="block1">
</div>
<h3 class="clamp">
This foo test asdas asdassd saasas dasasa asdasadsd asasddas asdadsg gfhfhg gddfd sddsfsdf
</h3>
<div>
Something
</div>
<div>
Something else
</div>
</li>
<li class="background">
<div class="block1">
</div>
<h3>
This foo test
</h3>
<div>
Something
</div>
<div>
Something else
</div>
</li>
<li class="background">
<div class="block1">
</div>
<h3>
This foo test
</h3>
<div>
Something
</div>
<div>
Something else
</div>
</li>
</ul>
</div>
I want the list items to stay at the same height, even when the header tags get bigger than the ones of the other list items (so for example, the second list item in the jsfiddle appears to be lower from the top than the first list item. I want it to still stick to the top (with the padding still in tact)).
Is there anyone out there that can help me with this?
Thanks in advance.
You probably simply want to add vertical-align: top for your list items.
li
{
display: inline-block;
margin: 2px;
padding: 0;
vertical-align: top;
}
https://jsfiddle.net/73kerhsn/1/
You can just apply this to your css for styling the list-items:
li{
display: inline-table;
}
This will make your li items start from the same height, now you can set the height as you want, it won't hamper your next line contents. If you won't set a fixed height, then only the start of the boxes will remain same.
Related
Using the 98.css library: https://jdan.github.io/98.css/
I'm currently trying to fit the bottom element status-bar at the bottom of the box with its width set to stretch to the entire box's width. I feel like I'm doing it incorrectly and/or not doing it properly via percentages in .width-stretch.
The result is this:
Note that it is somehow overlapping the bottom-right edge of the box. When I try making the width: 99%, it gets pretty close to what I want but not quite, and it is left-aligned (and not centered). I'm trying to figure out a more elegant solution that fixes this issue; any suggestions? I'm also open to any CSS frameworks that can run alongside 98.css to make styling easier. Thanks!
...
<style>
html, body {
margin:0px;
background: #c0c0c0;
}
.center {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top:0px;
right:0px;
bottom:0px;
left:0px;
}
.relative-position {
position: relative;
width: auto;
}
.bottom {
position: absolute;
bottom: 0;
padding-bottom: 4px;
}
.width-stretch {
width: 100%;
}
</style>
</head>
<body>
<!-- MAIN -->
<div class="center">
<div class="window relative-position" style="width: 95%; height: 95vh;">
<div class="title-bar">
<div class="title-bar-text">A Window With A Status Bar</div>
</div>
<div class="window-body">
<p> There are just so many possibilities:</p>
<ul>
<li>A Task Manager</li>
<li>A Notepad</li>
<li>Or even a File Explorer!</li>
</ul>
</div>
<div class="status-bar bottom width-stretch">
<p class="status-bar-field">Press F1 for help</p>
<p class="status-bar-field">Slide 1</p>
<p class="status-bar-field">CPU Usage: 14%</p>
</div>
</div>
</div>
</body>
</html>
You can use flex-direction:column on .window, with flex:1 on the .window-body so that it fills all the available vertical space.
html,
body {
margin: 0px;
background: #c0c0c0;
}
.center {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
.window {
display: flex;
flex-direction: column;
}
.window-body {
flex: 1;
}
<link rel="stylesheet" href="https://unpkg.com/98.css">
<div class="center">
<div class="window " style="width: 95%; height: 95vh;">
<div class="title-bar">
<div class="title-bar-text">A Window With A Status Bar</div>
</div>
<div class="window-body">
<p> There are just so many possibilities:</p>
<ul>
<li>A Task Manager</li>
<li>A Notepad</li>
<li>Or even a File Explorer!</li>
</ul>
</div>
<div class="status-bar">
<p class="status-bar-field">Press F1 for help</p>
<p class="status-bar-field">Slide 1</p>
<p class="status-bar-field">CPU Usage: 14%</p>
</div>
</div>
</div>
Add these styles to the inside of the style tag.
.status-bar {
display: flex;
}
.status-bar-field {
flex: 1;
padding: 0 10px;
border: 1px solid black;
}
I'm trying to create an endless scrollable row, to display info items.
I have set it up as per below and it's making the item the same size as the holder. I've tried using inline-block but that displays the items in one column:
UPDATE:
the link is the is the element that need to appear at the bottom of the item, i've tried positioning absolute this removes the a tag from item completely. i have also tired vertical align:bottom to no effect.
any help is much appreciated.
.holder {
overflow-x: scroll;
overflow-y: visible;
height: 550px;
width: 100%;
padding: 0;
}
.item_row {
display: -webkit-inline-box;
list-style: none;
padding: 0;
}
.item {
width: 300px;
background: #fff;
margin: 0 10px 0 10px;
}
<div class="holder">
<div class="item_row">
<div class="item">
<!-- Info -->
need to appear at bottom
</div>
</div>
</div>
This is your solution for now. If you dont have content in the item why the link goes to bottom. -webkit--inline-box work only chrome thats why i have add two extra display in your .item-row class
Happy coding enjoy and good luck
.holder {
overflow-x: scroll;
overflow-y: visible;
height: 550px;
width: 100%;
padding: 0;
}
.item_row {
display: -webkit-inline-box;
display: -moz-inline-box;
display: -ms-inline-box;
list-style: none;
padding: 0;
}
.item {
width: 300px;
background: #fff;
margin: 0 10px 0 10px;
}
<body>
<div class="holder">
<div class="item_row">
<div class="item">
<!-- Info -->
<img src="http://cdn.online-convert.com/images/image-converter.png"
alt="test">
<h1>test</h1>
<p>test</p>
<p>test</p>
need to appear at bottom
</div>
<div class="item">
<!-- Info -->
<img src="http://cdn.online-convert.com/images/image-converter.png"
alt="test">
<h1>test</h1>
<p>test</p>
<p>test</p>
need to appear at bottom
</div>
</div>
</div>
</body>
I need two columns:
a button on the left
a list on the right
And they both need to be vertically centered in the middle of the wrapper div. So far I got this:
https://jsfiddle.net/s1ky1hqr/1/
I used this code to vertically center the inline-blocks inside the wrapper:
.wrapper {
/* let it fill the whole container */
position: absolute;
top: 0;
bottom: 0;
left: 5px;
right: 5px;
}
.wrapper:before {
content: '';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.column {
display: inline-block;
width: 48%;
}
<footer>
<div class="wrapper">
<div class="column">
<a class="cta" href="#">
<span class="text">
Button
</span>
<span class="arrow">
>
</span>
</a>
</div>
<div class="column">
<ul>
<li>Link 1</li><li>
Link 2</li><li>
Link 3</li>
</ul>
</div>
</div>
</footer>
The only problem is the ul list is not absolutely on the right, because the column divs aren't both 50% wide.
If I give both column divs a width of 50% the two divs won't fit next to each other. And I cannot "float" the column divs, cause in that case the text isn't vertically centered anymore.
Can anyone help me out?
You can actually use columns of 50% width if you set the font-size to 0 inside your wrapper and reset it for your columns, like this:
html { font-size: 12px; }
.wrapper {
/* let it fill the whole container */
position: absolute;
top: 0;
bottom: 0;
left: 5px;
right: 5px;
font-size: 0;
}
.wrapper:before {
content: '';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.column {
display: inline-block;
width: 50%;
font-size: 1rem;
}
<footer>
<div class="wrapper">
<div class="column">
<a class="cta" href="#">
<span class="text">
Button
</span>
<span class="arrow">
>
</span>
</a>
</div>
<div class="column">
<ul>
<li>Link 1</li><li>
Link 2</li><li>
Link 3</li>
</ul>
</div>
</div>
</footer>
You should add vertical-align:middle to .column instead .wrapper:before
You can achieve this by changing the li style to display: block; instead of display: inline-block, and getting rid of float: right; on the ul element.
Here's your example, updated.
This is my first post, because I'm stuck on the first part of making my first website.
I'm trying to make a navigation bar with five parts:
(Vertical list of 3 items) (Label) (Logo) (Label) (Vertical list of 3 items)
For example,
(Apples, Oranges, Pears) (Fruits) (Logo) (Vegetables) (Broccoli, Celery, Lettuce)
With my code, the two vertical lists aren't aligned with each other, and I can't get any of them to center vertically in the bar.
This is my code:
HTML
<body>
<div class='nav'>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-3'>
<ul class='port-list' class='navbar-left'>
<li>Art</li>
<li>Design</li>
<li>Writing</li>
</ul>
</div>
<div class='col-md-3'>
<p class='port'>Portfolio</p>
</div>
<img>
<div class='col-md-3'>
<p class='about'>About</p>
</div>
<div class='col-md-3'>
<ul class='about-list' class='navbar-right'>
<li>Biography</li>
<li>Résumé</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</div>
</body>
CSS
* {
list-style: none;
list-style-type: none;
}
body {
height: 100%; /* Prevents rubber-band scrolling */
overflow: hidden; /* Prevents rubber-band scrolling */
}
.nav {
color: #fff;
font-family: 'Donegal One', serif;
background-color: #004d40;
padding-top: 12px;
padding-bottom: 8px;
display: block;
}
.port-list {
text-align: right;
}
.port {
text-align: left;
}
.about {
text-align: right;
}
.about-list {
text-align: left;
}
This here newbie would appreciate any help. Thanks.
Here is the updated code
HTML
<div class='row newRow'>
Added newRow to row
CSS
.newRow {
width: 100%;
display: table;
}
.newRow .col-md-3 {
display: table-cell;
vertical-align: middle;
float: none
}
You can define line-height for both div as follow:
<div class='col-md-3' style="line-height:58px;">
<p class='port'>Portfolio</p>
</div>
....
<div class='col-md-3' style="line-height:58px;">
<p class='about'>About</p>
</div>
I think I'm going insane over this now, no idea how to resolve it... please help guys.
I have three divs on a page that should all fit onto one line. They have to be square (with rounded corners) so I have to set a width and a height to keep the 1:1 aspect ratio. I have a heading inside them that should be vertically and horizontally centered. The wording of the heading may change and might run over 2 lines so a simple margin-top is not enough in this case.
First problem: there are weird margins at the top despite there not being anything else affecting that (well there must be but I can't see what). If I float the divs they line up but floating isn't the way to go is it... why is inline-block not working?
Second issue (which is likely related, so I'm posting it in one go) is that I'm unable to vertically center the title divs. Any ideas?
Here's a jsfiddle to illustrate: http://jsfiddle.net/fydC4/
The HTML:
<div id="container">
<div class="nav-left">
<p id="nav-left-title">In this section…</p>
<ul>
<li><a class="light" href="#">page title here</a></li>
<li><a class="light" href="#">page title here</a></li>
<li><a class="light" href="#">page title here</a></li>
</ul>
</div>
<div id="main">
<h1>Assignments</h1>
<p>Click on the titles of the assignments to find out more.</p>
<div class="box" id="good-designs">
<h2 class="box">3 good designs</h2>
</div>
<div class="box" id="temp">
<h2 class="box">title here</h2>
</div>
<div class="box" id="temp2">
<h2 class="box">title here</h2>
</div>
</div><!--end main-->
</div>
</div><!--end container-->
The CSS:
#container {
max-width: 960px;
margin: auto;
}
#main {
display: table-cell;
width: 73em;
padding: 1em 2em 2em;
background-color: white;
}
#nav-left-title {
padding-bottom: 0.5em;
margin: 0;
color: white;
}
.nav-left{
display: table-cell;
width: 14em;
background-color: #87a8b1;
padding: 1.1em;
font-size: 1.2em;
}
.nav-left li {
padding: 0.5em 0;
border-bottom: 1px solid white;
}
h2.box {
padding: 15px 0;
margin: 50% 15px;
margin: auto;
text-transform: uppercase;
text-align: center;
}
div.box {
padding: 15px;
height: 180px;
width: 180px;
border-radius: 50%;
margin-top: 25px;
margin-left: 1.5em;
display:inline-block;
/* float: left; */
}
#good-designs {
background-color: green;
}
#temp, #temp2 {
background-color: yellow;
}
Hi you may use two properties to align all your elements
vertical-align:middle;
display:inline-table on div.box and
display:table-cell on h2.box; (for the texts inside your divs)
Check this code http://jsfiddle.net/fydC4/16/
This worked for me, replace inline-block with float left.
you are also calling margins twice on some element which are not necessary
here you go
jsfiddle.net/fydC4/14