rescaling div inside a table cell - html

I'm trying to add a simple upvote/downvote counter into each row of a table. The counter is basically a container of divs shaped by css, that I'm inserting into a table cell. However, as is, the vote counter causes the row to balloon up. I trying resizing the top most div container but it only resizes the voting elements. The actual counter remains the same size. I'm new to css so I don't have a good sense of things yet. What is the best way to rewrite my CSS so I can easily scale the entire vote counter from the topmost level, without having to manually change all the sub-elements? This would be great if I wanted to stick this counter somewhere else on my site, not inside a table cell.
Here is the jsfiddle.
https://jsfiddle.net/havok2063/30way48v/
Very simple html describing the upvote/downvote counter.
<div class="vote circle">
<div class="increment up"></div>
<div class="increment down"></div>
<div class="count">8</div>
</div>
Here is the CSS.
.vote {
display: flex;
flex-direction: column;
position: relative;
width: 10rem;
height: 10rem;
}
.circle .up { border-radius: 10rem 10rem 0 0; }
.circle .down { border-radius: 0 0 10rem 10rem; }
.circle .count { border-radius: 50%; }
.up {
background: #4BC35F;
height: 50%;
margin-bottom: 0.25rem;
}
.down {
background: #C15044;
height: 50%;
}
.increment {
flex: 1 0 0;
text-align: center;
opacity: .5;
transition: 0.3s;
cursor: pointer;
}
.increment:hover {
opacity : 1;
}
.count {
position: absolute;
top: 0;
background: rgba(245,245,245,1.0);
border-radius: 0.1rem;
margin: 2.5rem;
width: 5rem;
font-size: 2.5rem;
font-weight: bold;
line-height: 5rem;
text-align: center;
box-shadow: 0 0 0 0.5rem rgba(245,245,245,1.0);
pointer-events: none;
}
html, body { height: 100%; }

Are you trying to make all the table cells the same height like this fiddle? https://jsfiddle.net/30way48v/2/
If so, add this to your css td{height: 100px;}

