Get table cell content to move up on page - javascript

Ok, I have an odd problem trying to align content in 2 columns (achieved using display:table), and have the content in the column div be up top rather than bottom.
Here is my problem - see the buttons/content on far right are aligned at the BOTTOM of that div:
Here is how this is achieved - I am trying to do this:
<div class="content">
<div id = "centered">
<div id = "video">
<iframe style = "border-width: 0" width="600px" height="600px"
src="https://www.youtube.com/embed/nRG3wWeMqAQ?autoplay=1">
</iframe>
</div>
</div>
<div id = "righted">
<p id = "contentTxt"> <strong> Choose </strong>the option that sounds like you.</p>
<div class='button -dark'>im a user</div>
<div class='button -light'>im a store</div>
</div>
CSS:
.content #centered {
padding-left: 280px;
}
/*Divides into 2 sections*/
#righted {
display: table-cell;
padding-left: 2em;
}
#centered {
width: 600px;
display: table-cell;
padding-left: 270px;
}
#content {
display: table-row;
}
On the righted no matter what I do with margin-top, padding-top, or top it stays on the bottom there. How can I fix this?

Set the vertical align to move the content up
#righted {
vertical-align: top
}
and you probably need to remove the margin on the paragraph so it is at the very top and without the default margins from the browser
#righted p {
margin-top: 0;
}

The vertical-align property should do what you need here
.content #centered {
padding-left: 280px;
}
/*Divides into 2 sections*/
#righted {
display: table-cell;
vertical-align: top;
padding-left: 2em;
}
#centered {
width: 600px;
display: table-cell;
padding-left: 270px;
}
#content {
display: table-row;
}
<div class="content">
<div id="centered">
<div id="video">
<iframe style="border-width: 0" width="600px" height="600px" src="https://www.youtube.com/embed/nRG3wWeMqAQ?autoplay=1">
</iframe>
</div>
</div>
<div id="righted">
<p id="contentTxt"> <strong> Choose </strong>the option that sounds like you.</p>
<div class='button -dark'>im a user</div>
<div class='button -light'>im a store</div>
</div>

Use vertical-align: top for #righted
Also you have defined display: table-row for #content but content is not the id of a div so it should be .content
check the edited code
.content #centered {
padding-left: 280px;
}
/*Divides into 2 sections*/
#righted {
display: table-cell;
padding-left: 2em;
vertical-align: top;
}
#centered {
width: 600px;
display: table-cell;
padding-left: 270px;
}
.content {
display: table-row;
}
<div class="content">
<div id = "centered">
<div id = "video">
<iframe style = "border-width: 0" width="600px" height="600px"
src="https://www.youtube.com/embed/nRG3wWeMqAQ?autoplay=1">
</iframe>
</div>
</div>
<div id = "righted">
<p id = "contentTxt"> <strong> Choose </strong>the option that sounds like you.</p>
<div class='button -dark'>im a user</div>
<div class='button -light'>im a store</div>
</div>
Hope it helps

Related

How to change whole layout of a div without refreshing the page

So, I'm doing a project on React and I have this div tag which is a container that consists of information portrayed in this first image. Then what I would like to do is within that div without having the page refreshed change the display into this second image. It is like a card stacking on each other. I have no idea what keywords to search on google so I couldn't find any examples to do this.
Here's my html and css code for my div in the first image.
HTML
<div className={styles.showTicketBox}>
<div className={styles.showTicketBox1}>
<div className={styles.userEligibleTickets}>
<p>Your Eligible Tickets</p>
<h3 style={tokenContent}>0 Ticket(s)</h3>
</div>
<div className={styles.userDepositedTickets}>
<p>Your Deposited Tickets</p>
<h3 style={tokenContent}>0 Ticket(s)</h3>
</div>
</div>
<div className={styles.showTicketBox2}>
<div className={styles.userWinningTickets}>
<p>Your Winning Tickets</p>
<h3 style={tokenContent}>0 Ticket(s)</h3>
</div>
<div className={styles.userTicketsAllo}>
<p>Your Allocation</p>
<h3 style={tokenContent}>0 SHI</h3>
</div>
</div>
</div>
CSS
.showTicketBox{
width: 100%;
display: flex;
justify-content: space-around;
padding: 20px;
margin-top: 2em;
.showTicketBox1{
width: auto;
height:auto;
display: inline-block;
}
.showTicketBox2{
width: auto;
height:auto;
position: relative;
display: inline-block;
}
}

position two components as columns

