This div's border is a floating line instead of an actual border - html

I might be missing something basic. It's so simple:
.items {
float: left;
font-family: 'Arial', sans-serif;
text-decoration: none;
color: black;
font-size: 30px;
margin: 25px 30px 0px 0px;
}
.langswitch {
border: 3px solid #86D1DA;
border-radius: 5px;
}
<a href="#" class="langswitch">
<div class="items">Italiano</div>
</a>
jsFiddle
Moving the class from the anchor to the div will make it (the border) disappear all together.

Well, your <a class="lamgswitch"> does not have any content... The float: left; makes the <div class="items">float out of it...
So try to remove it, and replace it with display: inline-block;, as the div is a block component, and you placed it inside an inline component (a)...
.items {
display: inline-block;
font-family: 'Arial', sans-serif;
text-decoration: none;
color: black;
font-size: 30px;
margin: 25px 30px 0px 0px;
}
.langswitch {
border: 3px solid #86D1DA;
border-radius: 5px;
}
<a href="#" class="langswitch">
<div class="items">Italiano</div>
</a>

Place the <a> tag inside the <div> rather than the other way around.
.items{
float: left;
font-family: 'Arial', sans-serif;
text-decoration: none;
color: black;
font-size: 30px;
margin: 25px 30px 0px 0px ;
}
.langswitch{
border: 3px solid #86D1DA;
border-radius: 5px;
}
<div class="items">Italiano</div>
Hope this helps.

Technically, placing the <a> inside the <div> is the semantically correct way to do this as described in the other answer.
If you really HAVE to do it this way, you need to change the display of the <a> tag from inline to inline-block.

Related

span in container is breaking border radius rule leveraged in conjunction with first child pseudo selector

