I'm trying to create the following header using CSS:
This is my attempt so far using CSS grid:
HTML:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="jumbotron">
<div class="grid">
<div class="a">
28
</div>
<div class="b">
clubs
</div>
<div class="c">
/
</div>
<div class="d">
48
</div>
<div class="e">
virtual
</div>
<div class="f">
gyms
</div>
</div>
CSS:
.jumbotron {
background: linear-gradient(141deg, rgb(0,223,179), rgb(34,198,252));
}
.grid {
display:grid;
grid-template-columns: 50px 50px 50px 50px;
color:white;
}
.a{
grid-column: 1;
grid-row: 1/span 2;
font-size:35px;
}
.b{
grid-column: 2;
grid-row: 2;
}
.c{
grid-column: 3;
grid-row: 1/span 2;
font-size:35px;
}
.d {
grid-column: 4;
grid-row:1/span 2;
font-size:35px;
}
.e {
grid-column:5;
grid-row:1;
}
.f {
grid-column:5;
grid-row:2;
}
https://codepen.io/anon/pen/jGKwEL
I don't know if I'm overthinking it but this is the best solution I can come up with to make the stacked text somewhat align. It's very tedicous however to make look exactly like the picture and it includes a lot of CSS classes. Any other way to approach this or am I on the right track?
Edit: this what I ended up doing with help of the answers to this question: https://codepen.io/anon/pen/jGKwEL
You don't have to use CSS grid: just because it is available does not mean that you have to use it, or that it is relevant for your usecase. In your layout requirement, it is more suitable to use a mix of display: flex and some simple relative positioning to get the baseline of the text to line up.
First, with the markup, you can simply use a <ul>:
<ul>
<li>
<span class="count">28</span>
<span class="text">clubs</span>
</li>
<li>
<span class="count">48</span>
<span class="text">virtual<br />gyms</span>
</li>
</ul>
With regards to styling:
use display: flex on the <ul> parent so that the child elements will be arranged horizontally
the slanted border can simply be emulated using border-right, and we disable it on the last child using the li:last-child selector
the baseline alignment of the text/description next to the number requires manual adjustment, just play around with some values with bottom offset
use transform: skew(...) to slant your text uniformly, instead of relying on italics. This will lead to uniform slanting of the text and the separators :)
The outcome will look something like this:
Here is a quick proof-of-concept I have whipped up, based on the suggested changes listed above:
.jumbotron {
background: linear-gradient(141deg, rgb(0, 223, 179), rgb(34, 198, 252));
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: flex-end; /* Align to right */
}
ul li {
transform: skew(-10deg);
border-right: 3px solid #fff;
padding: 0 20px;
display: flex;
align-items: flex-end; /* Align to bottom */
}
ul li:last-child {
border: none;
}
ul li span {
color: white;
line-height: 1em;
font-weight: bold;
}
ul li span.count {
font-size: 45px;
margin-right: 10px;
}
ul li span.text {
text-transform: uppercase;
position: relative;
bottom: .35em; /* Adjust this value manually */
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="jumbotron">
<ul>
<li>
<span class="count">28</span>
<span class="text">clubs</span>
</li>
<li>
<span class="count">48</span>
<span class="text">virtual<br />gyms</span>
</li>
<li>
<span class="count">33</span>
<span class="text">active<br />players</span>
</li>
<li>
<span class="count">15</span>
<span class="text">inactive<br />players</span>
</li>
</ul>
</div>
Here's an example using a list, :after for styling the slashes, and spans for the different parts of one item. You can just duplicate the <li>'s to add more items, without the need for futher classes. I hope it's the way you need it :)
You could use flexbox as an alternative, but I personally think there is no need for it in this case.
https://codepen.io/anon/pen/YrvQMp
Related
When I try to size down my desktop screen navigation size of 1440px(90em) to any lower width screen, my navigation bar links start dropping off the screen. I have tried using some media query combinations, but nothing to show for it.I haven't got much experience with frontend, so I am a little bit thin on this side. Any long-term fixes to this one?Any hint on this one will be highly appreciated.
HTML header code:
<!--header-->
<header>
<nav class="nav__bar">
<a href="#" class="logo">
<img src="./images/logo.svg" alt="Sunnyside logo">
</a>
<ul class="nav__links">
<li class="nav__item">
About
</li>
<li class="nav__item">
Services
</li>
<li class="nav__item">
Project
</li>
Contact
</ul>
<img src="./images/icon-hamburger.svg" alt="toggle menu icon" class="toggle__menu">
</nav>
</header>
CSS header styles:
header {
height: 5em;
position: absolute;
left: 0;
right: 0;
}
.nav__bar {
height: 100%;
width: 90em;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
flex: 1 1 auto;
padding: 0 2em;
}
.nav__links {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
list-style: none;
}
.nav__item {
margin: 1em;
}
.nav__link {
text-decoration: none;
font-size: 1.125em;
color: hsl(0, 0%, 100%);
font-family: 'Barlow', sans-serif;
transition: all 350ms ease-in-out;
}
.nav__link:hover {
color: hsl(232, 10%, 55%);
}
.toggle__menu {
cursor: pointer;
display: none;
}
In your example code, you set the color of the link text to white... it's white on white. But that's not fully the problem... you should also remove width:90em from the .nav_bar... it's unnecessary. see this codepen https://codepen.io/aequalsb/pen/jOmyJNp
Just simply allow the <nav> to "be itself"... which is a block level element and naturally attempts to stretch out to fit available width.
padding in CSS Sizes the margin inside a button or element. Try using margin: (how many 'px' it's going off the screen); and I've had this problem before:
SOLUTION 1:
use margin-*left or top*: *px is going off screen*
<style>
#button {
width: 100px; /* the width of the button */
position: absolute;
left: 50%; /* always 50% when centering */
margin-left: -50px; /* minus half the size of the element */
}
</style>
<button id="button">Center of page</button>
SOLUTION 2
i've had this problem before, and in best situations, use position: absolute instead of relative if you are positioning the element.
<head>
<style>
.background {
position: relative;
}
.overlap {
position: absolute;
left: 30px;
}
</style>
</head>
</style>
</head>
<body>
<!-- background-element -->
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/Circle_Rufous_Solid.svg/1200px-Circle_Rufous_Solid.svg.png" class="background" width="10.5%" />
<!-- Overlap element -->
<img src="https://cdn.onlinewebfonts.com/svg/img_24930.png" class="overlap" width="10%" />
</body>
SOLUTION 3
if none of the above works, consider using javascript: device tester command and redirect to an error page with unsupported devices.
This example will detect a handful of mobile-devices, and if so, it'll redirect to 𝘩𝘵𝘵𝘱://𝘨𝘰𝘰𝘨𝘭𝘦.𝘤𝘰𝘮
<script>
if( /Android|webOS|iPhone|iPad|Mahc|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.location.href = "http://google.com";
} else {
}
</script>
NOTE: if there is big problem you cannot solve, and none of these work, its best to do research or find some articles to find your answer. Then consider using stackoverflow.
I want to display the first item of the <aside> tag centered at the left.
All other items should be displayed on the right.
I'm using a tool (asciidoctor-html5s) to convert asciidoc to html5.
Therefore I cannot change the HTML.
This is the generated HTML:
<aside class="admonition-block tip" role="doc-tip">
<h6 class="block-title">
<span class="title-label">Tip: </span>
Info
</h6>
<p>Go to this URL to learn more about it:</p>
<div class="ulist">
<ul>
<li><a class="bare" href="http://asciidoc.org">http://asciidoc.org</a></li>
</ul>
</div>
<p>Or you could return to the First Steps or Purpose.</p>
</aside>
And this is an example how it should look like:
Is this possible and if yes, how?
Please do not focus on the Info text inside the h6. I know this is not possible. The question is centered around having the first item on the left an all n other items on the right.
You can make use of the float: left and a bit styling to the height and margin-right
.admonition-block .block-title {
float: left;
margin-right: 2rem;
height: 4rem;
}
<aside class="admonition-block tip" role="doc-tip">
<h6 class="block-title">
<span class="title-label">Tip: </span>
Info
</h6>
<p>Go to this URL to learn more about it:</p>
<div class="ulist">
<ul>
<li><a class="bare" href="http://asciidoc.org">http://asciidoc.org</a></li>
</ul>
</div>
<p>Or you could return to the First Steps or Purpose.</p>
</aside>
If your HTML is going to be exactly like that (e.g. an h6, a p, a div, and then another p), then you can hard code it like this using a combination of CSS Grid and CSS Flexbox styles:
aside {
display: grid;
grid-template-columns: 50px 320px; /* picked these sizes at random; feel free to change */
grid-gap: 5px; /* picked these sizes at random; feel free to change */
}
aside > * {
grid-column: 2;
}
h6 {
grid-column: 1;
grid-row: 1 / 5;
display: flex;
visibility: hidden;
align-items: center;
justify-content: center;
}
h6 span {
visibility: visible;
}
p::before {
content:"Info";
position: absolute;
top: 5px;
font-style: italic;
}
aside p:first-of-type {
grid-row: 1;
}
aside div {
grid-row: 2;
}
aside p:last-of-type {
grid-row: 3;
}
<aside class="admonition-block tip" role="doc-tip">
<h6 class="block-title">
<span class="title-label">Tip: </span>
Info
</h6>
<p>Go to this URL to learn more about it:</p>
<div class="ulist">
<ul>
<li><a class="bare" href="http://asciidoc.org">http://asciidoc.org</a></li>
</ul>
</div>
<p>Or you could return to the First Steps or Purpose.</p>
</aside>
I hid the "Info" text node in markup and added it in CSS as a pseudo-element. It's not selectable that way, but the trade of is it can be positioned the way you want it to.
Maybe there is a way in your converter software to disallow naked text nodes like that (it's considered bad practice to have atomic text not wrapped in an element if you want to style/select it).
I am trying to align my items list to the right side of the web page. Also, I wanted to have a vertical thin separator between the left and center data structure (hierarchy) and my right list.
Right.component.html :
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="header-divider">
<ul class="selection-list">
<li *ngFor="let item of getSelections()">
<button class="btn" (click)="deselect(item)" *ngIf="item.selected">
<i class="fa fa-close"> {{ item.displayName }} </i>
</button>
</li>
</ul>
</div>
Right.component.css :
.selection-list {
list-style: none;
margin-top: 5px;
margin-bottom: 10px;
line-height: 15px;
font-size: 16px;
color: #555;
padding-left: 23px;
text-transform: capitalize;
right: 0;
}
.btn {
border: none;
padding: 0;
background: none;
}
.header-divider {
border-left:1px solid #38546d;
height:30px;
position:relative;
right:20px;
top:10px;
}
Right now, it just appears below my hierarchy structure. What should I do to fix this?
I always favor the use of flexbox which is a great simple way to use all available space inside a container. This is how I would do it:
-----(Edited)-----
.flex-container {
display: flex;
height: 50px;
border: solid 1px peru;
}
.sendToRight {
margin-left: auto;
}
<div class="flex-container">
<div class="PLCheck">
fortuneSelect
</div>
<div class="sendToRight"> <!-- add class to div for manipulation -->
rightSideComp
</div>
</div>
In this example, the margin-left:auto makes your .sendToRight div move all the way to the right. You could also use justify-content: space-between; in your container element to achieve the same result.
I'm currently coding a very basic page for my friend and he said he wanted a box which would change color depending on which link he hovers over. I've tried a few things but none of it seem to work.
This is how the body looks:
body {
color: #fff;
background: #98adca;
text-align: center;
margin: 275px auto;
}
#box {
padding: 30px;
border: solid;
}
li {
list-style: none;
text-decoration: none;
}
a,
a:hover,
a:active,
a:visited {
color: #fff;
text-decoration: none;
}
.twt:hover {
background: #c3c0d1;
color: #fff;
}
<div id="box">
<h1>social media</h1>
<div class="twt">
<li>twitter
</li>
</div>
<div class="ig1">
<li>art instagram
</li>
</div>
<div class="ig2">
<li>regular instagram
</li>
</div>
<div class="fb">
<li>facebook
</li>
</div>
<div class="yt">
<li>youtube
</li>
</div>
</div>
But I don't get how I should write the CSS to make the box another color when just, for example, hovering over the YouTube link. In my current CSS only the background of the text is changed when hovering and not the entire box.
Try using jQuery with the "onmouseover" event:
HTML:
<div id="box">
<a onmouseover="colorChange()" onmouseout="revert()" href="#">Link</a>
</div>
Javascript:
function colorChange() {
$("#box").css("background-color", "red");
}
function revert() {
$("#box").css("background-color", "lightgrey");
}
Here is my pen: http://codepen.io/Hudson_Taylor11/pen/ozQogO
Hope this helps!
Use jQuery:
$(".twt").hover(
function() {
$("#box").css( "background-color", "#000" );
},
function() {
$("#box").css( "background-color", "#98adca" );
}
);
Let me know if you need help setting up jQuery.
From what I know. CSS doesn't be made to walk backward. All I can think about the way I can do is using jQuery to do that.
$(document).ready(function(){
$('.ig1 li a').hover(function(){
$('#box').css({'background-color': 'green'});
});
$('.ig2 li a').hover(function(){
$('#box').css({'background-color': 'blue'});
});
$('.yt li a').hover(function(){
$('#box').css({'background-color': 'red'});
});
$('.fb li a').hover(function(){
$('#box').css({'background-color': 'pink'});
});
});
body {
color: #fff;
background: #98adca;
text-align: center;
margin: 275px auto;
padding: 30px;
}
#box {
border: 3px solid #fff;
padding: 30px;
}
li {
list-style:none;
text-decoration:none;
}
a, a:hover, a:active, a:visited {
color: #fff;
text-decoration:none;
}
.twt:hover {
background: #c3c0d1;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="box">
<h1>social media</h1>
<div class="twt">
<li>twitter</li>
</div>
<div class="ig1">
<li>art instagram</li>
</div>
<div class="ig2">
<li>regular instagram</li>
</div>
<div class="fb">
<li>facebook</li>
</div>
<div class="yt">
<li>youtube</li>
</div>
</div>
</body>
Right, so I started thinking, you can do it with JS, but can you do it with pure CSS. Short answer - No. CSS does not allow child elements to access parent elements, because of security and other concerns. A simple Google search will show you all the things I read, there's no point of sharing docs here. But what if we trick the user, right, just hear me out. Instead of changing the colour of the parent, which is illegal, let's change the colour of a sibling - allowed by CSS LinkSo I unified your classes, for the links to share the same class (they still have separate IDs, chill). I then added a "pretend div" which will serve the purpose of the body. I stylised the "pretend", the unified div and added a "sibling on hover" CSS rule. Take a look:HTML`
<body>
<div class="box">
<h1>social media</h1>
<div class="link_divs" id="div_1">
<li>twitter</li>
</div>
<div class="link_divs" id="div_2">
<li>art instagram</li>
</div>
<div class="link_divs" id="div_3">
<li>regular instagram</li>
</div>
<div class="link_divs" id="div_4">
<li>facebook</li>
</div>
<div class="link_divs" id="div_5">
<li>youtube</li>
</div>
<div id="pretend_div">
</div>
</div>
</body>
And here's the CSS
body {
color: #fff;
background: #98adca;
text-align: center;
margin: 275px auto;
padding: 30px;
border: 3px solid #fff;
height: 100%;
}
li {
list-style:none;
text-decoration:none;
}
a, a:hover, a:active, a:visited {
color: #fff;
text-decoration:none;
}
/* IMPORTANT - This will be the new "body" */
#pretend_div{
position: absolute; /* REQUIRED */
width: 96%; /* Matching your body size */
height: 180px; /* Matching your body size */
border: 1px solid red; /* Differentiating made easy */
top:0; /* IMPORTANT - push the element to the top */
left: 0; /* IMPORTANT - push the element to the left */
margin: 275px auto; /* Grabbed the margin from your body */
padding: 30px; /* Grabbed the padding from your body */
z-index: -1; /* IMPORTANT - push the element to the back of stack */
}
/* IMPORTANT - generic link class */
.link_divs{
z-index: 0; /* IMPORTANT - set the links on-top of the pretend div */
position: relative; /* IMPORTANT - positioning */
}
/* What link you hover over ~ The pretend div */
#div_1:hover ~ #pretend_div{
background-color: #00A000; /* change bck colour */
}
#div_2:hover ~ #pretend_div{
background-color: orangered;
}
#div_3:hover ~ #pretend_div{
background-color: darkgoldenrod;
}
REMARKS I'm aware this is not the best solution, honestly - just use JS. But I wanted to try and make it happen with pure CSS. Now I tried to match the pretend div to your body as best I could, thus it looks, well, not as good as it could. I added some comments to help you understand what is happening with each line. The ones that use the "sibling style" CSS are marked by Important. Everything else is just matching your body style.JSFiddle Demo -> DEMO LINKHope that helps
instead of background try background-color
I'm making a menu selection bar, and I'm running into a problem when I mouse over. The icon's corners should all be curved, but only the left hand side ones are.
Here's a demo of the code: https://jsfiddle.net/gfqgcwq5/
From what I can tell, it seems like inline-block is the culprit here:
.wrapper{
display:inline-block;
margin:10px;
}
I just don't know how to accomplish the inline array without it. I'm not great at css, so if someone could lend me a hand, I'd appreciate it.
try this one:
.icon{
border-radius:8px;
padding-top:15px;
padding-bottom:5px;
transition:.1s;
font-size:60px;
display: inline-table;
}
.icon:hover{
cursor:pointer;
background-color: #00B1EB;
color:#fff;
}
span#picture > span {
padding-right:9px;
padding-left:10px;
padding-top:7px;
padding-bottom:10px;
}
.text{
text-align:center;
}
.wrapper{
display:inline-block;margin:10px;
}
DEMO HERE
Used to this
Define your .icon display inline-block
as like this
.icon{display:inline-block;line-height:60px;}
or you can used to
.icon{display:block;}
Demo
Remember that the border-radius is a property (in this case) of the .icon class, if you use the inspector you will see that the wrapper has the proper size and shapewraper
So as the other says the issue is on the display of the .icon class, If your idea is to have more than one .icon elements inside of the wrapper and inline, you should use display: inline-block;, if your call is to have just one per wrapper use display: block;.
Hope this helps you.
You gotta give icon block display: inline-block property in order to work !!
.icon {
border-radius: 8px;
padding: 15px;
padding-bottom: 5px;
transition: .5s all ease;
font-size: 60px;
display: inline-block;
}
.icon:hover {
cursor: pointer;
background-color: #00B1EB;
color: #fff;
}
span#picture > span {
padding-right: 9px;
padding-left: 10px;
padding-top: 7px;
padding-bottom: 10px;
}
.text {
text-align: center;
}
.wrapper {
display: inline-block;
margin: 10px;
}
<link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
Apply padding for the text div to allow the entire curve to visible.
.text{
text-align:center;
padding:0px 7px;
}
DEMO