So, I am new to programming (3rd day) and I got a problem with my buttons.
The thing is I want each button to be next to other, not above.
I have tried using all kinds of position. But none of them works.
My css:
#about {
margin: 0 auto;
width: 200px;
border:navy solid;
display: block;
}
#forum {
margin: 0 auto;
width: 200px;
border:navy solid;
display: block;
}
#shop {
margin: 0 auto;
width: 200px;
border:navy solid;
display: block;
}
Html:
<ul>
<div id="about">About</div>
<div id="forum">Forums</div>
<div id="shop">Shop</div>
</ul>
What am I doing wrong? (Sorry for my bad english).
Since you are using the same style on all the elements, you can use a class instead of id.
HTML
<input type="button" class='classname' />
<input type="button" class='classname' />
<input type="button" class='classname' />
CSS
.classname {
margin: 0 auto;
width: 200px;
border:navy solid;
display: inline-block;
}
That you need to change is:
display: block;
To
display: inline-block;
I'm guessing your buttons are being centered in a column on the page currently.
Try this:
HTML
<ul id="button_list">
<li class="button" id="about">About</li>
<li class="button" id="forum">Forum</li>
<li class="button" id="shop">Shop</li>
</ul>
CSS
#button_list {
padding-left: 0px;
}
#button_list li {
list-style: none;
display: inline;
margin-right: 10px;
}
Fiddle: http://jsfiddle.net/patrickbeeson/v9307r0f/
Related
Today, I am comming with a problem from work. First of all, the code was created some time ago and I have to correct it now. Of course I've made the sandbox easier to avoid unnecessary styles.
<div>
<a id="perfect" href="https://css-tricks.com/">
<span class="perfect">
<p>Perfect</p>
</span>
<span class="maker">Solution</span>
</a>
</div>
<div>
<a href="https://css-tricks.com/">
<span class="problem">Problem</span>
<span class="maker">Makes me cry</span>
</a>
</div>
<div>
<a href="https://css-tricks.com/">
<span class="problem">Problem</span>
<span class="maker">Makes me cry</span>
</a>
</div>
div {
display: block;
width: 150px;
height: 150px;
background: lightblue;
text-align: center;
float: left;
margin: 10px;
}
a {
display: block;
width: 150px;
height: 150px;
text-decoration: none;
color: black;
}
.problem {
display: block;
padding: 30px 10px 0;
}
.maker {
display: block;
padding: 20px 10px 0;
}
p {
padding: 0;
margin: 0;
}
p:hover {
color: red;
}
I have three tile there. First of all works what I expect, but I would like to receive the same result on the second and third tile without paragraph.
The clue is that red color appears, if I put a mouse on random place above right content. I mean all span called "problem" is on hover.
How to ensure a similar behaviour like in first tile on the others without using paragraph? Do you have some idea?
I've tried to do that using margin, but it was wrong.
Try to add this into your stylesheets:
div > a > span:hover {
color: red;
}
Here is a solution:
Your issue is that your applying padding: 30px 10px 0; to span. The link is applying itself to the entire span with its padding.
I removed padding on your span and instead applied it to the div. - You can now adjust the padding on the div instead of the span.
Additionally, I moved the #perfect id to the first div because it had a different background-color.
div {
display: block;
width: 150px;
height: 150px;
background: lightblue;
text-align: center;
float: left;
margin: 10px;
padding: 30px 10px 0;
}
a {
display: block;
width: 150px;
height: 150px;
text-decoration: none;
color: black;
}
.problem {
display: block;
}
.problem:hover {
color: red;
}
.maker {
display: block;
}
p {
padding: 0;
margin: 0;
}
p:hover {
color: red;
}
.perfect {
display: block;
}
#perfect {
background-color: pink;
}
<div id="perfect">
<a href="https://css-tricks.com/">
<span class="perfect">
<p>Perfect</p>
</span>
<span class="maker">Solution</span>
</a>
</div>
<div>
<a href="https://css-tricks.com/">
<span class="problem">Problem</span>
<span class="maker">Makes me cry</span>
</a>
</div>
<div>
<a href="https://css-tricks.com/">
<span class="problem">Problem</span>
<span class="maker">Makes me cry</span>
</a>
</div>
Just change the display for the .problem from 'block' to 'inline-block', change the padding-top to 0 and give a margin-top of 30px
.problem {
display: inline-block;
padding: 0px 10px 0;
margin-top: 30px;
}
.problem:hover {
color: red;
}
I am trying to center-align a block of page numbers at the bottom of this page. The HMTL and CSS looks like this:
.pt-cv-pagination-wrapper {
position: relative;
display: block;
text-align: center;
margin: 20px 0;
padding: 0;
}
.pt-cv-pagination {
position: static;
display: inline-block;
text-align: center;
margin: 20px 0;
padding: 0;
}
li {
position: relative;
display: inline;
text-align: center;
margin: 0;
padding: 0;
}
.pt-cv-pagination a {
position: relative;
display: block;
float: left;
padding: 6px 12px;
margin: 1em;
}
<div class="pt-cv-pagination-wrapper">
<ul class="pt-cv-pagination pt-cv-ajax pagination" data-totalpages="3" data-currentpage="1" data-sid="98f4b5c3fg" data-unid="">
<li class="cv-pageitem-prev">
<a title="Go to previous page">‹</a>
</li>
<li class="cv-pageitem-number">
<a title="Go to page 1">1</a>
</li>
<li class="cv-pageitem-number">
<a title="Go to page 2">2</a>
</li>
<li class="cv-pageitem-number active">
<a title="Current page is 3">3</a>
</li>
<li class="cv-pageitem-next active">
<a title="Go to next page">›</a>
</li>
</ul>
<div class="clear pt-cv-clear-pagination"></div>
</div>
If you look on a narrow screen (on the live site), it will be easier to see that the page numbers are very slightly off centre. I've read several articles on here that all make sense but seem to have no further effect on my outcome. It's driving me crazy trying figure out why it's not working. Any help appreciated!
Ah, the art of centering elements in CSS. Good thing we have flexbox to help us all out.
This should do the trick:
.pt-cv-pagination-wrapper .pt-cv-pagination.pagination {
display: flex;
justify-content: center;
}
The centering looks fine. If you want to have a border on the <li> then change the inline of the li in an inline-block.
.pt-cv-pagination li {
position: relative;
display: inline-block;
text-align: center;
margin: 0;
padding: 0;
}
Remove the float from the <a> to have the block on this anchor working the correct way.
.pt-cv-pagination a {
position: relative;
display: block;
padding: 6px 12px;
margin: 1em;
}
Here is the HTML markup
<div class='container'>
<li class="options list-unstyled">
<div class="rank-label">
<span class="rank theme-inverse-color">1</span>
<span class="name">AAAAA</span>
<div class="move-btns">
<button type="button" class="btn btn-icon btn-up"><span class="icon icon-down">Down</span></button>
<button type="button" class="btn btn-icon btn-down"><span class="icon icon-up">Up</span></button>
</div>
</div>
</li>
</div>
And here is the less (css) code
.square (#size) {
width: #size;
height: #size;
}
.options {
li {
display: block;
width: 100%;
margin-bottom: 5px;
}
}
.container {
width: 50%;
border: 1px solid red;
}
.options {
font-size: 30px;
}
.text {
.flex-grow(1);
.align-items(center);
.justify-content(center);
}
.inverse-color {
color: blue;
}
.rank {
margin: auto;
padding-top: 2px;
display: inline-block;
.align-items(center);
.justify-content(center);
text-align: center;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 50%;
.square(40px);
min-width: 40px;
margin-right: 10px;
}
.rank-label {
.display(flex);
}
.btn {
margin: 10px;
border: 1px solid red;
}
.name {
.display(flex);
.flex-grow(1);
.align-items(center);
padding-right: 30px;
min-height: 35px;
}
.move-btns {
.display(flex);
.flex-basis(auto);
.flex-shrink(0);
.flex-grow(0);
.justify-content(center);
}
So in browsers like chrome, Safari and IE11, the output looks exactly like I expected:
However in IE10, the alignment is off. It has somehow become:
the number and text 'AAAAA' are all shifted to right-hand side.
I have tried tweaking flex-grow and other parameters but they have no effect.
How can I fix this issue?
Here is a link to the code in codepen.io: http://codepen.io/kongakong/pen/bpygoV
I think all you need to do is turn on the autoprefixer in your code pen css settings and it will start working. Basically E10 runs on the old version of the flexbox syntax. So it needs the vendor prefixes. Good Luck.
Thanks to #orangeh0g 's answer, I checked the css generated by autoprefixer in my codepen code. I find that I only need to add
-ms-flex-positive: 1;
to the text css class and the misalignment will be fixed.
I have a menu made up of 5 links. I need each link to be 33% of the available width with spacing between the links. The horizontal and vertical spacing must be the same.
Links must be the same height as the tallest link in there row, even though the length of the link text will vary per link. Ideally all links would be the same height but I doubt this is possible.
The link text is dynamic and will change. This for a responsive website so the page width will vary.
I cant change the HTML at all.
This is for a mobile only website so I dont need to worry about older browsers. I should be fine to use flexbox.
<ul>
<li>
<a href="#">
<span>Link 1</span>
</a>
</li>
<li>
<a href="#">
<span>Link 2 has much longer text than the other links</span>
</a>
</li>
<li>
<a href="#">
<span>Link 3</span>
</a>
</li>
<li>
<a href="#">
<span>Link 4</span>
</a>
</li>
<li>
<a href="#">
<span>Link 5</span>
</a>
</li>
</ul>
My code below works fine in Chrome. The only thing I still need to do is vertically center the link text (see the image below).
The align-items: center property looked promising however If I apply it to the ul then the lis' stop being the same height.
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
ul {
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
width: 50%;
border: 2px solid black;
margin: auto;
}
li {
list-style-type: none;
float: left;
width: 32%;
background: grey;
text-align: center;
overflow: hidden;
margin-bottom: 2%;
vertical-align: middle;
}
li:nth-of-type(2),
li:nth-of-type(5)
{
margin-left: 2%;
margin-right: 2%;
}
a {
display: inline-block;
margin: -10em;
padding: 10em;
}
a {
background: gold;
}
a:hover {
background: green;
}
http://codepen.io/anon/pen/CeiqK
I don't know if this solution that I post here will be valid for you. Anyway, I changed your css a bit to get it:
ul {
margin: 0;
padding: 0;
width: 50%;
border: 2px solid black;
margin: 0 auto;
font-size: 0; /* this fix inline-block margins */
}
li {
font-size: 14px;
list-style-type: none;
display: inline-block;
width: 32%;
min-height: 34px;
background: grey;
text-align: center;
overflow: hidden;
margin-bottom: 2%;
}
a {
display: table-cell;
width: 100em;
height: 34px;
vertical-align: middle;
}
Check it at codepen
Creates this:
I have a question about making a button show image
For example, I have four buttons
I want Each button showing image in the same content for images
In other words:
When you press one of the buttons show you image
here is an example: https://jsfiddle.net/i5yal/yvCtQ/1/
<div id="section-container">
<div class="section-img-container"><a>images will appear here</a>
</div>
</div>
<div id="section-button-container"><div>
<div class="section-button1"><a>1</a>
</div>
<div class="section-button2"><a>2</a>
</div>
<div class="section-button3"><a>3</a>
</div>
<div class="section-button4"><a>4</a>
</div>
</div>
</div>
CSS code:
#section-container {
background-color: #C0C0C0;
width: 300px;
height: 300px;
margin:0 auto;
}
#section-button-container {
width: 300px;
height: 30px;
margin:0 auto;
}
.section-button1 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 30px;
margin-right: 20px;
}
.section-button2 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 20px;
margin-right: 20px;
}
.section-button3 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 20px;
margin-right: 20px;
}
.section-button4 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 20px;
margin-right: 20px;
}
.section-img-container {
background-color: #008080;
background-position: center center;
width: 270px;
height: 270px;
margin: 0 auto;
}
To avoid using JavaScript, it's possible to use CSS (albeit there has to be some minor adjustments to your HTML in order to do so); so given the amended HTML:
<div id="section-container">
<div class="section-img-container">
<input type="radio" name="images" id="img1" />
<img src="http://placekitten.com/300/300/" />
<input type="radio" name="images" id="img2" />
<img src="http://lorempixel.com/300/300/nightlife" />
<input type="radio" name="images" id="img3" />
<img src="http://lorempixel.com/300/300/people" />
<input type="radio" name="images" id="img4" />
<img src="http://dummyimage.com/300x300/000/f90.png&text=image+lorem+ipsum" />
</div>
</div>
<div id="section-button-container"><div>
<div class="section-button1">
<label for="img1">1</label>
</div>
<div class="section-button2">
<label for="img2">2</label>
</div>
<div class="section-button3">
<label for="img3">3</label>
</div>
<div class="section-button4">
<label for="img4">4</label>
</div>
</div>
</div>
And the following CSS:
#section-button-container label {
display: block;
text-align: center;
height: 100%;
line-height: 30px;
cursor: pointer;
}
input[type=radio],
input[type=radio] + img {
display: none;
}
input:checked + img {
display: block;
}
JS Fiddle demo.
This does require that the browser supports the :checked pseudo-selector and the CSS next-sibling + combinator, however; and takes advantage of the label being able to check/uncheck a radio input (so long as the for attribute of the label identifies the id of the relevant input).
References:
:checked pseudo-selector`.
:checked pseudo-selector compatibility.
For the animation portion investigate this library, used it myself and it works nicely => animate.css
for the changing of the image it is rather trivial here is one way to do it.
$(document).ready(function() {
var viewer = $('img.viewer');
$('a.section-button').click(function () {
viewer.attr('src', 'your new path to new image');
});
});
In the above I added the classes that would be attached to the main view area so you'd have:
<img class="veiwer" />.
You'd just hide this or load up a default image when the page loads.
Also using "section-button" class on each anchor. I didn't account for positioning in the list of choices there meaning 1, 2, 3, 4th picture and so on. It might be easiest to have data-attributes for that on the section buttons. So something like.
<a class="section-button" data-imgrc="path to the large image" data-number="1">1</a>
Note you could also if you just have numbers inside the section buttons just grabber the inner text however personally I prefer data-attributes.