Hi SO I have what one day might be used on my web page that is a block of tabs (very basic currently) and I want them to be aligned in such a way that there is 5 blocks on the first line and 4 blocks on the second but they both align horizontally to end at the same point (so it doesn't look like one is missing)
here is a link to what I have currently http://jsfiddle.net/xs8d6zuh/2/
html -
<span>twenty letters long</span>
<span>twelve lette</span>
<span>eight123</span>
<span>ten letter</span><br></br>
<span>twenty letters long!</span>
<span>sixteen letters!</span>
<span>1seven</span>
<span>sixsix</span>
CSS -
a {
text-decoration: none;
color: #000000;
border: 2px;
background-color: #f6f0e0;
font-family: Arial;
font-size: 14px;
padding: 6px;
border: 1px solid;
border-color: #d5c898;
display: inline;
width: 123px;
text-align: center;
}
a:hover {
background-color: #000000;
color: #f6f0e0;
}
<div class="container">
Bavaria
twenty letters long
twelve lette
eight123
ten letter
twenty letters long!
sixteen letters!
1seven
sixsix
</div>
CSS
.container {
font-size: 0px;
}
a {
text-decoration: none;
text-align: center;
color: #000000;
background-color: #f6f0e0;
font-family: Arial;
font-size: 14px;
padding: 6px;
border: 1px solid #d5c898;
display: inline-block;
}
a.five {
width: calc(20% - 14px);
}
a.four {
width: calc(25% - 14px);
}
a:hover {
background-color: #000000;
color: #f6f0e0;
}
https://jsfiddle.net/xs8d6zuh/2/
use calc() function
"for first 4 use width:calc(100% / 4);
for remaining 3 use width:calc(100% / 3);"
if u have 7 span elements
Flexbox can do that:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
flex-wrap: wrap;
}
span {
flex: 1 0 20%;
display: block;
text-align: center;
}
a {
display: block;
text-decoration: none;
color: #000000;
border: 2px;
padding: 6px;
background-color: #f6f0e0;
font-family: Arial;
font-size: 14px;
border: 1px solid;
border-color: #d5c898;
}
a:hover {
background-color: #000000;
color: #f6f0e0;
}
<div class="container">
<span>Bavaria</span>
<span>twenty letters long</span>
<span>twelve lette</span>
<span>eight123</span>
<span>ten letter</span>
<span>twenty letters long!</span>
<span>sixteen letters!</span>
<span>1seven</span>
<span>sixsix</span>
</div>
JSfiddle Demo
Related
still learning flexbox. I can´t find the reason about how the items on the nav element are not vertically aligned with the h1 text. Would love some help! Link for the codepen at the end.
The expected result should be both the nav and the h1, inside the .main-header, vertically aligned.
HTML:
<div class="container">
<header class="main-header clearfix">
<h1>📘 The Code Magazine</h1>
<nav>
<!-- <strong>This is the navigation</strong> -->
Blog
Challenges
Flexbox
CSS Grid
</nav>
</header>
</div>
CCS:
* {
/* border-top: 10px solid #1098ad; */
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
color: #444;
font-family: sans-serif;
border-top: 10px solid #1098ad;
position: relative;
}
.main-header {
background-color: #f7f7f7;
/* padding: 20px;
padding-left: 40px;
padding-right: 40px; */
padding: 20px 40px;
margin-bottom: 60px;
/* height: 80px; */
}
nav {
font-size: 18px;
/* text-align: center; */
}
h1,
h2,
h3 {
color: #1098ad;
}
h1 {
font-size: 26px;
text-transform: uppercase;
font-style: italic;
}
a:link {
color: #1098ad;
text-decoration: none;
}
a:visited {
/* color: #777; */
color: #1098ad;
}
a:hover {
color: orangered;
font-weight: bold;
text-decoration: underline orangered;
}
a:active {
background-color: black;
font-style: italic;
}
nav a:link {
/* background-color: orangered;
margin: 20px;
padding: 20px;
display: block; */
margin-right: 30px;
display: inline-block;
}
.main-header {
display: flex;
align-items: center;
}
Here is the link for the codepen:
https://codepen.io/Swanbe/pen/OJzpjor
Thanks in advance!
For past 10 minutes, I have been debugging your code.
Wrote another code like this to see if the problem persists. But that was vertically aligned.
So I dug deeper and tried changing and tags. Nothing Great.
....
Until I just removed that blue rubber(Emoji or whatever you call that ) and added a property in nav.
nav {
height: 100px;
display: flex;
flex-direction: row;
align-items: center;}
and that's it.
Try removing that emoji and see if it helps.
ul.bs-pagination {
font-weight: 500;
height: 30px;
line-height: 30px;
margin: 0 2px;
min-width: 30px;
text-align: center;
align-items: center;
display: flex;
font-size: 18px;
}
ul.bs-pagination a {
padding: 0 10px;
border-radius: 5px;
color: #cc092f;
transition: 0.3s;
border: 1px solid transparent;
}
ul.bs-pagination a:hover {
border-color: #cc092f;
}
<nav class="bs-pagination__nav" aria-label="Paginação">
<ul class="bs-pagination">12<a href="p0/IZ7_819E19820H3TB0Q3I25JK808F2=CZ6_819E19820H3TB0Q3I25JK800I3=MKJTMIKw=GE=/#Z7_819E19820H3TB0Q3I25JK808F2"
title="Link para a página 3" id="pc1617018954514_linkToPage_3">3</a> </ul>
</nav>
The sequence 1 2 3 above is how it should be and the one below is like it should be ...
I have an html element, where I want to add a css customization to it, but it is not between span, it has no class and id. It is simply a text inside a div, can I style it?
Try to apply your styles directly to ul parameter and the next you can write separated styles for links.
ul.bs-pagination {color: red;} - it's for 1
ul.bs-pagination > a {color: blue;} - it's for 2 and 3
ul.bs-pagination {
font-weight: 500;
height: 30px;
line-height: 30px;
margin: 0px 2px;
min-width: 30px;
text-align: center;
align-items: center;
display: flex;
font-size: 18px;
}
ul.bs-pagination a {
padding: 0 10px;
border-radius: 5px;
color: #cc092f;
transition: 0.3s;
border: 1px solid transparent;
text-decoration: none;
}
ul.bs-pagination a:first-child {
margin-left: 10px;
}
ul.bs-pagination a:hover {
border-color: #cc092f;
}
<nav class="bs-pagination__nav" aria-label="Paginação">
<ul class="bs-pagination">123 </ul>
</nav>
Frankly speaking if you can't put your links inside <li> </li>, you should change your ul to div like below:
div.bs-pagination {
font-weight: 500;
height: 30px;
line-height: 30px;
margin: 0px 2px;
min-width: 30px;
text-align: center;
align-items: center;
display: flex;
font-size: 18px;
}
div.bs-pagination a {
padding: 0 10px;
border-radius: 5px;
color: #cc092f;
transition: 0.3s;
border: 1px solid transparent;
text-decoration: none;
}
div.bs-pagination a:first-child {
margin-left: 10px;
}
div.bs-pagination a:hover {
border-color: #cc092f;
}
<nav class="bs-pagination__nav" aria-label="Paginação">
<div class="bs-pagination">123 </div>
</nav>
Firstly, your HTML code is not correct. You are changing the semantics of HTML elements. The whole purpose of developing HTML is to describe the semantic element of the documents.
According to HTML Spec, the only children of ul element is li element.
<ul>
<li>Norway</li>
<li>Switzerland</li>
<li>United Kingdom</li>
<li>United States</li>
</ul>
There is initial space before the list. And the list is scrollable.
The space from the beginning needs to be removed while scrolling. Is it possible to do so using css?
I initially added padding before the list. But the padding is always maintaining it's space.
JSX:
<div class="pt-filter-container">
<div
v-for="(item, index) in items"
:key="index"
class="item"
>
{{ item.label }}
</div>
</div>
CSS:
.filter-container {
display: flex;
width: 30em;
overflow-x: auto;
white-space: nowrap;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.item {
font-size: 14px;
font-weight: 500;
letter-spacing: 0;
line-height: 16px;
color: #5A6872;
margin-right: 8px;
padding: 8px 12px;
border: 1px solid #chip-grey;
border-radius: 4px;
background-color: #FAFAFA;
position: relative;
}
.active {
background-color: #red;
color: #white;
}
}
It's just i need to add margin before the 1st element instead of container that is containing it.
So the actual code will be -
.pt-filter-container {
display: flex;
width: 30em;
overflow-x: auto;
white-space: nowrap;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.pt-item {
font-size: 14px;
font-weight: 500;
letter-spacing: 0;
line-height: 16px;
color: #5A6872;
margin-right: 8px;
padding: 8px 12px;
border: 1px solid #pt-chip-grey;
border-radius: 4px;
background-color: #FAFAFA;
position: relative;
&:first-child {
margin-left: 18px;
}
}
.active {
background-color: #pt-red;
color: #pt-white;
}
}
I don't know the exact dom and css structure of your project. But can't you use something like this?
overflow-x: hidden
or
ul > li: first-child {
padding-left: 0;
}
I have this JsFiddle, and I can not figure out why the buttons extend outside of the divs.
How can I get them to be inside of the divs?
Here is the CSS
.btn-link {
font-variant: small-caps;
text-decoration: none;
font-size: 1.2em;
padding: 8px 15px 12px 15px;
border-radius: 3px;
background-color: #7dc36b;
color: #ffffff;
}
div.left-nav {
float: left;
width: 200px;
}
div.left-nav > div {
clear: both;
width: 100%;
border: solid 1px red;
}
Here is the HTML:
<div class="left-nav">
<div>new story
</div>
<div>My Stories
</div>
</div>
You can specify display:inline-block; on the buttons, so the div expands to hold the anchors completely.
.btn-link {
font-variant: small-caps;
text-decoration: none;
font-size: 1.2em;
padding: 8px 15px 12px 15px;
border-radius: 3px;
background-color: #7dc36b;
color: #ffffff;
display:inline-block;
}
Fiddle
div.left-nav > div {
overflow: auto; /* removed clear: both; */
width: 100%;
border: solid 1px red;
}
div.left-nav > div > a {
display: inline-block;
}
http://jsfiddle.net/ZjvZu/10/
Hey hope this works for you : -
demo
<div class="left-nav">
<div class="btn">new story
</div>
<div class="btn">My Stories
</div>
CSS:-
.btn-link {
font-variant: small-caps;
text-decoration: none;
font-size: 1.2em;
padding: 8px 15px 8px 15px;
border-radius: 3px;
background-color: #7dc36b;
color: #ffffff;
}
div.left-nav {
float: left;
width: 200px;
}
div.left-nav > div {
clear: both;
width: 100%;
border: solid 1px red;
}
.btn{
padding:8px 15px 8px 15px;
}
I'm new to css, I have a top nav but I couldn't set its width. It seems different when I test with Dreamweaver, ie9, ie6, Firefox and Opera. Here's my code:
#charset "utf-8";
/* CSS Document */
html {
background: url(images/light-tile.gif) repeat;
}
body {
overflow: auto;
width: 54.35em;
margin: 0 auto;
background-color: #fff;
padding-left: 0.25em;
padding-right: 0.4em;
border: 0.07em solid #97b4e0;
overflow: visible;
}
#main {
background-color: #fff;
}
ul#top-nav {
list-style: none;
margin: .9em .9em .9em 0;
padding: 0;
width: 110%;
}
ul#top-nav li {
display: inline;
}
ul#top-nav li a {
text-decoration: none;
font-size: 0.75em;
font-family: Arial, Helvetica, sans-serif;
padding: 0.90em 0;
width: 18.5%; /* for 5 items */
background: #99CCFF;
color: #3F4037;
font-weight: bold;
float: left;
display: inline-block;
text-align: center;
border-right: 0.05em solid #fff;
border-left: 0.05em solid #fff;
border-bottom: 0.2em solid #97b4e0;
}
ul#top-nav li a:hover {
color: #000;
font-weight: bolder;
background: #D7EBFF;
border-bottom: 0.2em solid #e9e9e9;
}
...
<body>
<div id="main">
<div id="top-info">Kumcuğaz Köyü İlköğretim Okulu</div>
<img id="top-image" src="../images/top_image.png" alt="üst resim" width="869" height="159" />
<ul id="top-nav">
<li>ANASAYFA</li>
<li>GALERİ</li>
<li>PERSONEL</li>
<li>İLETİŞİM</li>
<li>ZİYARETÇİ DEFTERİ</li>
</ul>
<div class="clear"></div>
<div id="faux">
...
If it isn't possible it to view same on all browsers, I'll have to use a table. Thanks for helping.
Sincerely
What's the reason for making it 110% wide? That's wider than the window. Also, you have 5 menu items each set to 18.5% wide... that adds up to only 90.5% total.
What happens when you make it 100% wide and each of the 5 items is 20% wide?
http://jsfiddle.net/u78Ks/2/
It looks like this might be the issue
width: 18.5%; /* for 5 items */
in here
ul#top-nav li a {
text-decoration: none;
font-size: 0.75em;
font-family: Arial, Helvetica, sans-serif;
padding: 0.90em 0;
width: 18.5%; /* for 5 items */
background: #99CCFF;
color: #3F4037;
font-weight: bold;
float: left;
display: inline-block;
text-align: center;
border-right: 0.05em solid #fff;
border-left: 0.05em solid #fff;
border-bottom: 0.2em solid #97b4e0;
}
Browsers could be interpreting this differently based on the font sizes, window sizes, etc.
Try setting this to a static width in pixels.