I have a screen that looks like this:
The text is at the top while the red section (VideoComponent) is at the bottom. I want the VideoComponent to appear on the left side while all the text should move towards the right. Like a flex box. Or like in 2 columns.
return (
<div>
<main className="content">
<div className="text">
In this section.....TEXT
<div className="video">
<VideoComponent />
</div>
</div>
</main>
</div>
);
I tried adding float right/left to the css but it does not make a difference.
.content{
padding-left: 280px;
padding-top: 100px;
background-color: white;
}
.buttons{
padding-top: 20px;
flex-direction: column;
display: flex;
width: 200px;
}
.heading{
font-size: 25px;
}
.text{
float: left;
}
.video{
float: right;
}
How else can I fix this? Here's a codesandbox: https://codesandbox.io/s/vibrant-turing-tulc2?file=/src/VideoComponent.tsx
You could use Flexbox to achieve this. I know you're working with react, but this is just HTML and CSS. Maybe try something like this:
<div class="wrapper">
<div class="text">
My text
</div>
<div class="image">
<img src="imageurl">
</div>
</div>
.wrapper {
display:flex
}
.text {
margin: 10px
}
https://codepen.io/pauladiniz/pen/abpxeLK
Set the "text" class in the css file to "display: flex;" this should automatically change the objects (the text and the video) to a row. Maybe float will cancel it out but i am not sure about that. Just try it out.
You didn't nested your elements properly.. your JSX should be like this below
<div>
<main className="content">
<div className="video">
<VideoComponent />
</div>
<div className="text">
In this section.....TEXT
</div>
</main>
</div>
Simply update with the below css.
.content{
padding-left: 280px;
padding-top: 100px;
background-color: white;
display:flex;
}
.buttons{
padding-top: 20px;
flex-direction: column;
display: flex;
width: 200px;
}
.heading{
font-size: 25px;
}
.text{
// float: left;
}
.video{
// float: right;
}
This problem will be reolved
The solution to the problem is very simple that you can use cross-browser too.
<main>
<div class="text">text goes here</div>
<div class="video">video here</div>
</main>
Now for the CSS part, you can do this
main{
display:flex;
}
main .text{
order:2;
}
main .video{
order:1;
}
and you can test it on cross-browser we have another CSS property too which is already used by ''Medi'' flex-direction but it does not support Firefox, So you can use "order" which is supported in all browsers.

How to create 2 divs with equal height without bootstrap or jquery

I am trying to write a code is CSS and normal javascript but it won't work. Here is my code (HTML and CSS).
.wrapper{
height: 100%;
margin: 1.5rem 0 0 0;
display: flex;
}
.first{
vertical-align: top;
display: inline-block;
margin-right: 2rem;
flex: 1;
}
.second{
vertical-align:top;
display: inline-block;
flex: 1;
}
<div class="wrapper">
<div class="first">
<div class="times">
<div><h1>TIMES</h1><br></div>
<div class="space">
<h2>TIMES</h2>
<p>GESLOTEN</p>
</div>
<div class="space">
<h2>Dinsdag - Zaterdag</h2>
<p>09:30 UUR - 18:00 UUR</p>
</div>
</div>
</div>
<div class="second">
<div class="welcome">
<div><h1>WELKOM</h1></div>
<div><p>TEKST</p></div>
</div>
</div>
</div>
I have tried everything, at least I think I have.
The problem is that I can't fix this in CSS but I tried Java.
Still no success. Can someone please explain why I can't get it the same height.
It's a school project and I need to make a website from scratch.
Here is my full website source code: https://codepen.io/crosso_7/pen/VERrvQ
Both first and second divs are actually the same height - I just copied your snippet and applied a border around each div to see the issue and both divs are equal.
.wrapper{
height: 100%;
margin: 1.5rem 0 0 0;
display: flex;
}
.first{
vertical-align: top;
display: inline-block;
margin-right: 2rem;
flex: 1;
border: solid 1px blue;
}
.second{
vertical-align:top;
display: inline-block;
flex: 1;
border: solid 1px red;
}
<div class="wrapper">
<div class="first">
<div class="times">
<div><h1>TIMES</h1><br></div>
<div class="space">
<h2>TIMES</h2>
<p>GESLOTEN</p>
</div>
<div class="space">
<h2>Dinsdag - Zaterdag</h2>
<p>09:30 UUR - 18:00 UUR</p>
</div>
</div>
</div>
<div class="second">
<div class="welcome">
<div><h1>WELKOM</h1></div>
<div><p>TEKST</p></div>
</div>
</div>
</div>
You can do it using flexbox. Something like this code snippet.
.wrapper {
display: flex;
justify-content: space-between;
}
.wrapper div {
background: #000;
color: #fff;
flex: 1;
margin: 10px;
justify-content: center;
}
<div class='wrapper'>
<div>
<h1>1</h1>
<h2>asasasa</h2>
</div>
<div>2</div>
</div>
Is the first div the one thats higher? It's probably created by the padding from first div content vs seconds less content.
May have to set first and second div with a px or % height which are the same to make it equal.
Try using the code below in your .first and .second divs
flex: 1;
display: flex;

