I got 2 main div that i'm trying to make appear on the same line. I'm struggling with the CSS to get what I want.
First div is a kind of menu, displaying categories. I can have more or less of them (should be dynamic). Second div is displaying main buttons/shortcuts and is static.
Goal:
both div on same line
second div (button-container) taking 25% of the page on the right
first div (category-container) taking whatever is left, on the left of the page. Overflow hidden, size of each indivual cells will be adjusted with javascript so everything can fit.
section.home {
white-space: nowrap;
}
section.home > div.category-container {
width: 75%;
overflow: hidden;
display: inline;
}
section.home > div.buttons-container {
width: 25%;
height: 300px;
display: inline-block;
background-color: #EEEEEE;
}
section.home > div.category-container > ul > li {
padding-right: 15px;
padding-left: 15px;
padding-bottom: 15px;
display: inline-block;
}
div.category {
width: 200px;
height: 300px;
text-align: center;
box-shadow: 0 3px 5px #aaa;
background: White none repeat scroll 0 0;
border: 1px solid #ccc;
overflow: hidden;
}
div.category > div.category-title {
padding: 5px;
background-color: #EEEEEE;
color: rgb(254, 107, 3);
font-weight: bold;
}
div.category > a > img {
width: 200px;
}
div.category_content {
padding-top: 10px;
padding-bottom: 10px;
}
<section class="home">
<div class="category-container">
<ul>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 1</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 2</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 3</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
</ul>
</div>
<div class="buttons-container">
Buttons container
</div>
</section>
By adding float: left; to the .category-container you are able to format the div's side-by-side.
section.home>div.category-container {
width: 75%;
overflow: hidden;
display: inline;
float: left; /* Float left is what you need */
}
I've updated your HTML & CSS with this edit:
section.home {
white-space: nowrap;
}
section.home > div.category-container {
width: 75%;
overflow: hidden;
display: inline;
float: left;
}
section.home > div.buttons-container {
width: 25%;
height: 300px;
display: inline-block;
background-color: #EEEEEE;
}
section.home > div.category-container > ul > li {
padding-right: 15px;
padding-left: 15px;
padding-bottom: 15px;
display: inline-block;
}
div.category {
width: 200px;
height: 300px;
text-align: center;
box-shadow: 0 3px 5px #aaa;
background: White none repeat scroll 0 0;
border: 1px solid #ccc;
overflow: hidden;
}
div.category > div.category-title {
padding: 5px;
background-color: #EEEEEE;
color: rgb(254, 107, 3);
font-weight: bold;
}
div.category > a > img {
width: 200px;
}
div.category_content {
padding-top: 10px;
padding-bottom: 10px;
}
<section class="home">
<div class="category-container">
<ul>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 1</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 2</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 3</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
</ul>
</div>
<div class="buttons-container">
Buttons container
</div>
</section>
The problem is your ul, setting it to inline-block does the trick.
It crashed for small windows, because .category has a fixed width.
section.home > div.category-container UL {
display: inline-block;
}
section.home {
white-space:nowrap;
}
section.home > div.category-container {
width:70%;
overflow:hidden;
display:inline;
}
section.home > div.category-container UL {
display: inline-block;
}
section.home > div.buttons-container {
width:25%;
height:300px;
display:inline;
background-color:#EEEEEE;
}
section.home > div.category-container > ul > li {
padding-right:15px;
padding-left:15px;
padding-bottom:15px;
display:inline-block;
}
div.category {
width:200px;
height:300px;
text-align:center;
box-shadow:0 3px 5px #aaa;
background:White none repeat scroll 0 0;
border:1px solid #ccc;
overflow:hidden;
}
div.category > div.category-title {
padding:5px;
background-color:#EEEEEE;
color:rgb(254,107,3);
font-weight:bold;
}
div.category > a > img {
width:200px;
}
div.category_content {
padding-top:10px;
padding-bottom:10px;
}
<section class="home">
<div class="category-container">
<ul>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 1</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1<br/>
subcategory2<br/>
subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 2</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1<br/>
subcategory2<br/>
subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 3</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1<br/>
subcategory2<br/>
subcategory 3
</div>
</div>
</li>
</ul>
</div>
<div class="buttons-container">
Buttons container
</div>
</section>
Related
I have a list of movies.
When you hover a movie, it is gonna appear a border around the movie, that is ok, but at the exact time, if you hover a movie is like you are feeling that you adding extra padding to the 'top' and 'bottom' and make the div.item moving
How can I fix this?
Click on the 'full page' on the snippet code to see exactly what I mean.
#import url(https://fonts.googleapis.com/css2?family=Cairo:wght#200;300;400;600;700;900&display=swap);
#import url(https://fonts.googleapis.com/css2?family=Signika:wght#300&display=swap);
#import url(https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap);
:root {
--main-color: #4D6275;
--second-color: #3F5060;
--body-bg: #2E3841;
--box-bg: #272F37;
--text-color: #D5D5D5;
--grey-color: #B2B2B2;
--simple-color: #C3C3C3;
--content-height: 92px;
--space-top: 30px;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: var(--body-bg);
color: var(--text-color);
}
a {
text-decoration: none !important;
}
button:focus {
outline: none;
}
.wrapper {
position: relative;
width: auto;
height: 100vh;
padding: 15px;
font-size: 1.1em;
top: 0;
}
.content-wrapper {
margin-top: 110px;
margin-bottom: 30px;
margin-left: 170px;
}
.header-menu {
display: flex;
/*align-items: flex-start;*/
/*justify-content: left;*/
font-size: 18px;
}
.header-item ~ .header-item {
margin-left: 100px;
}
li.active {
border-bottom: 2.5px solid #E3AA1E;
}
li.active a {
color: #E2E2E2;
}
.header-item a {
color: #9f9f9f;
}
.content-wrapper li {
list-style-type: none;
}
.list-menu {
display: flex;
flex-wrap: wrap;
}
.item {
width: auto;
margin-top: 20px;
margin-bottom: 10px;
margin-right: 40px;
background-color: var(--body-bg);
border-radius: 5px;
border: 25px solid var(--body-bg);
}
.item:hover {
background-color: #36414B;
border-color: #36414B;
border-radius: 15px;
box-shadow: 0 10px 16px 0 rgb(0 0 0 / 20%), 0 6px 20px 0 rgb(0 0 0 / 19%);
}
.item a {
color: unset;
}
.item img {
width: 250px;
height: 380px;
}
.item-name {
font-weight: 500;
font-size: 14px;
white-space: normal;
width: 85%;
margin-top: 5px;
}
.item-time {
margin-top: 3px;
color: #9F9F9F;
font-size: 13px;
font-weight: 500;
}
.label {
display: inline;
padding: .2em .5em .25em;
font-size: 70%;
font-weight: 700;
line-height: 1;
color: #ccc;
background-color: var(--box-bg);
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: .30em;
}
.label-yellow {
background-color: #008080;
}
.item-description {
display: none;
}
.item:hover .item-description {
display: block;
}
<div class="wrapper">
<div class="content-wrapper">
<div class="content-header">
<ul class="header-menu">
<li class="header-item">Popular</li>
<li class="header-item active">New Releases</li>
<li class="header-item">Recently Added</li>
<li class="header-item">Recommanded</li>
</ul>
</div>
<div class="list-menu">
<div class="item">
<a href="#">
<img src="https://wallpapercave.com/wp/wp7248999.jpg" alt="">
<div class="item-name">Batman</div>
<div class="item-time">1 hr 43 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src="https://i.pinimg.com/originals/fb/ff/84/fbff84ea4b51cf1524c2a95fdac2183e.jpg" alt="">
<div class="item-name">The Flash</div>
<div class="item-time">2 hr 53 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src=https://m.media-amazon.com/images/M/MV5BYWQyZGQwMzktMjFhYS00MmZmLWI3ZDEtNzg3MzRmM2ZjMDc1XkEyXkFqcGdeQXVyODY5NzkyMjA#._V1_.jpg" alt="">
<div class="item-name">Scooby-Doo: The Sowrd and The Scoob</div>
<div class="item-time">1 hr 25 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src="https://m.media-amazon.com/images/M/MV5BZWRhMzdhMzEtZTViNy00YWYyLTgxZmUtMTMwMWM0NTEyMjk3XkEyXkFqcGdeQXVyNTIzOTk5ODM#._V1_.jpg" alt="">
<div class="item-name">X-MEN: Wolverine</div>
<div class="item-time">2 hr 46 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src=https://m.media-amazon.com/images/M/MV5BYWQyZGQwMzktMjFhYS00MmZmLWI3ZDEtNzg3MzRmM2ZjMDc1XkEyXkFqcGdeQXVyODY5NzkyMjA#._V1_.jpg" alt="">
<div class="item-name">Scooby-Doo: The Sowrd and The Scoob</div>
<div class="item-time">1 hr 25 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src="https://m.media-amazon.com/images/M/MV5BZWRhMzdhMzEtZTViNy00YWYyLTgxZmUtMTMwMWM0NTEyMjk3XkEyXkFqcGdeQXVyNTIzOTk5ODM#._V1_.jpg" alt="">
<div class="item-name">X-MEN: Wolverine</div>
<div class="item-time">2 hr 46 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src=https://m.media-amazon.com/images/M/MV5BYWQyZGQwMzktMjFhYS00MmZmLWI3ZDEtNzg3MzRmM2ZjMDc1XkEyXkFqcGdeQXVyODY5NzkyMjA#._V1_.jpg" alt="">
<div class="item-name">Scooby-Doo: The Sowrd and The Scoob</div>
<div class="item-time">1 hr 25 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
<div class="item">
<a href="#">
<img src="https://m.media-amazon.com/images/M/MV5BZWRhMzdhMzEtZTViNy00YWYyLTgxZmUtMTMwMWM0NTEyMjk3XkEyXkFqcGdeQXVyNTIzOTk5ODM#._V1_.jpg" alt="">
<div class="item-name">X-MEN: Wolverine</div>
<div class="item-time">2 hr 46 min</div>
<div class="item-description">
<span class="label label-yellow">2021</span>
<span class="label">Action</span>
<span class="label">Justice</span>
<span class="label">Hero</span>
</div>
</a>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
That's due to
.item-description {
display: none;
}
.item:hover .item-description {
display: block;
}
Hiding using display removes the item from the layout. Use visibility instead and elements will always occupy space. If this increases the height of the card, you may adjust margin around the card.
That's because you are showing extra content "tags" in the div when hovering, this will increase the block height, therefore, it will push the below items down.
Try using visibility instead of display for that sub section:
.item-description {
visibility: hidden;
}
.item:hover .item-description {
visibility: visible;
}
So I've been trying to make my sidebar smaller so that I can make the article bigger, but when I did so it seemed to have displaced everything in the sidebar but I really don't see how. I'm relatively new to html and css so I'm not as experienced and would be really happy if someone could help.
Heres my code:
body {
margin: 0;
background: #fff;
font-family: wayward;
font-weight: 100;
height: 100%;
overflow-x: hidden;
overflow-y: scroll;
display: flex;
flex-wrap: wrap;
padding-top:110px;
max-width: 1600px; margin: auto
}h1 {
margin: 10px;
}
img {
max-width: 100%;
}
.review {
line-height: 29.25px;
padding-top: 5px;
text-align: center;
border-width: 1px;
margin: 10px;
padding: 5px;
word-wrap: break-word;
flex: 1;
}
.text-wrapper{
max-width:800px;
margin:auto;
}
aside .articles{
list-style-type: none;
padding: 0px;
margin-top:0px;
border-top:3px solid;
}
.articles > li.card{
border-left: 1px solid #55d6aa;
border-right: 1px solid #55d6aa;
border-bottom: 1px solid #55d6aa;
}
.articles h3, .articles p {
margin-top: 0px;
}
.articles .content_col{
margin-left: 10px;
}
.image_col{
width:180px;
height:180px;
}
.card{
height:150px;
}
.card-link{
/* remove deafult link color + underline */
color: #55d6aa;
text-decoration: none;
/* change a display from deafult inline to block (all card area is clickbale) */
display: block;
/* transition */
transition: background-color 0.5s ease;
/* flex setting */
display: flex;
align-items: center;
/* extra padding around the card */
padding: 10px;
}
.card-link:hover{
background: #f3f3f3;
}
button {
color: #55d6aa;
background: transparent;
border-width: 2px;
border-style: solid;
border-color: #55d6aa;
position: relative;
margin: 0px;
display: inline-block;
padding: 0.5em 1em;
transition: all 0.3s ease-in-out;
text-align: center;
font-weight: bold;
}
button:before,
button:after {
content: "";
display: block;
position: absolute;
border-color: #55d6aa;
box-sizing: border-box;
border-style: solid;
width: 1em;
height: 1em;
transition: all 0.3s ease-in-out;
}
button:before {
top: -6px;
left: -6px;
border-width: 2px 0 0 2px;
z-index: 5;
}
button:after {
bottom: -6px;
right: -6px;
border-width: 0 2px 2px 0;
}
button {
color: #55d6aa;
border-color: #55d6aa;
}
button:before,
button:after {
border-color: #55d6aa;
}
button:hover:before,
button:hover:after {
width: calc(100% + 12px);
height: calc(100% + 12px);
border-color: #55d6aa;
transform: rotateY(180deg);
}
button:hover {
color: #55d6aa;
background-color: transparent;
border-color: #55d6aa;
}
<aside>
<h2 style="padding:13px;">Most Popular Posts</h2>
<ul class="articles">
<!-- card 1 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/300" />
</div>
<div class="content_col">
<h3>Features</h3>
<p>Responsive Buttons!</p>
<button>Hover me</button>
</div>
</a>
</li>
<!-- card 2 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/301" />
</div>
<div class="content_col">
<h3>Auto NavBar</h3>
<p>Try scrolling up and down!</p>
<button>Read more</button>
</div>
</a>
</li>
<!-- card 3 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/302" />
</div>
<div class="content_col">
<h3>Article heading</h3>
<p>Short description</p>
<button>Read more</button>
</div>
</a>
</li>
<!-- card 4 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/303" />
</div>
<div class="content_col">
<h3>Article heading</h3>
<p>Short description</p>
<button>Read more</button>
</div>
</a>
</li> <!-- card 5 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/304" />
</div>
<div class="content_col">
<h3>Article heading</h3>
<p>Short description</p>
<button>Read more</button>
</div>
</a>
</li> <!-- card 6 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/305" />
</div>
<div class="content_col">
<h3>Article heading</h3>
<p>Short description</p>
<button>Read more</button>
</div>
</a>
</li>
<!-- card 7 -->
<li class="card">
<a href="#" class="card-link">
<div class="image_col">
<img src="https://picsum.photos/400/306" />
</div>
<div class="content_col">
<h3>Article heading</h3>
<p>Short description</p>
<button>Read more</button>
</div>
</a>
</li>
</ul>
</aside>
<div class="review">
<h1>Titanic Movie Review 1996</h1>
<h3>-By Some random guy</h3>
<div class = "thumbnail">
<img src="https://static3.srcdn.com/wordpress/wp-content/uploads/2020/01/Rose-DeWitt-Bukater-and-Jack.png?q=50&fit=crop&w=767&h=450&dpr=1.5" alt="An Image of Jack holding rose from behind">
</div>
<div class = "text-wrapper">
<p>
paragraph here
</p>
</div>
</div>
Hi Just make a small change in your css
.image_col {
width: 180px;
height: auto;}
.card {
height: auto;}
While I hover Div tag, Another Div tag will appear in front of the prev Div. When i didn't put any words, it works. but when i put h3 tag, the div goes down.
here is the HTML
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<a href="#">
<div class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
</div>
here is CSS
#content{
width:50%;
}
.line{
border-top: 5px solid black;
}
.list-content{
display:inline-block;
width:25%;
height:200px;
background-color: black;
margin-top: 10px;
}
.detail-content{
display: none;
}
.list-content:hover .detail-content{
display: block;
width:100%;
height:75%;
background-color: rgba(255,255,255,0.6);
}
thank you before
Update below css part
.list-content:hover .detail-content {
display: table;
width: 100%;
height: 75%;
background-color: rgba(255, 255, 255, 0.6);
}
#content {
width: 50%;
}
.line {
border-top: 5px solid black;
}
.list-content {
display: inline-block;
width: 25%;
height: 200px;
background-color: black;
margin-top: 10px;
}
.detail-content {
display: none;
}
.list-content:hover .detail-content {
display: table;
width: 100%;
height: 75%;
background-color: rgba(255, 255, 255, 0.6);
}
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<a href="#">
<div class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
</div>
#James Please find following code. I hope you are expecting the same. Just replaced "display:inline-block;" with "float:left;" and took class "list-content" in anchor tag itself.
#content{
width:50%;
}
.line{
border-top: 5px solid black;
}
.list-content{
float:left;
width:25%;
height:200px;
background-color: black;
margin-top: 10px;
margin-right:10px;
}
.detail-content{
display: none;
}
.list-content:hover .detail-content{
display: block;
width:100%;
height:75%;
background-color: rgba(255,255,255,0.6);
}
.clearfix{
clear:both;
}
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<div class="clearfix">
<a href="#" class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</a>
<a href="#" class="list-content">
<div class="detail-content">
</div>
</a>
<a href="#" class="list-content">
<div class="detail-content">
</div>
</a>
</div>
</div>
Because the .list-content items are inline blocks, when you add a text content you have to vertically align them. Add vertical-align: top to .list-content:
.list-content {
display: inline-block;
width: 25%;
height: 200px;
background-color: black;
margin-top: 10px;
vertical-align: top;
}
And remove the top margin from :
h3 {
margin-top: 0;
}
{
width: 50%;
}
.line {
border-top: 5px solid black;
}
.list-content {
display: inline-block;
width: 25%;
height: 200px;
background-color: black;
margin-top: 10px;
vertical-align: top;
}
.detail-content {
display: none;
width: 100%;
height: 75%;
background-color: rgba(255, 255, 255, 0.6);
}
.list-content:hover .detail-content {
display: block;
}
h3 {
margin-top: 0;
}
<div id="content">
<h1 class="head-content">Biscuits</h1>
<div class="line"></div>
<a href="#">
<div class="list-content">
<div class="detail-content">
<h3>Biscuits 1</h3>
<p>Price: IDR 12000</p>
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
<a href="#">
<div class="list-content">
<div class="detail-content">
</div>
</div>
</a>
</div>
I got these elements display on a inline-block, specific width etc.
Preview: https://s13.postimg.org/hk700r45z/solvthis.png
But, when more than one line is displayed, they get disalineadas.
.shop_container,
.list_container {
display: block;
}
.list_container {
max-width: 1170px
}
.element_container,
list_container,
element {
box-sizing: border-box;
}
.element_container {
display: inline;
font-size: 13pt;
line-height: 1.5em;
...
}
.element {
width: 40%;
margin: 25px 2.5%;
height: 100px;
border: 1px solid {
colour
}
;
padding-top:38px;
line-height:17px;
font-size:14px;
display:inline-block;
position:relative;
}
.element > span {
font-size: 14px;
}
<div class="shop_container">
<div class="list_container">
<!-- Element 1 -->
<div class="element_container">
<a href="#" class="element">
<span>Element1</span>
</a>
</div>
<!-- Element 2 -->
<div class="element_container">
<a href="#" class="element">
<span>Element2</span>
</a>
</div>
<!-- Element 3 -->
<div class="element_container">
<a href="#" class="element">
<span>Element3</span>
</a>
</div>
<!-- Long list elements -->
</div>
</div>
Would you know where is the problem? I think that is in the fixed padding-top added to element, but I don't know how to fix it.
You can do it like below:-
.shop_container, .list_container { display: block; }
.list_container { max-width: 1170px }
.element_container, list_container, element { box-sizing: border-box; }
.element {
width: 40%;
margin: 25px 2.5%;
height: 100px;
border: 1px solid {colour};
padding-top: 38px;
line-height: 17px;
font-size: 14px;
display: inline-block;
position: relative;
word-break:break-all;
}
.element_container {
display: inline;
float: left;
font-size: 13pt;
line-height: 1.5em;
width: 50%;
}
.element > span { font-size: 14px; }
<div class="shop_container">
<div class="list_container">
<!-- Element 1 -->
<div class="element_container">
<a href="#" class="element">
<span>Element1</span>
</a>
</div>
<!-- Element 2 -->
<div class="element_container">
<a href="#" class="element">
<span>Element2</span>
</a>
</div>
<!-- Element 3 -->
<div class="element_container">
<a href="#" class="element">
<span>Element3
hello again
we meet here
you have a problem
i solved it
thanks
</span>
</a>
</div>
<div class="element_container">
<a href="#" class="element">
<span>Element4</span>
</a>
</div>
<!-- Long list elements -->
</div>
</div>
A bit more good:-
.shop_container, .list_container { display: block; }
.list_container { max-width: 1170px }
.element_container, list_container, element { box-sizing: border-box; }
.element {
width: 40%;
margin: 25px 2.5%;
height: 100px;
border: 1px solid {colour};
padding-top: 38px;
line-height: 17px;
font-size: 14px;
display: inline-block;
position: relative;
word-break:break-all;
}
.element_container {
display: inline;
float: left;
font-size: 13pt;
line-height: 1.5em;
width: 50%;
}
.element > span {
float: left;
font-size: 14px;
margin-top: 10px;
width: 100%;
}
<div class="shop_container">
<div class="list_container">
<!-- Element 1 -->
<div class="element_container">
<a href="#" class="element">
<span>Element1</span>
</a>
</div>
<!-- Element 2 -->
<div class="element_container">
<a href="#" class="element">
<span>Element2</span>
</a>
</div>
<!-- Element 3 -->
<div class="element_container">
<a href="#" class="element">
<span>Element3</span>
<span>hello again
we meet here
you have a problem
i solved it
thanks
</span>
</a>
</div>
<div class="element_container">
<a href="#" class="element">
<span>Element4</span>
</a>
</div>
<!-- Long list elements -->
</div>
</div>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
<style>
#metro {
width: 100%
height: auto;
font-size: 16px;
}
#metro .metro_half_row {
width: 50%;
float: left;
height: 100px;
color: white;
background-color: grey;
}
#metro .metro_half_row a {
display: block;
height: inherit;
text-align: center;
}
</style>
<div id="metro">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
I've wrapper as #metro, .metro_half_row as each section, using a display: block
Right now the text in <a> is centered horizontally, but not vertically. I need to center the text contained in the links, and each <a> covering the entire sub div block both horizontally and vertically.
display: table and display: table-cell are your friends.
#metro {
width: 100%;
height: auto;
font-size: 16px;
}
#metro .table-block {
width: 100%;
display: table;
}
#metro .table-cell {
width: 50%;
display: table-cell;
vertical-align: middle;
}
#metro .metro_half_row {
width: 100%;
height: 100px;
color: white;
background-color: grey;
display: table;
}
#metro .metro_half_row a {
width: 100%;
display: table-cell;
height: inherit;
text-align: center;
vertical-align: middle;
}
<link href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css" rel="stylesheet" />
<div id="metro">
<div class="table-block">
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
</div>
<div class="table-block">
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
</div>
</div>
If i understand your problem correctly in your case, the CSS may look like this:
a{
margin-top:25px;
}
or
a{
position: relative;
top: 25%;
}
Try:
#metro .metro_half_row a {
display: table-cell;
width: inherit;
vertical-align: middle;
height: inherit;
text-align: center;
}
#metro .metro_half_row {
display: table;
}
view http://jsfiddle.net/alemarch/589pqd62/