OK, here its is with smaller <td>'s
here is the fiddle https://jsfiddle.net/30way48v/3/
td{height: 50px;}
.vote {
display: flex;
flex-direction: column;
position: relative;
width: 5rem;
height: 5rem;
margin: 0px;
}
.circle .up { border-radius: 5rem 5rem 0 0; }
.circle .down { border-radius: 0 0 5rem 5rem; }
.circle .count { border-radius: 50%; }
.up {
background: #4BC35F;
height: 50%;
margin-bottom: 0.25rem;
}
.down {
background: #C15044;
height: 50%;
}
.increment {
flex: 1 0 0;
text-align: center;
opacity: .5;
transition: 0.3s;
cursor: pointer;
}
.increment:hover {
opacity : 1;
}
.count {
position: absolute;
top: 0;
background: rgba(245,245,245,1.0);
border-radius: 0.1rem;
margin: 1.45rem;
width: 2rem;
font-size: 2.5rem;
font-weight: bold;
line-height: 2rem;
text-align: center;
box-shadow: 0 0 0 0.5rem rgba(245,245,245,1.0);
pointer-events: none;
&.upvoted { color: #4BC35F; }
&.downvoted { color: #C15044; }
}
html, body { height: 100%; }

Related

Transforming and tranisitions in CSS | Transition not working

I have the following css file
body {
font-family: Baskerville;
background: #ecf0f1;
color: #2c3e50;
}
h1 {
margin: 16px 0;
padding-left: 16px;
border-left: 5px solid #e74c3c;
font-family: Baskerville;
font-size: 48px;
}
h3 {
margin: 16px 0;
padding-left: 16px;
color: #cccac4;
}
.container1 {
padding: center;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
}
.container1 .checkbox {
padding: 8px 48px;
margin: 8px;
font-family: Baskerville;
font-size: 25px;
}
input[type="checkbox"]{
display: none;
}
label {
position: relative;
}
label::before {
content: "";
background: url("check-circle.svg");
background-position: center;
background-size: contain;
width: 32px;
height: 32px;
position: absolute;
left: -44px;
top: -8px;
transform: scale(0) rotateZ(180deg);
transition: all 0.4s cubic-bezier(0.54, 0.01, 0, 1.49);
}
input[type="checkbox"]:checked + label::before {
transform: scale(1.0) rotateZ(0deg);
}
label::after {
content: "";
border: 2px solid #27ae60;
width: 24px;
height: 24px;
position: absolute;
left: -42px;
top: 1px;
border-radius: 50%;
}
This is a simple transform and transition where i rotate the img (check-circle.svg) in those 4 curve points of cubic-bezier , whenever it is checked or unchecked after. However the transition and transformation wont work. It will simply not show. Where am i mistaken ?
Are you sure you've placed <label>...</label> immediately after <input type="checkbox"/>? Code seems fine, although I'm not sure what is the purpose of input[type="checkbox"]{ display: none; }. Posting html would be nice too.
Also you can check if provided svg's url is correct. Try to replace it with some other svg url found on internet.
make sure that (label) is a direct next child of (input)

Why is my input element wider than the other elements even though I already applied "box-sizing: border-box"?

I have an input element which has a padding of 1em on both the left and the right side. But I have applied "box-sizing: border-box" to it. However, It's width is still more than the other elements. I think it might be because I need to remove some piece of code but I'm not sure. The input element is definitely the one issue as the other element is properly center aligned.
Below is the code:
:root {
--main-color: #00308f;
--secondary-color: #7cb9e8;
--dark-color: #444;
--light-color: #fafafa
}
body {
font-family: Montserrat, sans-serif;
background-color: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin-top: 70px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 1em
}
.my-contacts-div {
align-items: center
}
.contacts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center
}
.contact-card {
width: 288px;
margin: .5em;
border-radius: .5em;
box-shadow: var(--secondary-color) 1px 1px 10px;
padding: 0 .75em;
word-wrap: break-word
}
.contact-form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: grid;
align-self: center;
width: 350px;
z-index: 1;
background-color: var(--secondary-color);
border-radius: 1em;
padding: 1em;
box-shadow: 1px 1px 1.5em var(--main-color);
visibility: hidden
}
.contact-form:target {
visibility: visible
}
.input-field {
margin: .5em 0;
border: solid 1px var(--secondary-color);
border-radius: .5em;
padding: 0 1em;
height: 40px;
box-sizing: border-box
}
.searchbar {
margin: .5em;
width: 100%
}
#media screen and (max-width:687px) {
.my-contacts-div {
padding: 0
}
.contact-card {
width: 100%
}
}
#media screen and (max-width:614px) {
body {
margin-top: 130px
}
}
<div class="my-contacts-div">
<h2>Heading</h2>
<form><input class="input-field searchbar" type="text" placeholder="Search here..."></form>
<div class="contacts-list">
<div class="contact-card">
<h3>Other component</h3>
</div>
</div>
</div>
What is wrong with it?
The issue was most likely that when you were using '.input-field' in the CSS, it was maybe not correctly using it so I just put 'form input.input-field' and also added some CSS to the form element. Now it is looking completely aligned.
:root {
--main-color: #00308f;
--secondary-color: #7cb9e8;
--dark-color: #444;
--light-color: #fafafa
}
body {
font-family: Montserrat, sans-serif;
background-color: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin-top: 70px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 1em
}
.my-contacts-div {
align-items: center
}
.contacts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center
}
.contact-card {
width: 288px;
margin: .5em;
border-radius: .5em;
box-shadow: var(--secondary-color) 1px 1px 10px;
padding: 0 .75em;
word-wrap: break-word
}
.contact-form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: grid;
align-self: center;
width: 350px;
z-index: 1;
background-color: var(--secondary-color);
border-radius: 1em;
padding: 1em;
box-shadow: 1px 1px 1.5em var(--main-color);
visibility: hidden
}
.contact-form:target {
visibility: visible
}
form input.input-field {
margin: .5em 0;
border: solid 1px var(--secondary-color);
border-radius: .5em;
padding: 0 1em;
height: 40px;
box-sizing: border-box;
}
form {
box-sizing: border-box;
padding: 0 0.5em;
}
.searchbar {
margin: .5em;
width: 100%
}
#media screen and (max-width:687px) {
.my-contacts-div {
padding: 0
}
.contact-card {
width: 100%
}
}
#media screen and (max-width:614px) {
body {
margin-top: 130px
}
}
<div class="my-contacts-div">
<h2>Heading</h2>
<form><input class="input-field searchbar" type="text" placeholder="Search here..."></form>
<div class="contacts-list">
<div class="contact-card">
<h3>Other component</h3>
</div>
</div>
</div>
Add display: flex in the tag. It will solve the overflowing issue.
display: flex fills the entire container taking margin and padding into consideration. That's why it didn't overflow.
display: block is at 100% width by default and then adds margin and padding after causing the overflow.

