Position button segment right - html

I'm writing a CSS framework and when it comes to handling buttons I'm trying to make it so that the user can segment the button (this is done, see the fiddle below) - however, I want to add another semantic CSS selector that will allow the user to positon this left/right of the button text (automatically right). My issue is, however - I don't want to affect the HTML in any way, the HTML structure is the same for every other button, so I'd rather not altar this if possible.
I've tried floating the segment left, afterwards I thought it was pretty obvious that wouldn't work - the height of the button is also dependent on the padding of the segment - so (as far as I'm aware) it's not possible to position this absolutely. I'm having a mental block as to how to achieve this.
Here is my current CSS:
.dte.button {
border-radius: 0;
display: inline-block;
border: 0;
outline: 0;
padding: 10px;
background: #34495e;
color: white;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
cursor: pointer;
transition: 0.25s all;
position: relative;
}
button.dte.button.segmented {
padding: 0;
padding-left: 10px;
position: relative;
}
.dte.button .segment {
filter: brightness(50%);
background: rgba(0, 0, 0, 0.53);
padding: 10px;
display: inline-block;
margin-left: 10px;
}
And my HTML structure
<button class="dte button segmented">
This should align the segment RIGHT (it does)
<div class="segment">
<i class="fa fa-align-right"></i>
</div>
</button>
<button class="dte button segmented left">
This should align the segment LEFT(It doesn't)
<div class="segment">
<i class="fa fa-align-left"></i>
</div>
</button>
Fiddle of what I current have.

It is not pretty, but you can use float:left if you then fix your spacing with some negative margins.
So for example:
.dte.button {
border-radius: 0;
display: inline-block;
border: 0;
outline: 0;
padding: 10px;
background: #34495e;
color: white;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
cursor: pointer;
transition: 0.25s all;
position: relative;
}
button.dte.button.segmented {
padding: 0;
padding-left: 10px;
position: relative;
}
button.dte.button.segmented.left {
padding: 10px 10px 10px 0;
}
.dte.button .segment {
filter: brightness(50%);
background: rgba(0, 0, 0, 0.53);
padding: 10px;
display: inline-block;
margin-left: 10px;
}
.dte.button.left .segment {
float: left;
margin: -10px 10px -10px 0;
}
<div style="padding: 20px;">
<button class="dte button">dte-button</button>
<button class="dte button segmented">
Dropdown Button
<div class="segment">
ICON
</div>
</button>
<button class="dte button segmented">
Segment Aligned Right
<div class="segment">
ICON
</div>
</button>
<button class="dte button segmented left">
Segment Aligned Left
<div class="segment">
ICON
</div>
</button>
</div>
Here also a fiddle.

Related

Targeting span within button tag on hover: How to change border color and pointer?

I have some cards and want to change the properties border-color and pointer-events when a user hovers a span tag which is inside a button tag.
This is no problem if i use a tag, see First Card on the left:
https://codepen.io/anon/pen/JzzEvj
However, when using a PRG pattern with form and button changing the pointer event and the border-bottom color when hovering does not work with Firefox. (See Second Card on the right side)
Any ideas how to fix this in Firefox?
Desired outcome see Card on the left:
The cursor should have pointer state when hovering the image
The cursor should have pointer state when hovering the card heading
The card heading's border-bottom color should change color when hovering the card heading
I spend a lot of time on this issue but only found this solution https://codepen.io/anon/pen/PLLWxJ which is not exactly the same, because
the card heading's border-bottom color changes when hovering any part of the card.
all parts of the card look clickable when hovering. The cursor state should only change to pointer when hovering the image or the card heading.
a {
text-decoration: none;
}
.product-cards-wrapper {
background: #fff;
padding: 64px 0;
}
.product-cards {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.product-card {
border: 1px dotted #ccc;
cursor: default;
margin: 0 16px 32px;
width: 250px;
text-align: center;
}
.product-card-img-wrapper {
align-items: center;
cursor: pointer;
display: flex;
justify-content: center;
height: 150px;
line-height: 0;
margin-bottom: 16px;
}
.product-card-heading {
border-bottom: 1px solid #e5e5e5;
color: #2bb3f0;
display: inline;
font-family: sans-serif;
font-size: 18px;
font-weight: 700;
line-height: 1.6;
text-align: center;
transition: border-color .2s;
}
.product-card-heading:hover {
border-color: #2bb3f0;
cursor: pointer;
}
.product-card-label {
background: #fee5ad;
border-radius: 99px;
color: rgba(0, 0, 0, .54);
cursor: text;
font-family: sans-serif;
font-size: 14px;
font-weight: 600;
margin-top: 4px;
padding: 2px 10px;
}
.product-card>button {
background: 0;
border: 0;
padding: 0;
width: 100%;
}
.product-card-heading {
border-bottom: 1px solid #e5e5e5;
color: #2bb3f0;
cursor: pointer;
transition: border-color .2s;
}
.product-card button .product-card-img-wrapper,
.product-card button .product-card-heading {
cursor: pointer;
}
.product-card button .product-card-heading:hover {
border-color: #2bb3f0;
}
.product-card-labels {
display: block;
font-family: sans-serif;
}
<section class=product-cards-wrapper>
<div class=product-cards>
<a class=product-card href=#>
<div class=product-card-img-wrapper>
<img src=https://via.placeholder.com/160x150 alt="">
</div>
<div class=product-card-heading>First Card</div>
<div class=product-card-labels><span class=product-card-label>Label</span></div>
</a>
<form class=product-card action=# method=post target=_blank>
<button name=l value=123>
<span class=product-card-img-wrapper>
<img src=https://via.placeholder.com/120x150 alt="">
</span>
<span class=product-card-heading>Second Card</span>
<span class=product-card-labels><span class=product-card-label>Label</span></span>
</button>
</form>
</div>
</section>
This was a six years old Firefox bug which was fixed in Firefox 66.
Children of the button tag now do respond to :hover. :)

How to align a dropdown menu in CSS

I'm having some trouble aligning my dropdown menu in my angular app.
Please see the screenshot attached. The menu extends too far right of the screen. I need it to align to the "top right" of the ellipses instead of the "top left" as it is currently. The menu is currently functioning in a table.
Any assistance in getting the menu to shift to the left would be greatly appreciated.
Here is the HTML/CSS:
<td class="dropup">
<div class="dropup">
<button style="background-color: white;" class="dropbtn">
<img class="icon" src="assets/ellipsis.png">
</button>
<div class="dropup-content">
Admin Functionality
Download Project Snapshot
<a [routerLink]="['/project/'+j._id+'/project-activity']">View Project Activity</a>
Archive Project
<a *ngIf="j.creatorid != user._id" (click)="onLeaveProjectClick(j._id, j.projectname, n)">Leave Project</a>
</div>
</div>
</td>
.dropbtn {
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropup {
position: relative;
display: inline-block;
float:right;
}
.dropup-content {
display: none;
position: absolute;
transform-origin: 60% 40%;
top: 20px;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 10px;
}
.dropup-content :hover {
border-radius: 10px;
}
.dropup-content a {
color: black;
padding: 8px 16px;
text-decoration: none;
display: block;
}
.dropup-content a:hover {
background-color: #ddd;
color: #00aca8 !important;
}
.dropup:hover .dropup-content {
display: block;
border-radius: 10px;
}
As you set .dropup-content to absolute, it will be left aligned relative to .dropup as .dropup-content is within .dropup. But as your class is already absolute, simply add:
right: 0;
left: auto; // Unsure if you really need this though
to .dropup-content. This will take care that the class is right aligned relative to .dropup.
add to class .dropup-content this:
right:0;
https://jsfiddle.net/b1stpfr4/2/

How can i move the button to the center (html,jsp)?

please tell me what to do to move my button to the center of the page. beacause right now it is in the right corner and i tried a lot of times to move it.
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 13px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 17px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
font-weight: bold;
}
.button1:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
</style>
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
Horizontal aligment, you need to put css on the containing div, to control the child element...
.container {
display: block;
margin: 0 auto;
text-align: center;
}
<div class="container">
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
</div>
If you are looking to vertically center the element, use...
button {
position: relative;
top: 50%;
transform: translateY(-50%);
}
Alternatively you can do it with flexbox, it's a powerful way to quickly center elements both horizontally and vertically.
You just have to put your button inside a container, apply flexbox to it, then margin: auto; will do the rest.
.container {
display: flex;
}
.button {
margin: auto;
}
<div class="container">
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
</div>

Control side that shortens when changing div height on hover

I'm using this hover effect for buttons, but in a few cases when the height changes, the top remains the same and the bottom moves up, instead of vice versa like it should. How can I make sure it always goes in the correct direction?
jsfiddle
.button {
box-sizing: border-box;
display: inline-block;
width: 215px;
height: 55px;
color: white;
font-family: $arial;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
text-align: center;
text-decoration: none;
text-shadow: 1px 1px 1px rgba(43, 36, 36, 0.35);
letter-spacing: .1em;
border-radius: 3px;
position: relative;
background: #009ee0;
border: 1px solid #148fc6;
border-bottom: 4px solid #148fc6;
}
.button:hover {
border-bottom: 1px;
height: 53px;
}
.button span {
position: absolute;
width: 90%;
left: 0;
right: 0;
margin: auto;
top: 50%;
transform: translateY(-43%);
line-height: 1.2;
}
div {
padding: 20px 5px;
}
<div>
<a href="#" class="button">
<span>Wrong way</span>
</a>
</div>
<div>
<a href="#" class="button">
<span>I work fine</span>
</a>
<a href="#" class="button">
<span>I work fine</span>
</a>
</div>
You're reducing the height from 55px to 53px. That 2px has to go somewhere. The top button is just collapsing it. (The bottom two are doing the same, it just doesn't look like it because they are being affected by vertical text alignment). change your hover rule to this to accommodate for the height loss.
.button:hover {
border-bottom: 1px;
margin-top: 2px;
height: 53px;
}
https://jsfiddle.net/exd6hhvz/
I was able to make it work consistently by adding margin-top: 2px; to .button:hover
Here's an example: https://jsfiddle.net/vf03czp5/

CSS: How to make custom file upload button take full width (button works)

I am new to CSS and hope someone here can help me with this.
I am trying to apply a simple custom style to a file upload button (as part of an HTML form) to make it look similar to other buttons on my page and to get a similar look cross-browser.
So far I have the following which works as intended.
My only problem now is that I would like the button to take the full width of its parent div (in my case this will span across 9/12 ('col-9') of the page).
I tried adding width: 100%; to the CSS but then the button doesn't work anymore.
My HTML:
<div class="col-3 frmCaption">Attachments:</div>
<div class="col-9">
<div class="customUpload btnUpload btnM">
<span>Upload files</span>
<input type="file" class="upload" />
</div>
</div>
My CSS:
.btnDefault, .btnUpload {
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
color: #333333;
cursor: pointer;
font-weight: 400;
display: inline-block;
padding: 6px 12px;
text-align: center;
text-decoration: none;
vertical-align: middle;
}
.btnDefault:focus, .btnDefault:hover, .btnUpload:focus, .btnUpload:hover {
background-color: #E6E6E6;
}
.btnM {
border-radius: 4px;
font-size: 14px;
padding: 6px 12px;
}
.customUpload {
overflow: hidden;
position: relative;
}
.customUpload input.upload {
cursor: pointer;
margin: 0;
opacity: 0;
filter: alpha(opacity=0);
padding: 0;
position: absolute;
right: 0;
top: 0;
}
To style input elements, you need to actually style its label element.
From MDN,
The HTML Label Element () represents a caption for an item in a user interface. It can be associated with a control either by placing the control element inside the element, or by using the for attribute. Such a control is called the labeled control of the label element.
So, whenever you click a label, the attached input gets triggered.
So, just wrap the input element in a label instead of a div and stretch as much as you want. That will fix your issue.
.btnDefault,
.btnUpload {
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
color: #333333;
cursor: pointer;
font-weight: 400;
display: inline-block;
padding: 6px 12px;
text-align: center;
text-decoration: none;
vertical-align: middle;
}
.btnDefault:focus,
.btnDefault:hover,
.btnUpload:focus,
.btnUpload:hover {
background-color: #E6E6E6;
}
.btnM {
border-radius: 4px;
font-size: 14px;
padding: 6px 12px;
}
.customUpload {
overflow: hidden;
position: relative;
display: block;
}
.customUpload input.upload {
cursor: pointer;
margin: 0;
opacity: 0;
filter: alpha(opacity=0);
padding: 0;
position: absolute;
right: 0;
top: 0;
}
<div class="col-3 frmCaption">Attachments:</div>
<div class="col-9">
<label class="customUpload btnUpload btnM"> <span>Upload files</span>
<input type="file" class="upload" />
</label>
</div>
Working Fiddle
You need to apply the width property to the containing <div> as well. Once the div has the full size, then only the button inside can have the full width.
For simplicity i have made change to html, you can move it to appropriate classes.
<div class="col-3 frmCaption">Attachments:</div>
<div class="col-9">
<div class="customUpload btnUpload btnM" style="width:100%;">
<span>Upload files</span>
<input type="file" class="upload" style="width:100%;"/>
</div>
</div>
JS Fiddle
Or you can use this CSS andadd it both to your div and file upload,
.fullwidth
{
width : 100%;
}
<div class="col-3 frmCaption">Attachments:</div>
<div class="col-9">
<div class="customUpload btnUpload btnM fullwidth">
<span>Upload files</span>
<input type="file" class="upload fullwidth"/>
</div>
</div>
Make the button take 12 cols (as you use a 12 col system) , as that is the max number of cils available, in that way the elemts will take up the size of the div that it is contained in