I basically need the tab header which current holds values 1,2,3 I would like changed to a favicon logo but because they are label tabs it wont display here is my code:
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">
<section class="home" id="home">
<div class="home-text">
<h1>Horrizion Travel</h1>
</div>
<div class="my-tabs">
<input type="radio" id="tabfree" name="my-tabs" checked="checked">
<label for="tabfree" >1</label>
<div class="tab">
<h2>Air Travel</h2>
<P>This is Tab 1</P>
</div>
<input type="radio" id="tab-2" name="my-tabs">
<label for="tab-2">2</label>
<div class="tab">
<h2>Coach Travel</h2>
<P>This is Tab 2</P>
</div>
<input type="radio" id="tab-3" name="my-tabs">
<label for="tab-3">3</label>
<div class="tab">
<h2>Train Travel</h2>
<P>This is Tab 3</P>
</div>
</div>
</div>
</section>
I added and linked the favicon but it deletes the other tabs when I input it. I think this is because it selects the next lable in order to check it as they are css tabs.
<i class="fa-solid fa-tickets-airline"></i>
`
#dest .my-tabs{
display: flex;
flex-wrap: wrap;
max-width: 1400px;
margin: 50px auto;
padding: 25px;
}
#dest .my-tabs input[type="radio"] {
display: none;
}
#dest .my-tabs label{
padding: 25px;
background-color: #5a7184;
font-weight: bold;
}
#dest .my-tabs .tab{
width:100% ;
padding: 20px;
background-color: #5a7184;
order: 1;
display: none;
}
#dest .my-tabs h2{
font-size: 2em;
}
#dest .my-tabs input[type="radio"]:checked + label + .tab{
display: block;
}
#dest .my-tabs input[type="radio"]:checked + label{
background: var(--main-color);
}
`
Related
Hi i have the following code and i am trying to Color the background of the TDs inside this little Tab i created.
<body>
<nav class="nav_tabs">
<ul>
<li>
<input type="radio" name="tabs" class="rd_tabs" id="tab2">
<label for="tab1">Shutdown</label>
<div class="content">
I tried doing like this on the style sheet:
.nav_tabs #tab2 .content td
{
background: lightcyan;
}
I dont really understand what i am doing wrong but it is not working, i tried different things but nothing.
I cant post the content inside the article but it is mostly tables:
<style>
*
{
margin:0;
padding: 0;
}
body
{
font-family: Arial, Helvetica, sans-serif;
}
.nav_tabs
{
width: 600px;
height: 400px;
margin 100px auto;
background-color: #fff;
position: relative;
}
.nav_tabs ul
{
list-style: none;
}
.nav_tabs ul li
{
float: left;
}
.nav_tabs label
{
width: 100px;
padding: 25px;
background-color: #363b48;
display:block;
color: #fff;
cursor: pointer;
text-align: center;
}
.rd_tabs:checked ~ label
{
background-color: #e54e43;
}
.rd_tabs
{
display: none;
}
.content
{
border-top: 5px solid #e54e43;
background-color: #fff;
display: none;
position: absolute;
height: 320px;
width: 600px;
left: 0;
}
.content article
{
padding 10px;
}
.rd_tabs:checked ~ .content
{
display: block;
}
.nav_tabs .content td
{
background: lightcyan;
}
</style>
<body>
<nav class="nav_tabs">
<ul>
<li>
<input type="radio" name="tabs" class="rd_tabs" id="tab1"
checked>
<label for="tab1">tab1</label>
<div class="content">
<article>
</article>
</li>
<li>
<input type="radio" name="tabs" class="rd_tabs" id="tab2">
<label for="tab2">SHUTDOWN (MINIMUM CONFIGURATION)</label>
<div class="content">
<article>
</article>
</div>
</li>
<li>
<input type="radio" name="tabs" class="rd_tabs" id="tab3">
<label for="tab3">Tab3</label>
<div class="content">
<article>
</article>
</div>
</li>
</ul>
</nav>
</body>
try remove #tab2 in your css
.nav_tabs .content td
{
background: lightcyan;
}
i dont see in your html code something like that id='tab2' between your.nav_tabs and .content .
so probably that's why it doesnt work now
update
if you need change the color of tab2 for example
so you have to add id='tab2' to the <li> element
but it shouldn't be duplicate the id in inputs
How can I make these radio buttons responsive? I'm not sure what I'm doing wrong. I'd like to be able to click the grid item each option is in and have it behave like a radio button, but I'm not sure what I'm missing. Any recommendations for streamlining this code would also be extremely helpful. Thanks!
body {
font-family: Arial, Helvetica;
font-size: 3vh;
background-color: #b0b0b0;
}
.wrapper {
width: 50%;
margin-left: 25%;
margin-right: 25%;
display: grid;
grid-template-columns: 100px 100px 100px;
grid-gap: 20px;
grid-auto-rows: 100px;
justify-content: center;
background-color: ;
}
.item {
border-radius: 50px;
color: white;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.item input {
opacity: 0;
position: absolute;
/*this makes it not interfere with the text location*/
}
.item:nth-child(odd) {
background: gray;
}
.item:nth-child(odd):hover {
background: limegreen;
cursor: pointer;
}
.item:nth-child(odd):label {}
.wrapper h2 {
grid-row: 1;
grid-column: 1/-1;
}
<div id="trialDiv" style="font-size: 13pt;">
<div id="TrialQuestions">
<div id="Questions" class="wrapper">
<h2 style="text-align:center"><i>What emotion was the face expressing? </i></h2>
<div id="gap" class="item"></div>
<div id="HappyButton" class="item">
<label>
<p><input class="responseButton" id="emotion_1" name="emotion" onclick = "GrabEmotionClickTime()" type="radio" value="1" /> Happiness</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="AngryButton" class="item">
<label>
<p><input class="responseButton" id="emotion_2" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="2" /> Anger</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="FearButton" class="item">
<label>
<p><input class="responseButton" id="emotion_4" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="3" /> Fear</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="NeutralButton" class="item">
<label>
<p><input class="responseButton" id="emotion_4" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="4" /> Neutral</p>
</label>
</div>
</div>
</div>
</div>
Without doing all the work for you, your arrangement of elements is incorrect. Here is a simple example:
https://codepen.io/seanstopnik/pen/8a2ca693e9fe1f1334b921a6d75dbe99
/* For demo only */
body {
font-family: sans-serif;
padding: 40px;
}
/* Emotion button */
.emotion-button {
position: relative;
margin: 20px; /* For demo only */
}
.emotion-button__input {
position: absolute;
left: -9999px;
}
.emotion-button__label {
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
border-radius: 50%;
background-color: #ccc;
cursor: pointer;
transition: all 0.15s ease-in-out;
}
.emotion-button__input:checked ~ .emotion-button__label {
color: #fff;
background-color: green;
}
<div class="emotion-button">
<input id="r1" class="emotion-button__input" type="radio" name="emotion"/>
<label for="r1" class="emotion-button__label">Happiness</label>
</div>
<div class="emotion-button">
<input id="r2" class="emotion-button__input" type="radio" name="emotion"/>
<label for="r2" class="emotion-button__label">Anger</label>
</div>
Same idea as #SeanStopnik, did all the work for you:
body {
font-family: Arial, Helvetica;
font-size: 13pt;
background-color: #b0b0b0;
}
#Questions h2 {
font-style: italic;
}
.wrapper {
width: 50%;
margin-left: 25%;
margin-right: 25%;
display: grid;
grid-template-columns: 100px 100px 100px;
grid-gap: 20px;
grid-auto-rows: 100px;
justify-content: center;
background-color: ;
}
.item label {
display: block;
border-radius: 50%;
color: white;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
height: 80px;
background: gray;
}
.item label:hover {
background: lime;
}
.item input {
display: none;
}
.item input:checked + label {
background: blue;
}
.wrapper h2 {
grid-row: 1;
grid-column: 1/-1;
}
<div id="trialDiv">
<div id="TrialQuestions">
<div id="Questions" class="wrapper">
<h2 style="text-align:center">What emotion was the face expressing?</h2>
<div class="gap"></div>
<div id="HappyButton" class="item">
<input class="responseButton" id="emotion_1" name="emotion" type="radio" value="1" />
<label for="emotion_1">Happiness</label>
</div>
<div class="gap"></div>
<div id="AngryButton" class="item">
<input class="responseButton" id="emotion_2" name="emotion" type="radio" value="2" />
<label for="emotion_2">Anger</label>
</div>
<div class="gap"></div>
<div id="FearButton" class="item">
<input class="responseButton" id="emotion_3" name="emotion" type="radio" value="3" />
<label for="emotion_3">Fear</label>
</div>
<div class="gap"></div>
<div id="NeutralButton" class="item">
<input class="responseButton" id="emotion_4" name="emotion" type="radio" value="4" />
<label for="emotion_4">Neutral</label>
</div>
</div>
</div>
</div>
Explanation:
radio inputs are made invisible
they are placed right before their labels
labels are associated with them using for="id" attribute, so that clicking the label will check the radio button
I'm using the CSS pseudoclass :checked to target checked radio for styling
the CSS operator + allows to target the label right after the checked radio
Also:
you shouldn't have javascript event handlers in your HTML. Better use addEventListener from javascript for that. Your onclick made the click fail.
you shouldn't repeat ids in html
you shouldn't style your fonts inline
you shouldn't use <i> to make your titles italic. You should use CSS for that
Use font-style: italic; for the h2 element, nowdays <i> is used to insert icons
You can the id value only once in your HTML! Can't give more than one element the same id.
By clicking on the label we check the input, so we hide the input and style the label : width + height = 100%
We give all the inputs the same name to prevent checking more than one input[radio].
AddEventListener for all the inputs to toggle the class active on each one item (depends on which is the checked one).
Print to the console the id of the input that is checked.
var inputs = document.querySelectorAll('.item label');
for (let i = 0; i < inputs.length; i++){
inputs[i].addEventListener('click', (e) => {
checkEmotion(inputs[i], e);
});
}
function checkEmotion(input, e){
for(let i = 0; i < inputs.length; i++){
inputs[i].parentElement.classList.remove('active');
}
e.target.parentElement.classList.add('active');
console.log(input.nextElementSibling.getAttribute("id"));
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica;
background-color: #b0b0b0;
}
h2 {
margin: 20px 0;
font-style: italic;
}
.wrapper {
display: flex;
justify-content: center;
}
.item {
border-radius: 50px;
color: white;
display: flex;
align-items: center;
justify-content: center;
width: 90px;
height: 90px;
margin: 0 10px;
background: gray;
position: relative;
overflow: hidden;
transition: all 0.2s;
}
.item.active {
background: #121212;
}
.item input {
opacity: 0;
display: absolute;
height: 0;
width: 0;
}
.item label {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.item:hover {
background: limegreen;
}
<h2 style="text-align:center">What emotion was the face expressing?</h2>
<div class="wrapper">
<div class="item">
<label for="emotion-happy">Happy</label>
<input type="radio" id="emotion-happy" name="emotion">
</div>
<div class="item">
<label for="emotion-sad">Sad</label>
<input type="radio" id="emotion-sad" name="emotion">
</div>
<div class="item">
<label for="emotion-angry">Angry</label>
<input type="radio" id="emotion-angry" name="emotion">
</div>
<div class="item">
<label for="emotion-confused">Confused</label>
<input type="radio" id="emotion-confused" name="emotion">
</div>
</div>
I have this source code. It's supposed to switch between tabs after clicking on any of the buttons. Everything works fine but when I try to wrap buttons in div it stops working and it doesnt display content anymore.
.main {
margin: 0 auto;
min-width: 320px;
max-width: 800px;
}
.content {
background: #fff;
color: #373737;
}
.content>div {
display: none;
padding: 20px 25px 5px;
}
input {
display: none;
}
label {
display: inline-block;
padding: 15px 25px;
font-weight: 600;
text-align: center;
}
label:hover {
color: #fff;
cursor: pointer;
}
input:checked+label {
background: #ed5a6a;
color: #fff;
}
#tab1:checked~.content #content1,
#tab2:checked~.content #content2,
#tab3:checked~.content #content3,
#tab4:checked~.content #content4 {
display: block;
}
<div class="main">
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">111</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">222</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">333</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4">444</label>
<div class="content">
<div id="content1">
<p>
111
</p>
</div>
<div id="content2">
<p>
222
</p>
</div>
<div id="content3">
<p>
333
</p>
</div>
<div id="content4">
<p>
444
</p>
</div>
</div>
</div>
The code above is working, but I would like to wrap this part in div:
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">111</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">222</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">333</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4">444</label>
The issue is that you are changing the document structure and this selector:
#tab1:checked ~ .content #content1,
#tab2:checked ~ .content #content2,
#tab3:checked ~ .content #content3,
#tab4:checked ~ .content #content4 {
display: block;
}
no longer matches the content areas. I can't think of a selector that would work because the addition of the new div breaks the sibling relationship between the tabs and the content.
However, you can add your div and make the code much simpler if you abandon the hidden radio buttons and the labels and just use a elements that target the content area that is supposed to be displayed. Then the CSS :target pseudo-class can be used to display the current content area that is the target of the clicked link.
Additionally, it's not clear why you have the actual content in a p that is inside of the div. That doesn't seem necessary.
<!doctype html>
<html lang="en">
<head>
<style>
.main {margin: 0 auto; min-width: 320px; max-width: 800px;}
.content {background: #fff; color: #373737;}
.content > div {display: none; padding: 20px 25px 5px;}
a {display: inline-block; padding: 15px 25px; font-weight: 600; text-align: center;}
a:hover {color: #fff; cursor: pointer;}
a:link {background: #ed5a6a; color: #fff; text-decoration:none; }
.content > :target
{
display: block;
}
</style>
</head>
<body>
<div class="main">
<div id="parent">
111
222
333
444
</div>
<div class="content">
<div id="content1">111</div>
<div id="content2">222</div>
<div id="content3">333</div>
<div id="content4">444</div>
</div>
</div>
</body>
</html>
I found this code on the internet which is fine but I want the section tags first then the inputs, I tried so many times to move the tabs navigation below the content without success.
section {
display: none;
padding: 20px 0 0;
border-top: 1px solid #ddd;
}
input {
display: none;
}
input:checked+label {
color: #ff0000;
}
#tab1:checked~#content1,
#tab2:checked~#content2,
#tab3:checked~#content3,
#tab4:checked~#content4 {
display: block;
}
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">home</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">about</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">FAQ</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4">contact</label>
<section id="content1">
<p>home</p>
</section>
<section id="content2">
<p>about</p>
</section>
<section id="content3">
<p>FAQ</p>
</section>
<section id="content4">
<p>contact</p>
</section>
Any ideas how to move the navigation bar below the content
Thank you
You could try that as below, wrap the section tags by a div and then you could change the positioning of label using position:absolute,
section {
display: none;
padding: 0px 0 0;
border-bottom: 1px solid #ddd;
}
input {
display: none;
}
input:checked+label {
color: #ff0000;
}
#tab1:checked~.wr #content1{
display:block;
}
#tab2:checked~.wr #content2{
display:block;
}
#tab3:checked~.wr #content3{
display:block;
}
#tab4:checked~.wr #content4{
display:block;
}
.wr{
position:relative;
top:0;
display:block;
}
.tb1{
position:absolute;
top:80px;
display:inline-block;
}
.tb2{
position:absolute;
top:80px;
display:inline-block;
left:60px;
}
.tb3{
position:absolute;
top:80px;
display:inline-block;
left:120px;
}
.tb4{
position:absolute;
top:80px;
display:inline-block;
left:180px;
}
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1" class="tb1">home</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2" class="tb2">about</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3" class="tb3">FAQ</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4" class="tb4">contact</label>
<div class="wr">
<section id="content1">
<p>home</p>
</section>
<section id="content2">
<p>about</p>
</section>
<section id="content3">
<p>FAQ</p>
</section>
<section id="content4">
<p>contact</p>
</section>
</div>
Use Navbar technique with <div id="home">.
It will be easy.
Or you can use javascript to make it look more refined.
body {margin:0;}
.navbar {
overflow: hidden;
background-color: #fff;
position: fixed;
bottom: 0;
width: 100%;
}
.navbar a {
float: left;
display: block;
color: #000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.main {
padding: 16px;
margin-bottom: 30px;
height: 1500px; /* Used to enable scrolling */
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="navbar">
Home
About
</div>
<div id="home"class="main">
<h1>Home</h1>
</div>
<div id="about"class="main">
<h1>About</h1>
</div>
</body>
</html>
I have changed your code. Please try this code.
a:focus {
outline: none!important;
}
.content-wrap {
background:#eee;
padding:20px;
margin-bottom:10px;
}
.tabs-bottom > .nav-tabs{
border-bottom: 0;
}
.tabs-below > .nav-tabs {
border-bottom: 0;
}
.tab-content > .tab-pane,
.pill-content > .pill-pane {
display: none;
}
.tab-content > .active,
.pill-content > .active {
display: block;
}
.tabs-bottom > .nav-tabs {
border-top: 1px solid #ddd;
}
.tabs-bottom > .nav-tabs > li {
margin-top: -1px;
margin-bottom: 0;
}
.tabs-bottom > .nav-tabs > li > a {
border-radius: 0 0 4px 4px;
}
.tabs-below > .nav-tabs > li > a:hover,
.tabs-below > .nav-tabs > li > a:focus {
border-top-color: #ddd;
border-bottom-color: transparent;
}
.tabs-bottom > .nav-tabs > .active > a,
.tabs-bottom > .nav-tabs > .active > a:hover,
.tabs-bottom > .nav-tabs > .active > a:focus {
border-color: transparent #ddd #ddd #ddd;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-xs-12">
<!-- tabs -->
<div class="tabbable tabs-bottom">
<div class="tab-content">
<div class="tab-pane active" id="home">
<div class="content-wrap">
<h2>Home Tab</h2>
<p>test</p>
</div>
</div>
<div class="tab-pane" id="about">
<div class="content-wrap">
<h2>About Tab</h2>
<p>test</p>
</div>
</div>
<div class="tab-pane" id="services">
<div class="content-wrap">
<h2>Services Tab</h2>
<p>test</p>
</div>
</div>
<div class="tab-pane" id="contact">
<div class="content-wrap">
<h2>Contact Tab</h2>
<p>test</p>
</div>
</div>
</div>
<!-- tab content -->
<ul class="nav nav-tabs">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
<!-- /tabs -->
</div>
</div>
</div>
you just need to use CSS display flex for reorder the content :
https://codepen.io/seltix/pen/XaLVaY
<dix id="blockcontainer" >
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">home</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">about</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">FAQ</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4">contact</label>
<div class="divider"></div>
<section id="content1">
<p>home</p>
</section>
<section id="content2">
<p>about</p>
</section>
<section id="content3">
<p>FAQ</p>
</section>
<section id="content4">
<p>contact</p>
</section>
</div>
CSS :
section {
display: none;
padding: 20px;
border-bottom: 1px solid #AAA;
background :#EEE;
}
div.divider {
width:100%;
}
input {
display: none;
}
label {
padding: 10px;
}
input:checked + label {
color: #ff0000;
}
#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3,
#tab4:checked ~ #content4 {
display: block;
}
#blockcontainer {
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
}
section {
-ms-flex-order: 1;
order: 1;
}
div.divider {
-ms-flex-order: 6;
order: 6;
}
input, label {
-ms-flex-order: 12;
order: 12;
}
I have a carousel created with only CSS, but I have identified some difficulties. All images are in the 4:3 aspect ratio and may have a maximum of 640x480 px (that is, they can be smaller than this value), so:
I can not center the next and previous arrows;
The arrows can not be "floating" on the screen (if the next image is
smaller than the previous one, the arrows should not change
position);
I do not know how to set the size of the carousel according to the
largest image currently used.
The code:
html {
font-size: 10px;
}
body {
padding: 2rem;
background: #F8F8F8;
font-size: 16px;
}
.wrap {
max-width: 70rem;
margin: auto;
padding: 2rem;
background: #FFF;
}
.carousel {
position: relative;
display: -webkit-box;
display: flex;
max-width: 64rem;
min-height: 40rem;
margin: auto;
background: red;
-webkit-box-pack: center;
justify-content: center;
}
.group {
display: -webkit-box;
display: flex;
background: blue;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.group input {
position: absolute;
top: -100%;
left: -100%;
display: none;
}
.group input ~ .content {
/* tentar fixar tamanho aqui */
display: none;
-webkit-box-ordinal-group: 3;
order: 2;
}
div.group input:checked ~ div.content {
display: block;
}
div.group input:checked ~ label.previous,
div.group input:checked ~ label.next {
display: block;
}
div.group label {
top: 50%;
display: none;
width: 50px;
height: 50px;
border: solid 1px black;
background-color: #69C;
transform: translateY(-50%);
}
img {
width: 100%;
height: 100%;
}
label {
margin: 125px 0 0 0;
font-size: 4em;
}
label.previous {
padding: 0 0 30px 5px;
-webkit-box-ordinal-group: 2;
order: 1;
}
label.next {
padding: 0 5px 25px 0;
text-align: right;
-webkit-box-ordinal-group: 4;
order: 3;
}
<!DOCTYPE html>
<html>
<head>
<title>Teste 3</title>
<link rel="stylesheet" type="text/css" href="teste3.css">
<meta charset="utf-8">
</head>
<body>
<div class="wrap">
<div class="carousel">
<div class="group">
<input type="radio" name="test" id="0" value="0">
<label for="4" class="previous"><</label>
<label for="1" class="next">></label>
<div class="content">
<img src="https://www.oneperiodic.com/products/photobatch/tutorials/img/scale_original.png" width="200" height="286">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="1" value="1">
<label for="0" class="previous"><</label>
<label for="2" class="next">></label>
<div class="content">
<img src="https://www.ausmedia.com.au/Mmedia/4TO3.gif" width="200" height="139">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="2" value="2">
<label for="1" class="previous"><</label>
<label for="3" class="next">></label>
<div class="content">
<img src="http://www.cegepsherbrooke.qc.ca/~cpi/images/photo_4-3.jpg" width="140" height="200">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="3" value="3" checked="">
<label for="2" class="previous"><</label>
<label for="4" class="next">></label>
<div class="content">
<img src="http://www.projectorcentral.com/images/articles/4-3%20Bristlecone%20Pines.jpg" width="200" height="287">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="4" value="4">
<label for="3" class="previous"><</label>
<label for="0" class="next">></label>
<div class="content">
<img src="http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-951.jpg" width="96" height="139">
</div>
</div>
</div>
</div>
</body>
</html>
Can anyone help me find a solution or at least a balance in the measurements?
From what I understood,
You did not add
position: absolute to labels.
changed top to 18% to have them in center.
prev with left:0;
next with right:0;
This will set your labels as per the carousel, as it has the position relative.
html{
font-size: 10px;
}
body {
padding: 2rem;
background: #F8F8F8;
font-size: 16px;
}
.wrap {
max-width: 70rem;
margin: auto;
padding: 2rem;
background: #FFF;
}
.carousel {
position: relative;
display: -webkit-box;
display: flex;
max-width: 64rem;
min-height: 40rem;
margin: auto;
background: red;
-webkit-box-pack: center;
justify-content: center;
}
.group {
display: -webkit-box;
display: flex;
background: blue;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.group input {
position: absolute;
top: -100%;
left: -100%;
display: none;
}
.group input ~ .content {
/* tentar fixar tamanho aqui */
display: none;
-webkit-box-ordinal-group: 3;
order: 2;
}
div.group input:checked ~ div.content {
display: block;
}
div.group input:checked ~ label.previous,
div.group input:checked ~ label.next {
display: block;
}
div.group label {
position:absolute;
top: 18%;
display: none;
width: 50px;
height: 50px;
border: solid 1px black;
background-color: #69C;
transform: translateY(-50%);
}
img {
width: 100%;
height: 100%;
}
label {
margin: 125px 0 0 0;
font-size: 4em;
}
label.previous {
padding: 0 0 30px 5px;
-webkit-box-ordinal-group: 2;
order: 1;
left:0;
}
label.next {
padding: 0 5px 25px 0;
text-align: right;
-webkit-box-ordinal-group: 4;
order: 3;
right:0;
}
<!DOCTYPE html>
<html>
<head>
<title>Teste 3</title>
<link rel="stylesheet" type="text/css" href="teste3.css">
<meta charset="utf-8">
</head>
<body>
<div class="wrap">
<div class="carousel">
<div class="group">
<input type="radio" name="test" id="0" value="0">
<label for="4" class="previous"><</label>
<label for="1" class="next">></label>
<div class="content">
<img src="https://www.oneperiodic.com/products/photobatch/tutorials/img/scale_original.png" width="200" height="286">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="1" value="1">
<label for="0" class="previous"><</label>
<label for="2" class="next">></label>
<div class="content">
<img src="https://www.ausmedia.com.au/Mmedia/4TO3.gif" width="200" height="139">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="2" value="2">
<label for="1" class="previous"><</label>
<label for="3" class="next">></label>
<div class="content">
<img src="http://www.cegepsherbrooke.qc.ca/~cpi/images/photo_4-3.jpg" width="140" height="200">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="3" value="3" checked="">
<label for="2" class="previous"><</label>
<label for="4" class="next">></label>
<div class="content">
<img src="http://www.projectorcentral.com/images/articles/4-3%20Bristlecone%20Pines.jpg" width="200" height="287">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="4" value="4">
<label for="3" class="previous"><</label>
<label for="0" class="next">></label>
<div class="content">
<img src="http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-951.jpg" width="96" height="139">
</div>
</div>
</div>
</div>
</body>
</html>
Couple issues with your code Bianca. First off when we write HTML, it's best to leave out width and height properties within the actual html. The reason for this is that the browser will consider anything in your html as more important than external css files. We call this inline-styling or inline-styles when CSS is written directly into HTML. (Here's a good explanation of the hierarchy of CSS: Inline <style> tags vs. inline css properties )
Secondly, I updated your code, and included a max-width property to the content div, wherein your images are wrapped (the controlling css). So you can set that max-width to whatever you need, and it happens to work in this case.
Here's a Codepen: http://codepen.io/0rfila/pen/JbKrwj
And your updated code:
CSS:
html {
font-size: 10px;
}
body {
padding: 2rem;
background: #F8F8F8;
font-size: 16px;
}
.wrap {
max-width: 70rem;
margin: auto;
padding: 2rem;
background: #FFF;
}
.carousel {
position: relative;
display: -webkit-box;
display: flex;
max-width: 64rem;
min-height: 40rem;
margin: auto;
background: red;
-webkit-box-pack: center;
justify-content: center;
}
.group {
display: -webkit-box;
display: flex;
position: relative;
background: blue;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.group input {
position: absolute;
top: -100%;
left: -100%;
display: none;
}
.group input ~ .content {
/* tentar fixar tamanho aqui */
display: none;
-webkit-box-ordinal-group: 3;
order: 2;
}
div.group input:checked ~ div.content {
display: block;
}
div.group input:checked ~ label.previous,
div.group input:checked ~ label.next {
display: block;
}
div.group label {
top: 50%;
display: none;
width: 50px;
height: 50px;
border: solid 1px black;
background-color: #69C;
transform: translateY(-50%);
}
img {
width: 100%;
height: 100%;
}
label {
margin: 125px 0 0 0;
font-size: 4em;
}
label.previous {
padding: 0 0 30px 5px;
-webkit-box-ordinal-group: 2;
order: 1;
}
label.next {
padding: 0 5px 25px 0;
text-align: right;
-webkit-box-ordinal-group: 4;
order: 3;
}
.content {
max-width: 400px;
}
HTML:
<!DOCTYPE html>
<head>
<title>Teste 3</title>
<link rel="stylesheet" type="text/css" href="teste3.css">
<meta charset="utf-8">
</head>
<body>
<div class="wrap">
<div class="carousel">
<div class="group">
<input type="radio" name="test" id="0" value="0">
<label for="4" class="previous"><</label>
<label for="1" class="next">></label>
<div class="content">
<img src="https://www.oneperiodic.com/products/photobatch/tutorials/img/scale_original.png">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="1" value="1">
<label for="0" class="previous"><</label>
<label for="2" class="next">></label>
<div class="content">
<img src="https://www.ausmedia.com.au/Mmedia/4TO3.gif">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="2" value="2">
<label for="1" class="previous"><</label>
<label for="3" class="next">></label>
<div class="content">
<img src="http://www.cegepsherbrooke.qc.ca/~cpi/images/photo_4-3.jpg">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="3" value="3" checked="">
<label for="2" class="previous"><</label>
<label for="4" class="next">></label>
<div class="content">
<img src="http://www.projectorcentral.com/images/articles/4-3%20Bristlecone%20Pines.jpg">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="4" value="4">
<label for="3" class="previous"><</label>
<label for="0" class="next">></label>
<div class="content">
<img src="http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-951.jpg">
</div>
</div>
</div>
</div>
</body>
</html>