CSS clip-path replacement for IE

Does anyone know of CSS property that I can use to achieve the same result as clip-path to make rounded shapes around a div? My site needs to be compatible with the latest version of IE, but I checked on www.caniuse.com and clip-path is not supported on IE 11.
This is what I am trying to do:
My current code works as you can see in this codepen: https://codepen.io/CodingGilbert/pen/BqwoGm?editors=1100
The problem is, that this code won’t work in IE, how can I solve this? Surely there must be another CSS property which does the same.
.card {
width: 80%;
height: 16.5rem;
border-radius: 5px;
background-color: #fff;
text-align: center;
padding: 0 1.5rem;
margin:10rem auto;
}
.card__inner-wrapper {
height: 55%;
position: relative;
margin: 0 auto;
display: flex;
justify-content: center; }
.card__img {
height: 100%;
position: absolute;
bottom: 50%;
clip-path: circle(50% at 50% 50%);
background-color: #fff;
border: 0.8rem solid #fff; }
.card__text-content {
position: absolute;
top: 6rem; }
.card__heading {
font-size: 1.8rem;
font-weight: 500;
color: #5fc0c3;
margin-bottom: 1.5rem; }
In this case, border-radius: 50%; on the .card__img will give you the same result, and it's compatible with IE9 and above.
Demo:
body {
background-color: gray;
}
.card {
width: 80%;
height: 16.5rem;
border-radius: 5px;
background-color: #fff;
text-align: center;
padding: 0 1.5rem;
margin: 10rem auto;
}
.card__inner-wrapper {
height: 55%;
position: relative;
margin: 0 auto;
display: flex;
justify-content: center;
}
.card__img {
height: 100%;
position: absolute;
bottom: 50%;
border-radius: 50%; /* instead of clip-path */
background-color: #fff;
border: 0.8rem solid #fff;
}
.card__text-content {
position: absolute;
top: 6rem;
}
.card__heading {
font-size: 1.8rem;
font-weight: 500;
color: #5fc0c3;
margin-bottom: 1.5rem;
}
<div class="card">
<div class="card__inner-wrapper">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Light_bulb_icon_red.svg/2000px-Light_bulb_icon_red.svg.png" alt="Bulb icon" class="card__img">
<div class="card__text-content">
<h4 class="card__heading">We help charities</h4>
<p>Share knowledge and working practice to make the best technology choices.</p>
</div>
</div>
</div>
you could use inline SVG to clip an image as it has great browser support - http://caniuse.com/#search=inline%20svg

CSS Animating search box with flex box

I have been trying to get this layout to animate the search box when clicking on the search icon. It kind of works, except for two things. When the animation begins, the search icon quickly moves to the left where I'd like it to stay put and the search box extend out to the left. That would then push the logo over at the same time the logo switches to the small version.
Any guidance would be appreciated. Here is a JSFIDDLE and the code:
HTML:
<button class="hamburger hamburger-cancel" id="menu-trigger">
<span class="icon"></span>
</button>
<a id="site-logo" data-cy="site-logo" href="http://www.website.local">
<img class="full-logo" src="https://www.tracetronic.com/cms/data/img/inhalte/Logos_TraceTronic/Logo_TEST-GUIDE_rgb_SCREEN.jpg" alt="Engineering360 Logo">
<img class="logo-kite" src="http://i.imgur.com/w4MxJnp.png" alt="Engineering360 Logo Kite">
</a>
<form id="global-search-form" action="/search" data-cy="global-search-form">
<input class="search-box catcomplete" type="text" name="query" required="" value="" data-cy="global-search-box">
<input type="hidden" name="newSearch" value="new">
<input class="submit" type="submit" value="">
</form>
<div class="header-reg-links">
<img id="reg-trigger" data-cy="profile-popup-trigger" src="https://www.freeiconspng.com/uploads/profile-icon-9.png">
</div>
</div>
</header>
CSS/SCSS:
header {
background: black;
background-size: cover;
box-sizing: border-box;
padding: 0 .5em;
position: relative;
width: 100%;
z-index: 10;
#header-content {
align-items: center;
display: flex;
flex-flow: row nowrap;
margin: 0 auto;
max-width: 1140px;
#site-logo {
margin: .5em 2em;
min-width: 0;
flex-grow: 1;
text-align: center;
.logo-kite {
display: none;
}
img {
height: auto;
width: 5em;
}
}
.header-reg-links {
align-items: center;
display: flex;
position: relative;
#reg-trigger {
cursor: pointer;
margin-left: auto;
min-width: 0;
transition: opacity .3s;
width: 2.25em;
height: 1.75em;
padding: 1em .25em;
&:hover {
opacity: 0.9;
}
}
}
#global-search-form {
align-items: center;
display: flex;
flex-flow: row nowrap;
flex-grow: 0;
font-size: 15px;
min-width: 0;
padding: 0 2em;
margin: .5em 0;
padding: 0 .5em;
.nav-search-dropdown {
display: none;
}
.search-box {
background: #fbfbfb;
box-sizing: border-box;
border: 0;
font-size: 15px;
height: 2.25em;
line-height: 2.25em;
margin: 0;
min-width: 0;
flex: 0;
max-width: 40em;
overflow: hidden;
text-overflow: ellipsis;
padding: 0;
transition: width 1s;
width: 0;
}
.submit {
border: 0;
border-radius: 0 3px 3px 0;
box-sizing: border-box;
cursor: pointer;
height: 2.25em;
font-size: 15px;
min-width: 0;
background: url("https://vignette.wikia.nocookie.net/deusex/images/9/9b/Magnifying_glass_icon.png/revision/latest?cb=20141205155051&path-prefix=en") center center / 1.65em no-repeat;
padding: 0;
width: 2em;
}
}
&.search-open {
#site-logo {
flex: 0 0 2em;
margin: 0 .5em;
.logo-kite {
display: block;
width: 2em;
}
.full-logo {
display: none;
}
}
#global-search-form {
flex: 1 1 0;
margin: 0;
padding: 0;
width: 16em;
.search-box {
flex: none;
padding: .25em .5em;
width: 90%;
}
.search-trigger {
display: none;
}
}
}
}
#menu-trigger {
background: transparent;
border: 0 none;
cursor: pointer;
display: inline-block;
height: 1em;
outline: none;
padding: 0;
transition: transform .2s ease-in-out;
vertical-align: middle;
flex: 0 0 1.25em;
font-size: 1.5rem;
margin: 0 .25em;
width: 1.5em;
&:before, &:after {
content: "";
}
&:before, &:after, .icon {
background: #FBFBFB;
border-radius: .05em;
display: block;
height: .1em;
margin: 0 0 .3em;
transition: transform .2s ease-in-out;
width: 100%;
}
&.menu-open:before {
transform: translateY(.4em) rotate(135deg);
}
&.menu-open .icon {
transform: scale(0);
}
&.menu-open:after {
transform: translateY(-.4em) rotate(-135deg);
}
}
}
JQUERY:
$(function() {
// Click event for profile icon.
$("#reg-trigger").click(function() {
$("#header-content .header-reg-links").toggleClass("active");
$(document).on("click.document", function(e) {
var container = $("#header-content .header-reg-links");
// if the target of the click isn't the container nor a descendant of the container
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.removeClass("active");
// remove the click event on the document when it's no longer needed.
$(document).off("click.document");
}
});
})
// Opens main menu
$("#menu-trigger").click(function() {
$("html, #menu-trigger, #site-nav").toggleClass("menu-open");
});
// Header search bar toggle
$("#global-search-form input.submit").click(function(e) {
console.log($("#global-search-form input.search-box").val());
if ($("#header-content").hasClass("search-open")) {
if ($("#global-search-form input.search-box").val() == "") {
e.preventDefault();
$("#header-content").toggleClass("search-open");
} else {
return true;
}
} else {
e.preventDefault();
$("#header-content").toggleClass("search-open");
}
});
});

