I have this setup of my elements http://codepen.io/Py89/pen/QbKgWv?editors=110
HTML:
<div class="container">
<div class="item-container" id="right-block">
<div class="row">
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
</div>
<!-- #Row -->
<div class="row">
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
</div>
<!-- #Row -->
</div>
<!-- #Item container -->
<div class="item-container" id="left-block">
<div class="row">
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
<h3>More text</h3>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
<h3>More text</h3>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
<h3>More text</h3>
</div>
</div>
<!-- #Item -->
</div>
<!-- #Row -->
<div class="row">
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
<div class="media">
<div class="media__item">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
<div class="media__body">
<h2>Some text</h2>
</div>
</div>
<!-- #Item -->
</div>
<!-- #Row -->
</div>
<!-- #Item container -->
</div>
CSS:
.container {
*zoom: 1;
}
.container:before, .container:after {
content: "";
display: table;
}
.container:after {
clear: both;
}
.container {
width: 80%;
margin: 20px auto;
background: rgba(100, 100, 100, 0.4);
}
.item-container {
float: right;
width: 50%;
}
.media {
background: rgba(30, 40, 50, 0.4);
float: right;
overflow: hidden;
margin: 0 10px 50px;
padding: 10px;
}
.media .media__item {
width: 100%;
}
.media .media__item img {
margin: 0 auto;
}
.media .media__body {
width: 100%;
padding-top: 10px;
overflow: hidden;
}
h2 {
margin: 0 0 10px;
text-align: center;
}
h3 {
margin: 0;
text-align: center;
}
#left-block {
background: rgba(200, 10, 50, 0.3);
}
#right-block {
background: rgba(50, 200, 100, 0.3);
}
Is it at all possible for the divs in the second row of the right to get pushed down the same amount as the divs on the left ?
I know it can be done with jQUery / JavaScript, but i'm interested if it can be done, purely by CSS.
Keep in mind that I cannot change the base HTML markup.
In this case , the easiest way is to give a height to container.
.media {
background: rgba(30, 40, 50, 0.4);
float: right;
overflow: hidden;
margin: 0 10px 50px;
padding: 10px;
height:420px;//add this
}
//could also place it on '.media .media__body'
http://codepen.io/maio/pen/PqGjam
There are two angles here, regarding the type of content on the page:
Dynamic content:
With the provided html layout, you can't obtain
the desired result. That's because u have two different container
nodes with (presumably) dynamic content, and no way to link them in
css.
Static content:
As maioman said, you can easily set a height to the
container, but i recommend setting to the row class.
Or, you can add:
<h3><br></h3>
to the divs where there is only one line of text. Additional break would be rendered as two lines of text below the pics so the heights would match each other exactly. Like this:
THIS IS YOUR DIVS WITH TWO LINES OF TEXT:
<h2>Some text</h2>
<h3>More text</h3>
AND FOR THE DIVS WITH ONE LINE OF TEXT ADD THIS:
<h2>Some text</h2>
<h3><br></h3>
I hope it helps....
Related
I want to set all the images in center and five image in first row and rest of the images in second row in center. I tried the following code.
<section id="Section">
<h1 class="sectionTitle text-center">Images</h1>
<div class="row center" id="Logo">
<!-- All logo from firestore -->
</div>
</section>
I am using firestore here is my JavaScript code:
db.collection('images').orderBy('image').onSnapshot((snapshot) => {
//insertHtml("#main-content", response);
snapshot.docs.forEach(doc => {
var brand = '<div class="column">'
+ '<img src="images/'+ doc.data().image + '"></div>';
$("#Logo").append(brand);
});
});
here is my css code:
#Section .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 80%;
}
#Section .row .column {
float: left;
width: 20%;
}
#Section .row .column img{
max-height: 115px;
max-width: 210px;
}
There are 8/9 images, so first row works well, but 2nd row is not in center. I want to fix it. How can I do it ?
Use display flex and change the flex-basis to 100/number of elements like so :
#Section .center {
display: flex;
margin-left: auto;
margin-right: auto;
justify-content : center;
align-items : center;
flex-wrap : wrap;
column-gap : 15px;
row-gap : 15px;
width: 80%;
}
.logos {
text-align : center;
flex-basis : calc(20% - 15px);
background-color : red;
]
<section id="Section">
<h1 class="sectionTitle text-center">Images</h1>
<div class="row center" id="Logo">
<div class="logos"> 1 </div>
<div class="logos"> 2 </div>
<div class="logos"> 3 </div>
<div class="logos"> 4 </div>
<div class="logos"> 5 </div>
<div class="logos"> 6 </div>
<div class="logos"> 7 </div>
<div class="logos"> 8 </div>
<div class="logos"> 9 </div>
</div>
</section>
You can use
For the alignment of all elements horizontally
<div class="row justify-content-center" id="Logo">
<div class="col-md-*"> 1 logo </div>
<div class="col-md-*"> 2 logo </div>
<div class="col-md-*"> 3 logo </div>
<div class="col-md-*"> 4 logo </div>
<div class="col-md-*"> 5 logo </div>
</div>
<div class="row justify-content-center" id="Logo">
<div class="col-md-4"> 1 logo </div>
<div class="col-md-4"> 2 logo </div>
<div class="col-md-4"> 3 logo </div>
</div>
Is this what you need?
[example
.container {
display: flex;
flex: 1;
flex-wrap: wrap;
}
.item {
width: 200px;
height: 50px;
background: pink;
margin: 20px;
display: flex;
justify-content: center;
}
img {
width: 40px;
background: teal;
}
<div class="container">
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
<div class="item">
<img src="" alt="1" />
</div>
</div>
Expected output image illustration:
html, body
{
max-width: 100vw;
max-height: 100vh;
}
html *
{
font-family: Arial !important;
}
.cand1
{
width: 50%;
float:left;
}
.cand2
{
width:50%;
float: right;
}
.prof1,.prof2
{
margin:0;
margin-top: 40;
text-align: center;
}
.name
{
font-weight: bold;
}
.post
{
font-weight: bolder;
}
.card
{
background: rgb(230, 230, 230);
}
h4
{
background: rgb(230, 230, 230);
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/style_vote.css">
</head>
<body>
<div id="header"></div>
<div id="wrapper">
<div id="content">
<div class="card">
<h4 class="post">Post 1</h4>
<div class="cand1">
<div class="prof1">
<img src="images/dummy1.jpg">
<p class="name">Candidate 1</p>
<p class="add">Class</p>
</div>
</div>
<div class="cand2">
<div class="prof2">
<img src="images/dummy1.jpg">
<p class="name">Candidate 2</p>
<p class="add">Class</p>
</div>
</div>
</div>
<div class="card">
<h4 class="post">Post 2</h4>
<div class="cand1">
<div class="prof1">
<img src="images/dummy1.jpg">
<p class="name">Candidate 3</p>
<p class="add">Class</p>
</div>
</div>
<div class="cand2">
<div class="prof2">
<img src="images/dummy1.jpg">
<p class="name">Candidate 4</p>
<p class="add">Class</p>
</div>
</div>
</div>
<div class="card">
<h4 class="post">Post 3</h4>
<div class="cand1">
<div class="prof1">
<img src="images/dummy1.jpg">
<p class="name">Candidate 5</p>
<p class="add">Class</p>
</div>
</div>
<div class="cand2">
<div class="prof2">
<img src="images/dummy1.jpg">
<p class="name">Candidate 6</p>
<p class="add">Class</p>
</div>
</div>
</div>
<div class="card">
<h4 class="post">Post 4</h4>
<div class="cand1">
<div class="prof1">
<img src="images/dummy1.jpg">
<p class="name">Candidate 7</p>
<p class="add">Class</p>
</div>
</div>
<div class="cand2">
<div class="prof2">
<img src="images/dummy1.jpg">
<p class="name">Candidate 8</p>
<p class="add">Class</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Current output image:
I am trying to implement a card like style with html and css.
the h4 tag in the div card produces spaces ,on using margin 0 and padding 0 in css it produces a white line ,I also couldn't find to split each card,tried margin as well as padding attributes for the card div,doesn't seem to work.
also the attributes i apply on the entire card div doesn't seem to apply on the h4 tag, modifying other attributes such as height on the card div makes the dummy image pop out of the card div section
Since your code is pretty messy i created a simple example for you. Hope it helps.
Also try to avoid !important to keep your code clean and maintainable.
section {
background: gray;
padding: 10px 25px;
margin: 0 0 25px 0;
}
section h4 {
margin: 0 0 10px 0;
}
.card-wrapper {
display: flex;
justify-content: space-around;
}
.card--text {
text-align: center;
}
<div class="container">
<section>
<h4>Post</h4>
<div class="card-wrapper">
<div class="card">
<img src="https://dummyimage.com/150x150/000/fff" />
<p class="card--text">
I am the Text
</p>
</div>
<div class="card">
<img src="https://dummyimage.com/150x150/000/fff" />
<p class="card--text">
I am the Text
</p>
</div>
</div>
</section>
<section>
<h4>Post</h4>
<div class="card-wrapper">
<div class="card">
<img src="https://dummyimage.com/150x150/000/fff" />
<p class="card--text">
I am the Text
</p>
</div>
<div class="card">
<img src="https://dummyimage.com/150x150/000/fff" />
<p class="card--text">
I am the Text
</p>
</div>
</div>
</section>
</div>
I want text on right and image on left and vice-versa with vertically centered both.
It should look like as follows
Image
Structure
<section>
<div class="columns">
<div class="column is-7">
<!-- Image -->
</div>
<div class="column is-5">
<!-- My hero -->
</div>
</div>
</section>
<section>
<div class="columns">
<div class="column is-5">
<!-- My hero -->
</div>
<div class="column is-7">
<!-- Image -->
</div>
</div>
</section>
In total
(Change CSS according to your needs)
.myBg {
background-color: #273238;
color: white;
border: 1px solid white;
}
.myHero .hr {
display: inline-block;
width: 100px;
height: 15px;
background: white;
border-radius: 20px;
margin-bottom: 15px;
}
.myHero h1 {
font-size: 50px
}
.myHero.hero-right {
padding-right: 100px;
text-align: right;
}
.myHero.hero-left {
padding-left: 100px;
}
#media(max-width: 768px) {
.myHero {
padding: 100px 50px !important;
//text-align: left !important;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.1/css/bulma.min.css">
<section class="myBg">
<div class="columns is-vcentered">
<div class="column is-7">
<figure class="image is-4by3">
<img src="https://i.stack.imgur.com/WpMdM.png" alt="">
</figure>
</div>
<div class="column is-5">
<div class="myHero hero-right">
<div class="hr"></div>
<h1>BOOST</h1>
<ul>
<li>This is the cooles thing.</li>
<li>I am gonna do in my entire life. Awesome!</li>
<li>Achievements are good as heaven. I want it soon.</li>
</ul>
</div>
</div>
</div>
</section>
<section class="myBg">
<div class="columns is-vcentered">
<div class="column is-5">
<div class="myHero hero-left">
<div class="hr"></div>
<h1>BOOST</h1>
<ul>
<li>This is the cooles thing.</li>
<li>I am gonna do in my entire life. Awesome!</li>
<li>Achievements are good as heaven. I want it soon.</li>
</ul>
</div>
</div>
<div class="column is-7">
<figure class="image is-4by3">
<img src="https://i.stack.imgur.com/WpMdM.png" alt="">
</figure>
</div>
</div>
</section>
I have dynamic div boxes created in a website, I want to have 4 boxes in each row using bootstrap, that's working, but each box has some text at the bottom, the problem is that when the text is too long and it creates a new line, the div expands but the box underneath this div moves to the right, instead of moving all the row underneath down.
This is the html:
<div class="row">
<div ng-repeat=""class="col-sm-3 album-art"> //loop to create the boxes
<div class="thumb">
<div class="box">
<span class="play" ng-click="">►</span>
<div class="overlay"></div>
</div>
<img src= height="200" width="200">
<p>text</p>
<p><i>text</i></p>
</div>
</div>
And this is the css I have:
.album-art{
padding-bottom: 20px;
padding-top: 20px;
margin-bottom: 10px;
}
.thumb {
position: relative;
}
.thumb .box {
position: absolute;
top: 0;
display: block;
width: 200px;
height: 200px;
text-align: center;
text-decoration: none;
cursor: pointer;
}
Basically what I'd need is that when the text overflows and creates a new line, the row below the current row moves down and not move every element to the right.The problem seems to be in the "album-art" class, since I removed all the other classes and the problem still there.
thanks
EDIT: I've added images for a better explanation
This is when everything is normal
But when the text is longer
EDIT2: I put an example here: jsfiddle.net/qgo7a701 you might have to expand the result area to the left in order to see 4 squares per row
I don't understand you question very well , but in bootstrap the row divided to 12 cell, and you can define divs in row with different sizes.and you can use col-[xl,lg,md,sm,xs]-[1 to 12] classes for that. you can look to this link :
http://getbootstrap.com/examples/grid/
for you example below i have tried to make two row with two boxes and i only break the text to prevent it to overflow to next div
.album-art{
padding-bottom: 20px;
padding-top: 20px;
margin-bottom: 10px;
}
p{
word-break: break-all;
}
.thumb {
position: relative;
}
.thumb .box {
position: absolute;
top: 0;
display: block;
width: 200px;
height: 200px;
text-align: center;
text-decoration: none;
cursor: pointer;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="row">
<div ng-repeat=""class="col-sm-3 album-art">
//loop to create the boxes
<div class="thumb">
<div class="box">
<span class="play" ng-click="">►</span>
<div class="overlay">
</div>
</div>
<img src= height="200" width="200"/>
<p style="">text helooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</p>
<p><i>text</i></p>
</div>
</div>
<div ng-repeat=""class="col-sm-3 album-art">
//loop to create the boxes
<div class="thumb">
<div class="box">
<span class="play" ng-click="">►</span>
<div class="overlay">
</div>
</div>
<img src= height="200" width="200"/>
<p style="">text heloooooooooooooooooooooooooooooooooooooooooo</p>
<p><i>text fffffffffffffffffffffffffffffffffffffffffffffffddddddddddddddsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssdddddddddddddddddddddddddddddddddddd fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</i></p>
</div>
</div>
</div>
<div class="row">
<div ng-repeat=""class="col-sm-3 album-art">
//loop to create the boxes
<div class="thumb">
<div class="box">
<span class="play" ng-click="">►</span>
<div class="overlay">
</div>
</div>
<img src= height="200" width="200"/>
<p style="">text helooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</p>
<p><i>text</i></p>
</div>
</div>
<div ng-repeat=""class="col-sm-3 album-art">
//loop to create the boxes
<div class="thumb">
<div class="box">
<span class="play" ng-click="">►</span>
<div class="overlay">
</div>
</div>
<img src= height="200" width="200"/>
<p style="">text helooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</p>
<p><i>text</i></p>
</div>
</div>
</div>
I tested what you did and it was working as intended. You used 1 row for the complete collection of cols, so they behaved as intended. To change that, you must force a grouping of cols and you can do it like this:
(Resume here:
- Add div class="col-sm-12" style="display: table" and close it after 4 of your "col-sm-3 divs". Add another one for the rest of the "col-sm-3 divs". Everything should be inside the div class="row". (I would have used two rows every 4 "col-sm-3 divs" but, is your code).
- Change the "style" into a css, include it in your stylesheet, add the class to the div. End.
.album-art {
padding-bottom: 20px;
padding-top: 20px;
margin-bottom: 10px;
}
.thumb {
position: relative;
}
.thumb .box {
position: absolute;
top: 0;
display: block;
width: 200px;
height: 200px;
text-align: center;
text-decoration: none;
cursor: pointer;
}
<!DOCTYPE html>
<html>
<head>
<title>Untitled Document</title>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" type="text/css" rel="stylesheet">
<style>
.album-art {
padding-bottom: 20px;
padding-top: 20px;
margin-bottom: 10px;
}
.thumb {
position: relative;
}
.thumb .box {
position: absolute;
top: 0;
display: block;
width: 200px;
height: 200px;
text-align: center;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<div class="row">
<div class="col-sm-12" style="display: table;">
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">tedddddddxxxx ewhuiofhew hfiuhiufw shidfshksdhxfffffffffffffxxxxxddddddxt</p>
</div>
</div>
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
</div>
<div class="col-sm-12" style="display: table;">
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
<div class="col-sm-3" style="padding-bottom: 20px; padding-top: 20px">
<div class="thumb">
<div class="box">
<span class="play"></span>
<div class="overlay"></div>
</div>
<img src="#" height="50" width="50" />
<p style="color: black">text</p>
</div>
</div>
</div>
</div>
</body>
</html>
I've searched and tried all Stackoverflow solutions without success.
I've this code and I'm using bootstrap3
<footer>
<div class="container">
<div class="row">
<div class="col-md-4">
<img src="Images/social/facebook.png" alt="facebook" class="footerimg" />
<img src="Images/social/twitter.png" alt="twitter" class="footerimg" />
<img src="Images/social/youtube.png" alt="youtube" class="footerimg" />
</div>
<div class="col-md-4 col-md-offset-4">
<p class="text-right">© <%: DateTime.Now.Year %> Test - All Rights Reserved</p><p class="text-right">P.IVA 123456789</p>
</div>
</div>
</div>
</footer>
I would like to vertically center col-md-4 elements and I have footer styles like this:
footer {
background-color: #000;
color: #fff;
height: 120px;
}
I've already tried with table-cell applied to col-md-4 but without success.
Can you suggest a solution?
If you want something like this : (images are not shown)
I made a live example.
This is the code :
<footer>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-4">
<div class="centered">
<img src="Images/social/facebook.png" alt="facebook" class="footerimg" />
<img src="Images/social/twitter.png" alt="twitter" class="footerimg" />
<img src="Images/social/youtube.png" alt="youtube" class="footerimg" />
</div>
</div>
<div class="col-md-4 col-sm-4 col-sm-offset-4 col-md-offset-4">
<div class="centered">
<p class="text-right">© Test - All Rights Reserved</p><p class="text-right">P.IVA 123456789</p>
</div>
</div>
</div>
</div>
</footer>
And the CSS
footer {
background-color: #000;
color: #fff;
height: 120px;
display: table;
width: 100%;
}
.centered {
display: table-cell;
vertical-align: middle;
height: 120px;
}
Ref : centering-in-the-unknown