Add image below a certain class of element using css

What I want to do:
I want to add a "walkingMan" image under an element when its class is changed to activeCell. I know how to do it when the image is added to the front or back of the element using pseudo class, but as far as I know, there isn't something like :below that I can use to achieve the same effect. Is there a way in css I can use to micmic this?
What I have done:
I have added image below every upper cell and make it visible when the class is changed to activeCell. But I hope to find a more simple solution.
What it looks like:
Code: Simplified Code Example
You can use a single pseudo element on the .cell element and place a background image on it when it's active.
let activeIndex = 0;
const cells = [...document.querySelectorAll('.cell')];
setInterval(() => {
cells.forEach(cell => {
cell.classList.remove('activeCell')
});
cells[activeIndex].classList.add('activeCell');
activeIndex = activeIndex === cells.length - 1 ? 0 : (activeIndex + 1);
}, 300)
.cell {
display: inline-block;
border: 1px solid black;
margin-bottom: 1.2em;
}
.activeCell {
background-color: lightgrey;
position: relative;
}
.activeCell::after {
content: "";
position: absolute;
width: 1em;
height: 1em;
top: 1.3em;
left: calc(50% - .5em); /* Center the stickman. Position it half of its width before the parent center*/
background-image: url('https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png');
background-size:cover; /* Scale the stickman to completely cover the background area. */
}
<div>
<div class='top'>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
</div>
<div class='bottom'>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
</div>
</div>
What about this: https://jsfiddle.net/147prwy5/3/
HTML
<div class="cell active">
<a>One</a>
<img src="https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png" alt="walkingMan" />
</div>
<div class="cell">
<a>One</a>
<img src="https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png" alt="walkingMan" />
</div>
<div class="cell">
<a>One</a>
<img src="https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png" alt="walkingMan" />
</div>
<div class="cell active">
<a>One</a>
<img src="https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png" alt="walkingMan" />
</div>
CSS
.cell {
display: inline-block;
}
.cell a {
border: 1px solid black;
}
.cell.active a {
background-color: lightgrey;
}
.cell img {
width: 20px;
height: 20px;
display: none;
}
.cell.active img {
margin-top: 5px;
width: 20px;
height: 20px;
display: block;
}
I've never been a fan of the ::before and ::after pseudo classes mainly because I've personally noticed some oddities when trying to position things in Chrome vs IE (damn it IE!). Since most people here are going to give a solution using these pseudo classes (because that's somewhat what you asked) I thought I'd give a different solution using flexbox and more divs.
Not the most optimal for download size but I do like that it's not absolute positioning elements and if the squares get bigger or smaller it's pretty easy to handle that as a scss variable at the top of the file. This all uses only two values, your padding between boxes and the size of the boxes so it should be easy to update and maintain.
Anyway, have fun! Awesome question by the way :-)
.blocks {
display: flex;
}
.block {
flex: 0 0 20px;
margin: 0px 5px;
display: flex;
flex-direction:column;
}
.block > .square {
flex: 0 0 20px;
margin: 5px 0px;
background: grey;
}
.block > .space {
flex: 0 0 20px;
margin: 5px 0px;
}
.block.activeCell > .space {
background: green;
}
<div class="blocks">
<div class="block activeCell"><div class="square"></div><div class="space"></div></div>
<div class="block"><div class="square"></div><div class="space"></div></div>
<div class="block"><div class="square"></div><div class="space"></div></div>
<div class="block"><div class="square"></div><div class="space"></div></div>
</div>
<div class="blocks">
<div class="block"><div class="square"></div></div>
<div class="block"><div class="square"></div></div>
<div class="block"><div class="square"></div></div>
<div class="block"><div class="square"></div></div>
</div>
Using jQuery you can toggle the class upon clicking with this:
$('.cell').click(function() { //catch clicks on .cell
$('.cell').removeClass('activeCell'); //remove class "activeCell" from all
$(this).addClass('activeCell'); //add class "activeCell" to .cell clicked
});
Apply position: relative; to .top and .bottom:
.top,
.bottom {
position: relative;
}
And use the psuedoclass :before to create a image under the .activeCell
.activeCell:before {
content: "";
position: absolute;
bottom: -20px;
height: 20px;
width: 20px;
background-image: url("https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png");
background-size: 20px 20px;
}
And remove this:
.walkingMan {
width: 20px;
height: 20px;
display: inline-block
}
And this:
<img src="https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png" alt="walkingMan" class='walkingMan'/>
And to add space between the divs .top and .bottom put a <br> between them.
$('.cell').click(function() {
$('.cell').removeClass('activeCell');
$(this).addClass('activeCell');
});
.cell {
display: inline-block;
border: 1px solid black;
cursor: pointer;
}
.top,
.bottom {
position: relative;
}
.activeCell {
background-color: lightgrey;
}
.activeCell:before {
content: "";
position: absolute;
bottom: -20px;
height: 20px;
width: 20px;
background-image: url("https://www.shareicon.net/data/512x512/2016/01/17/704754_people_512x512.png");
background-size: 20px 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div>
<div class='top'>
<a class='cell activeCell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
</div>
<br>
<div class='bottom'>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
<a class='cell'>One</a>
</div>
</div>
add .RunManActive Class for Active element
//clicking add active Class
$(".RunMan").click(function() {
$(".RunMan").removeClass('RunManActive');
$(this).toggleClass('RunManActive');
});
//timing add active Class
var i=0;
var $elm=$(".Animate");
setInterval(function(){
$elm.removeClass('RunManActive');
$elm.eq(i).toggleClass('RunManActive');
i=$elm.length<=i?0:i+1;
}, 1000);
.RunMan{
width:35px;
height:35px;
background-color:lightgray;
border:3px solid #fff;
float:left;
position: relative;
}
.RunManActive{
background-color:#eee;
border:3px solid lightgray;
}
.RunManActive > div{
width:35px;
height:35px;
position: absolute;
background-image:url(http://www.iconsfind.com/wp-content/uploads/2013/11/Objects-Running-man-icon.png);
background-size:cover;
top:100%;
margin-top:5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="RunMan"><div></div></div>
<div class="RunMan RunManActive"><div></div></div>
<div class="RunMan"><div></div></div>
<div class="RunMan"><div></div></div>
<div class="RunMan"><div></div></div>
<br><br><br><br><br><br>
<div style=" width:100%">
<div class="Animate RunMan"><div></div></div>
<div class="Animate RunMan "><div></div></div>
<div class="Animate RunMan"><div></div></div>
<div class="Animate RunMan"><div></div></div>
<div class="Animate RunMan"><div></div></div>
You can do something like this, using CSS only. With :target selector you can apply a style to the element you need to hide / show.
.container {
display: inline-block;
width: 100px;
height: 200px;
}
.link {
display: block;
width: 100px;
height: 100px;
background: #ccc;
}
.walking-man {
display: none;
width: 100px;
height: 100px;
background: red;
}
#p1:target {
display: block;
}
#p2:target {
display: block;
}
#p3:target {
display: block;
}
#p4:target {
display: block;
}
height: 90px;
float: left;
}
.walking-man img {
width: 100%;
}
.walkin-man:target {
display: block;
}
<div class="container">
<div id="p1" class="walking-man"></div>
</div>
<div class="container">
<div id="p2" class="walking-man"></div>
</div>
<div class="container">
<div id="p3" class="walking-man"></div>
</div>
<div class="container">
<div id="p4" class="walking-man"></div>
</div>

