Here's the problem. My checkbox was default one and I changed it by deleting the default styles with: -webkit-appearance: none;. But what happened after, you can see in the fiddle.
Somewhy, it's isn't aligned anymore. Tried to use vertical-align: middle or text-align:center, but didn't helped.
Why did it even happened and how to fix it?
.more-dropdown-price {
float: right;
vertical-align: middle;
}
.more-dropdown-checkbox {
height: 18px;
width: 18px;
border: 1px solid #92aabb;
-webkit-appearance: none;
display: inline-block;
}
input[type=checkbox]:checked {
background-color: #3180D8;
}
.dropdown-items:hover {
background-color: #87CEFA;
}
<div class="more-dropdown">
<div class="dropdown-items">
<input type="checkbox" class="more-dropdown-checkbox"> Foo <span class="more-dropdown-price"> 155$ </span>
</div>
<div class="dropdown-items">
<input type="checkbox" class="more-dropdown-checkbox"> Bar <span class="more-dropdown-price"> 15$ </span>
</div>
I suggest adding the following to your .dropdown-item class:
.dropdown-item{
display: flex;
align-items: center;
}
Add vertical-align: middle; to input.
.more-dropdown-price {
float: right;
vertical-align: middle;
}
.more-dropdown-checkbox {
height: 18px;
width: 18px;
border: 1px solid #92aabb;
-webkit-appearance: none;
display: inline-block;
vertical-align: middle;
}
input[type=checkbox]:checked {
background-color: #3180D8;
}
.dropdown-items:hover {
background-color: #87CEFA;
}
<div class="more-dropdown">
<div class="dropdown-items">
<input type="checkbox" class="more-dropdown-checkbox"> Foo <span class="more-dropdown-price"> 155$ </span>
</div>
<div class="dropdown-items">
<input type="checkbox" class="more-dropdown-checkbox"> Bar <span class="more-dropdown-price"> 15$ </span>
</div>
try something like this:
.dropdown-items:hover {
background-color: #87CEFA;
display: flex;
align-items: center;
align-content: center;
}
But I think you should align to the left because the elements have different number of letters so they are never aligned
Related
I have a label to the left of a text input but it looks like the text is just slightly below the bottom of the input. Here is my relevant HTML:
<div id="nickbox">
<label for="nickname" id="nicklabel">Nickname:</label>
<input type="text" id="nickname" value="" maxlength="20" size="20" role="textbox"
aria-label="Enter your nickname." data-lpignore="true" autofocus />
<input type="button" id="nicknameconfirm" value="Set" />
</div>
And my CSS:
#nickbox {
border: none;
display: inline;
padding: 5px;
background-color: #ffffff00;
align-self:center;
font-size: 2em;
}
#nickname {
background-color: #44475a;
border: none;
height: 2em;
width: 20em;
outline: none;
}
This is what the results look like. What can I do to change this? I assume I need to add some CSS to #nicklabel. Thanks.
Put vertical-align: middle; into #nickname
#nickname {
background-color: #44475a;
vertical-align: middle;
border: none;
height: 2em;
width: 20em;
outline: none;
}
http://jsfiddle.net/6xqgb0mu/
What about this?
#nickbox {
display: flex; /* Change display on parent */
border: none;
padding: 5px;
background-color: #fff;
font-size: 2em;
}
#nickname {
background-color: #44475a;
border: none;
height: 2em;
width: 20em;
outline: none;
align-self: center; /* Apply to child */
}
Use position: sticky; Like here: jsfiddle
#nicklabel{
top: 13px;
position: sticky;
}
I am working on some code that presents a form with a number of checkboxes. I would like to get the checkboxes to wrap to a second (and third, and fourth) line, but am having trouble doing so. At the moment, the checkboxes run straight off the page in a line without wrapping.
There are 10 (or more) checkboxes, but for the sake of brevity I've listed only a few of them since listing all of them wouldn't really add to the conversation:
My CSS:
.add-to-cart .attribute label {
display: inline;
padding-right: 35px;
}
.add-to-cart .form-checkboxes{
max-width: 600px;
height: 300px;
display: inline-flex;
}
.add-to-cart .attribute .form-item .form-type-checkbox {
position: absolute;
display: inline-block;
width: 100%;
height: 90px;
background-color: #ddd;
padding: 20px;
margin: 10px;
white-space: nowrap;
text-align: center;
vertical-align: middle;
font: bold 10px verdana, arial, 'Raleway', sans-serif;
font-style: italic;
}
My HTML/Code:
<div class="content">
<div class="add-to-cart">
<form class="ajax-cart-submit-form" action="/this-product" method="post" id="uc-product-add-to-cart-form-7" accept-charset="UTF-8">
<div class="attribute attribute-7 even">
<div class="form-item form-type-checkboxes form-item-attributes-7">
<label for="edit-attributes-7">Extras </label>
<div id="edit-attributes-7" class="form-checkboxes">
<div class="form-item form-type-checkbox form-item-attributes-7-49">
<input type="checkbox" id="edit-attributes-7-49" name="attributes[7][49]" value="49" class="form-checkbox" />
<label class="option" for="edit-attributes-7-49"> Blue </label>
</div>
<div class="form-item form-type-checkbox form-item-attributes-7-43">
<input type="checkbox" id="edit-attributes-7-43" name="attributes[7][43]" value="43" class="form-checkbox" />
<label class="option" for="edit-attributes-7-43"> Red </label>
</div>
<div class="form-item form-type-checkbox form-item-attributes-7-50">
<input type="checkbox" id="edit-attributes-7-50" name="attributes[7][50]" value="50" class="form-checkbox" />
<label class="option" for="edit-attributes-7-50"> Green </label>
</div>
</div>
</div>
</div>
</div>
</div>
Try this
.add-to-cart .attribute label {
display: inline;
padding-right: 35px;
}
.add-to-cart .form-checkboxes{
max-width: 600px;
height: 300px;
display: inline-flex;
}
.add-to-cart .attribute .form-checkboxes:not(.form-item) {
position: absolute;
display: inline-flex;
width: 100%;
height: 90px;
background-color: #ddd;
padding: 20px;
margin: 10px;
white-space: nowrap;
text-align: center;
vertical-align: middle;
font: bold 10px verdana, arial, 'Raleway', sans-serif;
font-style: italic;
}
live demo - https://jsfiddle.net/91r7v20q/
Well, I figured it out. I changed this CSS code:
.add-to-cart .form-checkboxes{
max-width: 600px;
height: 300px;
display: inline-flex;
}
To this:
.add-to-cart .form-checkboxes{
max-width: 600px;
display: inline-block;
}
I removed the fixed height to allow the block to be flexible in allowing the elements to be completely displayed before the last row (with the submit button, see comments on this questions). Whew!
I am trying to align the above elements in their divs evenly horizontally. In the above i'm trying to get 'high' and 'low' aligned so they are not up against the progress bar and are inline vertically. The checkboxes are fine but I used 'float:right' for the date - not ideal as this bumped it upward a little.
My html
<div class="show-for-small-only">
<div class="parents linkable">
<%= check_box_tag "homework[id][]", homework.id, checked = false, class: "narrowtr" %>
<%= link_to homeworks_engagement_view_item_path(:id => homework.id) do %>
<div class="progress-meter-interest-mobile horizTranslate linkable" data-bar-length="<%= homework.average_interest * 100 / 5 %>"><div class="text-center"><%= homework.average_interest %></div></div>
<font size="1" class="linkable mobile-center"><%= homework.significance.sig_option %></font>
<font size="1" class="linkable mobile-right"><strong><%= formatted_date(homework.due)%></strong></font>
</div>
<% end %>
<% end %>
My CSS:
.parents {
border-bottom: 20px;
background-color: white;
top: 0px;
margin:0px;
height: 60px;
padding: 15px 2px 2px 3px;
border-width: 2px;
border-bottom-width:1px;
border-bottom-color:Grey;
border-bottom-style: solid;
width: 100%;
}
.linkable{
color: black;
}
Div for bar:
.progress-meter-interest-mobile{
background-color: #FFD733;
height: 20px;
display: inline-block;
}
Aligned date with float:right...
.mobile-right{
float:right;
margin-right: 2px;
}
.mobile-center{
display: inline-block;
text-align: center;
margin-right: 6px;
background-color: #EEE;
}
.horizTranslate is just css animation for the bars.
It's the two middle elements i'm really stuck on - the bar and "high" and "low". I have tried display:inline and display:inline-block and playing around with different divs but can't seem to get it.
Any ideas? Appreciate any guidance.
You should check CSS Flexbox. It solved my issues quite a few times.
Flexbox Doc The following should help in your case
.container {
align-items:stretch;
}
Since you look for a table like layout, stay with your inline block and give them a width (and a minor markup change, where I swapped the progress/text tags)
Note, the font element is deprecated so I replaced it with a span
.parents {
margin-bottom: 10px;
height: 40px;
padding: 15px 2px 2px 3px;
border-bottom: 1px solid Grey;
width: 240px;
}
.linkable {
color: black;
}
.progress-meter-interest-mobile {
background-color: #FFD733;
height: 20px;
text-align: center;
}
.parents.linkable > * {
display: inline-block;
vertical-align: middle;
}
.progress-meter-interest-mobile.low {
width: 30px;
}
.progress-meter-interest-mobile.high {
width: 60px;
}
.parents.linkable > :nth-child(2) {
width: calc(100% - 130px);
}
.parents.linkable > :nth-child(3) {
width: 30px;
font-size: 11px;
}
.parents.linkable > :nth-child(4) {
width: 60px;
text-align: right;
font-weight: bold;
font-size: 11px;
}
<div class="show-for-small-only">
<div class="parents linkable">
<input type="checkbox">
<div>
<div class="progress-meter-interest-mobile low">2</div>
</div>
<span class="linkable">Low</span>
<span class="linkable">12/12/2016</span>
</div>
<div class="parents linkable">
<input type="checkbox">
<div>
<div class="progress-meter-interest-mobile high">4</div>
</div>
<span class="linkable">High</span>
<span class="linkable">12/12/2016</span>
</div>
</div>
Of course you can use flexbox, as suggested, though you still need to swap the markup to make the "meter" work properly as well as give each element a width so they align vertically.
.parents {
margin-bottom: 10px;
height: 40px;
padding: 15px 2px 2px 3px;
border-bottom: 1px solid Grey;
width: 240px;
}
.linkable {
color: black;
}
.progress-meter-interest-mobile {
background-color: #FFD733;
height: 20px;
text-align: center;
}
.parents.linkable {
display: flex;
align-items: center;
}
.progress-meter-interest-mobile.low {
width: 30px;
}
.progress-meter-interest-mobile.high {
width: 60px;
}
.parents.linkable > :nth-child(2) {
width: calc(100% - 130px);
}
.parents.linkable > :nth-child(3) {
width: 30px;
font-size: 11px;
}
.parents.linkable > :nth-child(4) {
width: 60px;
text-align: right;
font-weight: bold;
font-size: 11px;
}
<div class="show-for-small-only">
<div class="parents linkable">
<input type="checkbox">
<div>
<div class="progress-meter-interest-mobile low">2</div>
</div>
<span class="linkable">Low</span>
<span class="linkable">12/12/2016</span>
</div>
<div class="parents linkable">
<input type="checkbox">
<div>
<div class="progress-meter-interest-mobile high">4</div>
</div>
<span class="linkable">High</span>
<span class="linkable">12/12/2016</span>
</div>
</div>
I am no good in wrinting UIs in pure html... Right now I am trying to create a simple login page in pure html in css, but somehow I cannot get the Login button from here https://jsfiddle.net/2oxz5oja/ to be centered.
p {
display: table-row;
text-align: center;
}
Does this style work for table-row elements?
Could someone here give me an advice?
Sorry I'm having some issues with my Fiddle. So I've copy/pasted it here.
Try this:
HTML
<h3>Login here</h3>
<div id="loginMenu" class="mainDiv">
<form id="login-form" name="login-form" method="post" action="/konferencje-web/login.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="login-form" value="login-form" />
<p>
<label for="login-form:login" class="input-form">Login:</label>
<input id="login-form:login" type="text" name="login-form:login" class="input-form" />
</p>
<p>
<label for="login-form:password" class="input-form">Password:</label>
<input id="login-form:password" type="password" name="login-form:password" value="" class="input-form" />
</p>
<p>
<input id="login-form:button" class = "login" type="submit" name="login-form:button" value="Login" />
</p>
<p>
Info page
</p>
</form>
</div>
</html>
CSS
body {
background-color: #6B2424;
}
form {
display: table;
}
input {
display: table-cell;
margin: 0 auto;
}
label {
display: table-cell;
}
p {
display: table-row;
text-align: center;
}
li {
list-style-type: none;
line-height: 150%;
}
a {
color: #000000;
line-height: 30px;
vertical-align: middle;
text-align: center;
}
h1, h3 {
color: wheat;
font-size: 18px;
font-weight: bold;
text-align: center;
}
td {
text-align: center;
}
select {
min-width: 150px;
}
#login-form {
margin:0 auto;
text-align: center;
width: 50%
}
.mainDiv {
text-align: center;
background-color: bisque;
width: 500px;
border:2px solid;
border-radius:25px;
line-height: 30px;
vertical-align: middle;
margin:0 auto;
}
.login
{
position: relative;
left: 120px;
}
}
This is the Demo.
I want to align the two <p> element in the same line, but you can see the second one moves down a little bit. Anybody knows the reason?
HTML
<div class="logo">
<p>Hello world</p>
<p class="web_address">Hello all</p>
</div>
CSS
.logo p {
margin:0;
padding:0;
border: solid 1px black;
margin-left: 20px;
font-size: 36px;
display: inline-block;
line-height: 80px;
}
Inline(-block) elements (the paragraphs in this case) are aligned vertically in their baseline by default. You could add vertical-align: top; to fix the alignment issue.
Updated Demo.
.logo p {
/* other styles goes here... */
display: inline-block;
vertical-align: top;
}
For further details you can refer this answer.
<span> might be a better solution:
http://jsfiddle.net/Zxefz/
<div class="logo">
<span>Hello world</span>
<span class="web_address">Hello all</span>
</div>
.logo{
height: 80px;
border:1px solid red;
}
.logo span{
margin:0;
padding:0;
border: solid 1px black;
margin-left: 20px;
font-size: 36px;
display: inline;
line-height: 80px;
}
.logo .web_address{
font-size:26px;
}
the following worked for me:
.toptext {
display: flex;
align-items: center;
}
<div class="toptext">
<p>Please ensure all original documents requested are enclosed</p>
<p id="right">Claim Reference No.: <input type="text" name="" value=""></p>
</div>