I have created a Pagination which will show/hide div based on the active Page as here https://jsfiddle.net/bogaso/qh7cpxzv/11/
However, I failed to apply style on the Navigation bar. Particularly I want to apply below two styles at the minimum level:
I want the Navigation bar will stay at the center of the page, with specific margin at top
Furthermore I want to apply border around each page number as in https://www.w3schools.com/css/tryit.asp?filename=trycss_ex_pagination_border_round
However when I try to wrap the <a> tag with some <div>, I lost all control in the navigation, i.e. below code fails to apply any style
<div class = 'Top'>
1
2
3
4
7
6
</div>
Any help on how to apply Style in the navigation bar would be highly appreciated.
Also is it possible to implement the same based solely on HTML + CSS?
The main problem with your CSS code is at the beginning.
You are adding a rule to hide all div elements, and this is causing the problem when you wrap the <a> tags with a div.
The solution is to apply the CSS hiding only for the page elements.
So, remove the CSS rule at the top and style the AAA class instead:
.AAA {
display: none;
height: 120px;
width: 120px;
}
.AAA.active { display: block; }
To center the pagination controls, I recommend using the Flexible Box Layout Module, aka flex.
This would be the CSS rule to center the pagination and keep its margin:
.Top {
display: flex;
margin: 10px 0;
justify-content: center;
}
As for your question, it isn't possible to do this using only CSS and HTML, at least not in a good way. CSS shouldn't dictate the behaviour of a webpage.
For your development, I really suggest learning proper HTML style guide, and especially trying to be consistent. I noticed sometimes you use single quotes other times double quotes fort HTML attributes. It should always be double quotes without any spaces betweens the equal sign and the quotes :)
In the end, the code will be:
$('a.A1').click(function() {
$('.active').removeClass('active');
$(this).addClass('active');
$('#' + $(this).attr('rel')).addClass('active');
return false;
});
.A1 {
background: rgba(0,0,0,.1);
margin: 0;
padding: 0;
height: 10px;
width: 10px;
}
.AAA {
display: none;
height: 120px;
width: 120px;
}
.AAA.active { display: block; }
.Top {
display: flex;
margin: 10px 0;
justify-content: center;
}
.Top a {
color: black;
float: left;
padding: 8px 16px 16px;
text-decoration: none;
border: 1px solid #ddd;
}
.Top a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.Top a:hover:not(.active) {background-color: #ddd;}
.Top a:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.Top a:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="page-1" class="active AAA">p1</div>
<div id="page-2" class="AAA">p2</div>
<div id="page-3" class="AAA">p3</div>
<div id="page-4" class="AAA">p4</div>
<div id="page-5" class="AAA">p5</div>
<div id="page-6" class="AAA">p6</div>
<div class="Top">
1
2
3
4
7
6
</div>
Here's a working js fiddle:
https://jsfiddle.net/ovitrif/o8h3nrjb/
Please try with below HTML, CSS and JS.
$('.Top a').click(function() {
$('.active').removeClass('active');
$(this).addClass('active');
$('#' + $(this).attr('rel')).addClass('active');
return false;
});
div.AAA {
display: none
}
div.active {
display: block;
}
.Top {
display: inline-block;
}
.Top a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
border: 1px solid #ddd;
background: rgba(0, 0, 0, .1);
}
.Top a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.Top a:hover:not(.active) {
background-color: #ddd;
}
.Top a:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.Top a:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.AAA {
height: 120px;
width: 120px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="page-1" class="active AAA">p1</div>
<div id="page-2" class='AAA'>p2</div>
<div id="page-3" class='AAA'>p3</div>
<div id="page-4" class='AAA'>p4</div>
<div id="page-5" class='AAA'>p5</div>
<div id="page-6" class='AAA'>p6</div>
<div class='Top'>
1
2
3
4
7
6
</div>
Related
This a simple sign up formed I've made my school project and for one to sign up is to choose their roles. There's not much to this but I can't seem to figure how to fix this border problem under the anchor? How do I make it so that the space at the top is equivalent to the bottom as well?
enter image description here
body {
font-family: Arial, Helvetica, sans-serif;
}
* {
box-sizing: border-box;
}
.center {
position: absolute;
top: 150px;
width: 99%;
text-align: center;
font-size: 18px;
}
.box {
margin: auto;
border: 1px solid #ccc;
width: 30%;
padding: 15px;
}
a {
background-color: #333;
text-decoration: none;
display: block inline;
color: white;
padding: 14px 20px;
margin: 8px 0px;
border: none;
cursor: pointer;
width: 100%;
opacity: 1.5;
}
a:hover {
background-color: #ddd;
color: black;
}
ul {
list-style-type: none;
}
li {
display: inline;
}
<div class="center">
<div class="header">
<h2>WELCOME TO SMK USJ 12<br/> ENGLISH QUIZ</h2>
</div>
<form action="role.php" method="post">
<div class="box">
<h3>Choose your role<br/> You are a...</h3>
Teacher</button>
Student
</div>
</div>
You have a typo with the display property on the a tags. I think you meant to use inline-block instead of block inline?
a {
/* ... */
display: inline-block;
/* ... */
}
The correct solution (in my opinion) would be to change your markup a bit, employ a wrapping container for the buttons and then apply the proper styles to that container. However, without changing your markup - you can still achieve what you are looking for, by adding some line-height to your buttons. Something like:
.box a{
line-height: 5em;
}
Should put you in the ball-park of what you are trying to achieve.
I'm having some issues with styling the top bar for a website. I want all of the anchor tags to be equally distributed throughout the entirety of the screen. There are four anchor tags, so I thought that by making the width of each tag 25%, they would each take up a quarter of the block. They should theoretically all be in one line, but the very last one gets moved down. I have no clue what's causing this to happen and hope I'll be able to get some help. Thank you!
html code:
<div class="navbar">
Home
Lessons
Contact
Login
</div>
CSS code:
* {
margin-left:0;
margin-right:0;
margin-bottom:0;
margin-top:0;
}
html, body {
height:100%;
width:100%;
}
.navbar {
background-color: #555;
overflow: auto;
}
.navbar a {
float: left;
padding: 12px;
color: white;
text-decoration: none;
font-size: 17px;
width: 25%; /* Four equal-width links. If you have two links, use 50%, and 33.33% for three links, etc.. */
text-align: center; /* If you want the text to be centered */
}
It is the padding defined in .navbar a that causes the offset. You can add a box-sizing: border-box to the rule to avoid this effect (content will shrink instead of container expanding to fit the padding). Or, better i think, use flexbox :
.navbar {
background-color: #555;
overflow: auto;
display: flex
}
.navbar a {
flex: 1;
padding: 12px;
color: white;
text-decoration: none;
font-size: 17px;
text-align: center; /* If you want the text to be centered */
}
The display: flex will initialize flexbox on navbar container and the flex: 1 in anchor will tell browser to give equal width to all elements.
A quick fiddle to explain (case 1 & 2 can be easily fixed with box-sizing) :
.container {
width: 200px;
border: 1px solid #000;
}
.item-no-flex {
width: 25%;
padding: 3px;
border: 1px dashed #000;
float: left;
}
.item-ib {
width: 25%;
padding: 3px;
border: 1px dashed #000;
display: inline-block
}
.container-flex {
width: 200px;
display: flex;
border: 1px solid #000
}
.item-flex {
width: 25%;
padding: 3px;
flex: 1;
border: 1px dashed #000;
}
<p>Float</p>
<div class="container">
<div class="item-no-flex">1</div>
<div class="item-no-flex">2</div>
<div class="item-no-flex">3</div>
<div class="item-no-flex">4</div>
</div>
<p style="clear:both">Inline-block</p>
<div class="container">
<div class="item-ib">1</div>
<div class="item-ib">2</div>
<div class="item-ib">3</div>
<div class="item-ib">4</div>
</div>
<p style="clear:both">Flexbox</p>
<div class="container-flex">
<div class="item-flex">1</div>
<div class="item-flex">2</div>
<div class="item-flex">3</div>
<div class="item-flex">4</div>
</div>
Try simplifying your code and using flexbox.
HTML:
<div class="navbar">
Home
Lessons
Contact
Login
</div>
CSS:
.navbar {
display: flex;
justify-content: space-around;
}
This should distribute the links equally across the page with space around each link, regardless of screen width.
I have the following CSS and HTML:
body { background-color: #c0c0c0; }
.title-bar, { background-color: #999; color: white; float: left; overflow: hidden; }
.title-bar {
border-bottom: 1px solid white;
height: 128px;
width: 100%;
}
.logo, .user-info { box-sizing: content-box; height: 100%; width: 128px; }
.logo{
align-items: center;
background-color: #369;
border-right: 1px solid white;
display: flex;
float: left;
font-size: 2em;
font-kerning: none;
justify-content: center;
}
.user-info {
align-items: center;
border-left: 1px solid white;
display: flex;
float: right;
justify-content: space-between;
flex-flow: column nowrap;
}
.user-info .circle {
border: 2px solid #369;
border-radius: 50%;
display: inline-block;
flex: 0 0 auto;
height: 32px;
margin: 8px 8px;
overflow: hidden;
transition: border 0.15s ease-out;
width: 32px;
}
.user-info .circle:hover { border-width: 4px; }
.user-info .container {
border-top: 1px solid white;
display: flex;
justify-content: center;
margin-top: 6px;width: 100%;
}
.hor-nav { background-color: #404040; }
.option { display: inline-block; position: relative; }
.hor-nav .option:hover {background-color: #369; }
.option a {
color: white;
display: inline-block;
font-size: 1em;
padding: 14px;
text-align: center;
transition: background-color 0.15s ease-out;
}
.option .dropdown { display: none; position: absolute; }
.option:hover .dropdown{ display: block; }
.dropdown a {
display: block;
text-align: left;
width: 100%;
}
<div class="title-bar">
<a class="logo" href="#">
</a>
<div class="user-info">
<span>User name</span>
<div class="container">
</div>
</div>
<div class="hor-nav">
<div class="option">
OPTION 1
<div class="dropdown">
ITEM 1
</div>
</div>
</div>
</div>
as you can see, the hor-nav bar's color spills onto the user-info area.
I have researched this and found that if I set overflow-x: hidden; it will not do this (see this article).
I have tried that and it is true - the nav bar does not spill into the user-info but, when you hover over one of the nav bar options, the dropdown does not come down but instead the vert-nav gives you a scroll bar (see this jsfiddle).
Additionally, if you do overflow-y: hidden; there is no scroll bar at all.
I am trying to get it so that the background-color of the hor-nav does not spill into other div's, but also allows the dropdown to be activated and work
thank you.
The easiest way to to this with least code change is to just give the user-info area a background color. Since the hor-nav section is lower on the z-index this will give the visual affect you want although the bar will still be under the user-info section it won't appear to be and the drop down will funtion as it does now.
Per your inquiry, you could do this another way by using percentage based widths for all 3 elements so they don't overlap eachother. Please see this fiddle for code change (note I change the markup order slightly, widths, and added box sizing css property)
The way I see it, you have 3 options
You can try adding margin-left/right to the hor-nav.
.hor-nav {
margin: auto 128px;
}
Another option is to set a certain width to the .hor-nav. Or practically cut the width of it.
.hor-nav {
width: calc(100% - 128px);
}
And third, is to add a background color to the .user-info
I would like to push the text down to be centered in the green part, but I cannot seem to figure it out. I've been messing around with it for some time, but I'm still a novice. Any help would be appreciated. I've added the HTML and CSS below.
.beerimgcontainer {
width: 300px;
height: 400px;
margin-bottom: 20px;
margin-right: 20px;
display: inline-block;
position: relative;
text-align: center;
margin-right: 10px;
overflow: hidden;
max-height: 400px;
}
.beerimgcontainer a {
text-decoration: none;
}
.beerimgcontainer span {
text-decoration: none;
font-size: 23px;
font-family: champagne;
color: black;
}
.beerimgcontainer:hover {
background: #165a11;
color: white;
box-shadow: 0px 0px 0px 2px #3c8837;
box-sizing: border-box;
}
.beerimgcontainer:hover span {
color: white;
}
<div class="beerimgcontainer">
<a href="mug.html">
<img src="images/text2.png" class="positionimg" alt="Mug">
<span>Mug</span>
</a>
</div>
img and span are inline elements. They are initially next to each other. Since your image covers the whole width (that's available; 300px on parent div), it pushes the span down. Margin on the span wouldn't work.
What you should do is to set display: block on the span and then set a margin:
.beerimgcontainer span {
display: block;
margin-top: 15px;
}
JSFiddle
I'm trying to acomplish this:
This is my code:
In the view I add this to the title:
<ion-nav-title>
<div class="progress">
<div class="active"><div>Selección</div></div>
<div><div>Destino</div></div>
<div><div>Pago</div></div>
</div>
</ion-nav-title>
And I use this css:
.bar {
height: 60px !important;
}
.has-header {
top: 60px !important;
}
.progress {
line-height: 4;
display: table;
table-layout: fixed;
width: 100%;
text-align: center;
}
.progress > div {
display: table-cell;
}
.progress > div > div {
color: #ddd;
border-top: 2px solid #ddd;
padding-left: 5px;
padding-right: 5px;
padding-top: 2px;
margin-left: 5px;
margin-right: 5px;
font-size: 50%;
text-transform: uppercase;
font-weight: normal;
}
.progress > div.active > div {
color: #fff;
border-top-color: #fff;
}
You can play with this in codepen (please fork):
http://codepen.io/anon/pen/NqLvMN
But I get this:
And if I change the .progress > div > div display to inline I get this:
Help!
Depending on the first image, I have made the following
CSS changes
.progress > div {
display: inline-block; /* Horizontal alignment */
line-height: 15px; /* Vertical alignment */
width: 33%; /* Equal width 3 columns */
}
Updated Codepen