Responsive Equal height div without specifying the height

I am looking for some responsive equal height div by just using CSS. I don't want to specify the height. Looking somewhat similar to the image below but both the divs should adjust based on the other div height.
If the left side div is long then the right side div should adjust to the left side div and vice versa.
Also the right side div has 2 small divs which should also be of same height.
Can this be achieved using only CSS? Or should I make use of JS/jQuery?
Example here on the jsFiddle
img {
width: 100%;
border: 1px solid green;
}
.row {
display: table;
}
.column {
display: table-cell;
vertical-align: top;
}
.w100 {
width: 100%;
}
.w75 {
width: 75%;
}
.w50 {
width: 50%;
}
.w25 {
width: 25%;
}
<body>
<div class="row w100">
<div class="column w75">
<img src="http://placehold.it/500x500" alt="">
</div>
<div class="column w25">
<div class="col-row">
<img src="http://placehold.it/250x250" alt="">
</div>
<div class="col-row">
<img src="http://placehold.it/250x250" alt="">
</div>
</div>
</div>
You could use flex-box, for example:
.row {
display: flex;
flex-direction:row;
}
.column {
display: flex;
flex-direction:column;
}
And getting rid of the widths the browser does a great job aligning the items:
http://jsfiddle.net/2vLpx9k3/3/
You may need some prefixes for cross-browser support.
I've made something that might possibly be something that you are looking for.
http://jsfiddle.net/2vLpx9k3/4/
It adjusts the widht and height of the inner elements based on the outer element.
HTML:
<div class="outer">
<div class="left">
<div class="right"></div>
<div class="right bottom"></div>
</div>
</div>
CSS:
.outer {
height: 100vh;
}
.left {
background-color: red;
width: 100%;
height: 100%;
margin-right: 50%;
}
.right {
background-color: green;
height: 50%;
margin-left: 50%;
}
.right.bottom {
background-color: black;
}

Categories

Resources