I have two anchor tags that have border radius rules, but they're applied with the parameters first-child and last child pseduo selectors, so that the both of them together look kind of like a "pill"
See an example below:
.tc__timezone-toggle {
display: flex;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui:first-child {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
Now, what I need to now is add in some next to the left of this pill shaped UI that says a message - what I'm finding is for some reason it renders the border radius on the first child broken.
See below:
.tc__timezone-toggle {
display: flex;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui:first-child {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
Border-radius doesn't affect inner elements
The way that I understood this question, having elements next to border radiuses can have impacts.
So from the answer I tried:
#outer { overflow: hidden; }
In context of my problem this is the result:
.tc__timezone-toggle {
display: flex;
/* from answer */
overflow: hidden;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui:first-child {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
This did not work.
CSS Flexbox Border Radius with text-overflow: Ellipsis
This implies that you can;'t use span in conjunction with border radius.
Since the link above talks about li, I tried div and p with no luck.
I tried to find the problem (I think I'm having with the span inside a flexbox and a border radius) I'm having here but couldn't find any helpful resources relevant to what I'm dealing with:
Perfectly rouded border-radius for flexbox items
Border radius issue with div
Why is the span tag breaking my border radius?
So pretty sure your issue is that you are using the :first-child selector on an element that is not the first child among it's siblings. When you remove that first-child psuedo-class everything works. Alternatively if you want to be very specific you can instead use first-of-type which would be true for that first element. To clarify, the span is the first child in the .tc_timezone_toggle div.
.tc__timezone-toggle {
display: flex;
/* from answer */
overflow: hidden;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
When you add in the span element it becomes the first child, the first part of the 'pill' is no longer the first child so it doesn't receive the border radius settings.
To get round this and remain fairly general you could use first-of-type, the type being a.
.tc__timezone-toggle {
display: flex;
/* from answer */
overflow: hidden;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
a.tc__timezone-toggle-ui:first-of-type {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>

Can I achieve a scrollable flex container without a scrollbar on mobile devices using css only?

I uploaded a video here : https://streamable.com/uyddy
I am asking if I can somehow hide the horizontal scrollbar in that specific div, while still being able to scroll? I want to achieve this on mobile devices.
I attached the code here :
https://codepen.io/UrsuGrizzly/full/aVRZyg/
https://jsfiddle.net/o2ucuorL/
<div id="bottom">
All
Images
Videos
News
Maps
<a id="books" href="#">Books</a>
<a id="flights" href="#">Flights</a>
<a id="personal" href="#">Personal</a>
<a id="stools" href="#">Search tools</a>
<a id="moar" href="#">More</a>
Settings
<a href="#" id="tools">Tools</a
</div>
body{
font-family: arial,sans-serif;
font-size: 13px;
}
#bottom{
grid-area: 2/1/3/3;
display: flex;
overflow-x:scroll;
}
#bottom a{
font-size: 12px;
text-transform: uppercase;
text-decoration: none;
color: rgba(0,0,0,0.54);
padding: 14px 16px 12px 16px;
}
#bottom #stools{
border-left: 1px solid rgba(0,0,0,.12);
padding: 14px 16px 12px 24px;
white-space:nowrap;
}
#bottom #all{
color: #4285f4;
border-bottom: 2px solid #4285f4;
}
what I'd do is just to wrap the #bottom div inside a parent div with a fixed height and the overflow property set to hidden. Then you just have to give the #bottom div a padding-bottom with the same height as the scrollbar has (like 10px more or less). And thats all :), works great. Leave here the code:
// HTML Part
<div class="container">
<div id="bottom">
All
Images
Videos
News
Maps
<a id="books" href="#">Books</a>
<a id="flights" href="#">Flights</a>
<a id="personal" href="#">Personal</a>
<a id="stools" href="#">Search tools</a>
<a id="moar" href="#">More</a>
Settings
Tools
</div>
</div>
// CSS Part
body {
padding: 0;
margin: 0;
font-family: arial,sans-serif;
font-size: 13px;
}
.container {
height: 43px;
width: 100%;
overflow: hidden;
}
#bottom {
grid-area: 2/1/3/3;
display: flex;
overflow-x: scroll;
padding-bottom: 10px;
}
#bottom a {
font-size: 12px;
text-transform: uppercase;
text-decoration: none;
color: #0000008a;
padding: 14px 16px 12px 16px;
white-space: nowrap;
}
#bottom a#all {
color: #4285f4;
border-bottom: 2px solid #4285f4;
}

Display an image with a div which can wrap the link

I am working on a simple html/css web page.
What I am trying to do is having an image and a div. Both will be inline display and in div I want to put a link. But when I put a long link title it is not what I expect it to be.
My code is this-
code
<div class="heading"> featured posts
</div>
<div class="img_src">
<img style="height:120px;" src="/uploads/1.jpg"></img>
</div>
<div class="link_src">
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
</div>
CSS-
.img_src{
display: inline-block;
margin-top: 3px;
margin-left:-2%;
}
.link_src{
display: inline-block;
background-color: white;
height: 120px;
line-height: 120px;
width: 61%;
margin-top: 3px;
text-transform: uppercase;
}
.inside_link{
margin-left: 2%;
margin-right: 2%;
font-size: 15px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
I searched on google and StackOverflow but I did not get anything useful.
I want it to look like this(DIV wraps full)-
Any suggestion?
You csn use diplay:table-cell instead of inline-block but also I made edit in html by adding div.post that contain the image and title, and remove the inline-style that gave height to the image
<div class="post">
<div class="img_src">
<img src="http://i.dailymail.co.uk/i/pix/2016/03/22/13/32738A6E00000578-3504412-image-a-6_1458654517341.jpg">
</div>
<div class="link_src">
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
</div>
and in the css I give width:20%; to .img_src and width:80%; to .link_src (you can change the widths as you like) and remove height and line height from them and the diplay:table-cell will handle those height
.post{
font-size:0;
display:table;
width:100%;
}
.img_src{
display: table-cell;
vertical-align:top;
width:20%;
}
.img_src img{
width:100%;
}
.link_src{
display: table-cell;
background-color: white;
margin-top: 3px;
text-transform: uppercase;
vertical-align:middle;
width:80%;
}
.inside_link{
margin-left: 2%;
margin-right: 2%;
font-size: 15px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
https://jsfiddle.net/IA7medd/gg7ygdLs/17/
You can achieve that by changing the inline-block display to table-cell and then apply the vertical-align:middle; property on the text container.
That way, the text will be perfectly vertically centered if there are one, two, three lines of content.
.parent{
display: table;
border: 5px solid #ccc;
width: 100%;
}
.img_src{
display: table-cell;
}
.link_src{
display: table-cell;
vertical-align: middle;
background-color: white;
width: 61%;
text-transform: uppercase;
}
See this fiddle
Ok you are using the wrong approach. Line height is causing you the problem. Your html should look like this
<img class="img_src" style="height:120px;" src="/uploads/1.jpg">
<div class="link_src">
<div class="inner_link_src">
<div class="inner_margin">
Link will go here but if there is a long title then it may create some problems..
</div>
</div>
</div>
and your css like this
.img_src{
float:left
}
.link_src{
float:left;
position:relative;
width: 61%;
text-transform: uppercase;
background-color: white;
vertical-align: top;
display:table;
height:120px;
}
.inner_link_src{
display:table-cell;
width:100%;
height:100%;
vertical-align:middle;
margin-left:10px;
}
.inner_margin{
margin-left:10px;
}
see the jsfiddle it is working great
https://jsfiddle.net/gg7ygdLs/27/
You just change your CSS and HTML by following and then you get the desired result.
CSS:
.img_src{
display: inline-block;
margin-top: 3px;
margin-left:-2%;
}
.link_src{
display: inline-block;
background-color: white;
height: 120px;
width: 100%;
margin: 10px 0 10px 3px;
-webkit-box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
-moz-box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
}
.inside_link{
margin: 2%;
display: inline-block;
position:absolute;
padding: 8px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
HTML:
<div class="heading"> featured posts
</div>
<div class="link_src">
<img style="height:120px;" src="http://smashinghub.com/wp-content/uploads/2011/11/Text-Shadow-Box.jpg" />
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
Demo
You can simplify your code a lot by using Flexbox.
You can use it for your header as well, to center the title.
.your-header {
display: flex;
align-items: center;
justify-content: center;
}
Then the image container. Use it's more semantic and it's a block element, perfect to wrap an image with a caption or a link in your case:
<figure class="your-figure">
<img class="your-image" src="http://pipsum.com/200x150.jpg"></img>
<a class="your-link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</figure>
and the CSS
.your-figure {
display: flex;
align-items: center;
padding: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
.your-image {
margin-right: 10px;
}
Have a look here for the complete code ;)
Follow this if you don't know Flexbox, might seems daunting at first, but when it clicks in your head it will change your life :) Complete guide to Flexbox

btns (as anchor tags) not at same height but is side by side

Ok, I have two buttons that need to sit side by side. I got that. But the right 'button' is sitting higher than the left one. Why? I believe that it is because of my right 'button' has two lines of text with it. My proponent will not budge on this button having two lines of text. Does anyone know how to do this better?
I put my code in jsfiddle: http://jsfiddle.net/energeticpixels/k7awcfts/
Here is my code:
<div id='tonyzBTNs'>
<a id='regCourse' class='btn' href='https://cloudlms.slhc.serco-na.com' target='_blank'>Register for Course</a>
<a id='regTest' class='btn' href='https://www.atrrs.army.mil/atrrscc/courseInfo.aspx?fy=2016&sch=910&crs=4E-F33%2f645-F17+(DL)&crstitle=ARMY+ELECTRICAL+EXPLOSIVE+SAFETY+(CERT)&phase=' target='_blank'>Register for Exam<span style="font-size: 10px;"><br />(after completing the course)</span></a>
</div>
And the css:
#tonyzBTNs {
margin-top: 20px;
margin-bottom: 20px;
}
#tonyzBTNs .btn {
text-align: center;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
text-decoration: none;
}
#tonyzBTNs #regCourse {
background-color: #9EB95C;
border: 2px solid #708542;
border-radius: 10px;
padding: 10px;
color: black;
}
#tonyzBTNs #regTest {
background-color: #C54F4D;
border: 2px solid #6A4346;
border-radius: 10px;
padding: 1px 10px 1px 10px;
color: white;
display: inline-block;
}
Depending on how the rest of the site is layed out, Using float: left; in your #tonyzBTNs #regCourse will probably solve your issue.
Updated Fiddle
#tonyzBTNs .btn {
...
vertical-align: top;
display: inline-block;
}
Demo

How can my button's position be centered without any kind of "margin cheat"?

How can I place my button in the center without any kind of "margin cheat" (for example setting margin-left: 525px;)?
HTML
<div id="banner">
<div id="bannerContainer">
<h1>H1 tag</h1>
Products
</div>
</div>
CSS
.bannerButton {
border: 2px solid #fff;
color: #fff;
font-weight: 300;
font-family: 'Raleway';
font-size: 20px;
display: inline-block;
background-color: rgb(63, 127, 191);
padding: 18px 60px 18px 50px;
margin-bottom: 50px;
margin-top: 50px;
position: relative;
margin-left: 525px;
}
.bannerButton:hover {
text-decoration: none;
background: #eaf;
color: #fff;
}
I've tried making it sit in the center but it didn't work out so well without me setting margin-left; 525px;, which in my case, centers the button under the text, please help me remove this "margin cheat" and do it in the right way.
The a act like text it means when you give text-align:center; to its parent, it will be placed in center of its parent.
You don't need to give margin to the a element. You can use text-align:center;.
#bannerContainer
{
text-align:center;
}
.bannerButton {
border: 2px solid #fff;
color: #fff;
font-weight: 300;
font-family: 'Raleway';
font-size: 20px;
display: inline-block;
background-color: rgb(63, 127, 191);
padding: 18px 60px 18px 50px;
margin-bottom: 50px;
margin-top: 50px;
position: relative;
}
.bannerButton:hover {
text-decoration: none;
background: #eaf;
color: #fff;
}
<div id="banner">
<div id="bannerContainer">
<h1>H1 tag</h1>
Products
</div>
</div>
If you set the position of the button to absolute, give it a set width, and add this it should center:
left: 50%; right: 50%;
Have you try this:
<center>Products</center>
I am not sure whether it is helpful to you..