Vertically Align <a> text inside a div

I am having trouble vertically aligning the 's text inside a div.
This is what I have. I need to center "Next" inside the blue box:
#import url(http://fonts.googleapis.com/css?family=Muli);
/*Makes the little side arrow*/
.open {
position: fixed;
width: 100px;
height: 40px;
left: 50%;
top: -1000px;
margin-left: -80px;
margin-top: -30px;
border: 1px solid #ccc;
background-color: #fff;
border-radius: 6px;
padding: 10px 30px;
color: #444;
transition: all ease-out 0.6s;
}
.open:hover {
border: 1px solid #aaa;
box-shadow: 0 0 8px #ccc inset;
transition: all ease-out 0.6s;
}
.tutorial-box {
position: fixed;
width: 400px;
height: 238px;
top: 75px;
background-color: #F3F3F3;
border-radius: 6px;
box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4);
}
.slider-turn p, .tutorial-box h1{
margin-left: 10px;
}
.tutorial-box:before {
content: '';
position: absolute;
left: -14px;
top: 28px;
border-style: solid;
border-width: 10px 14px 10px 0;
border-color: rgba(0, 0, 0, 0) #f3f3f3 rgba(0, 0, 0, 0) rgba(0, 0, 0, 0);
}
.tutorial-box p {
width: 350px;
font-size: 16px;
color: #a8aab2;
font-weight: 400;
line-height: 28px;
float: left;
margin: 0;
}
.tutorial-box .bottom {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
width: 100%;
bottom: 0;
position: absolute;
}
.tutorial-box .bottom .btn-2 {
flex: 3;
-webkit-flex: 3;
-ms-flex: 3;
width: 100%;
height: 54px;
background-color: #373942;
border-bottom-left-radius: 6px;
display: flex;
}
.tutorial-box .bottom span {
flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
line-height: 54px;
color: #fff;
margin-left: 25px;
font-size: 18px;
}
.next {
text-decoration: none;
display: inline-block;
vertical-align: middle;
text-align: center;
flex: 1;
background-color: #6cb5f3;
border: 0;
margin: 0;
padding: 0;
text-transform: uppercase;
color: #fff;
font-weight: bold;
border-bottom-right-radius: 6px;
cursor: pointer;
transition: all .3s;
}
.next:hover {
text-decoration: none;
background-color: #6BA5D6;
transition: all .3s;
}
.next:active {
text-decoration: none;
background-color: #5F8AAF;
}
.slider-tutorial-box {
width: 350px;
margin: 0 25px;
overflow: hidden;
}
.slider-turn {
width: 10000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- TUTORIAL -->
<div class="tutorial-box">
<h1>Welcome</h1>
<span class="close"></span>
<div class="slider-container">
<div class="slider-turn">
<p>
Here, under the Company tab, is where you will do most of the company managment.<br>
</p>
</div>
</div>
<div class="bottom">
<div class="btn-2">
<span>Step 2/?</span>
</div>
Next
</div>
</div>
Please let me know how I can center the text vertically to the center of the div.
Thank you very much. Let me know if I wasn't clear enough.
Seems like you already did that for .tutorial-box .bottom span so, do the same thing for .next
.next{
line-height: 54px;
}
the simplest and possibly most easy way would be to add the 'center' and '/center' tag before and after the text you want, and after each letter use '/br' to move to the next line. this will add some bulk, but would be considerably easier than other methods.
<center>
'letter'</br>'next letter'</br>'next letter'</br>
</center>
repeating the letter and break for all letters
alternatively, you could also add "div" tags around the "a" tag. you would have to modify the 'height' and 'width' to make it vertical for you. I would use px for this and not '%' or 'em'. add this to them:
<div style="height: /* modify this */100px; width: /* and this*/20px;">
Next
</div>
this may not be AS compatible cross platform though.
Like this:
.next {
position: relative;
top: 50%;
transform: translateY(-50%);
}
A nice trick that works both vertically and horizontally.