Cosmic CSS Unveilment

Currently working on building a responsive HTML page and facing a slight challenge.

I have two divs that I want to display side by side.

If the width drops below X, the second div should be hidden.

This part is functioning as expected.

However, when inserting content longer than the width, word-wrap kicks in creating some white space at the top of the first div.

Below is the code snippet:

To remove the white space at the top (while keeping the divs inline), here is a modified version with the required adjustments:

$(document).ready(function() {
    $('#menu').click(function(e) {  
if( $('#menu').text() == "SHOW INFO" )
$('#menu').text('HIDE INFO');
else
$('#menu').text('SHOW INFO');
    });
Updated CSS Code:
 
/* Add your updated styles here */

@media only screen and (min-width: 100px) and (max-width: 700px) 
{
.content
{
background-color:black;
width:100%;
height:100%;
}

.info { display:none; }

.menu
{
display:block;
height:40px;
line-height: 40px;
font-family: Verdana;
font-weight: normal;
font-size: 18px;
color: #D00355;
position: relative;
text-align: center;
-webkit-user-select: none;     
-moz-user-select: none; 
-ms-user-select: none; 
-o-user-select: none;
user-select: none;
-webkit-transition: background 0.5s linear;
        -moz-transition: background 0.5s linear;
        -ms-transition: background 0.5s linear;
        -o-transition: background 0.5s linear;
        transition: background 0.5s linear;
}

.menu:hover
{
background-color:#D00355;
-webkit-transition: background 0.5s linear;
        -moz-transition: background 0.5s linear;
        -ms-transition: background 0.5s linear;
        -o-transition: background 0.5s linear;
        transition: background 0.5s linear;
line-height: 40px;
font-family: Verdana;
font-weight: normal;
font-size: 18px;
color: white;
position: relative;
text-align: center;
cursor:pointer;
}
<html>
<head>
<title>Responsive Test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>
<div class="wrapper">
<div class="content">
1
</div>
<div class="info">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</div>

<div class="menu" id="menu" name="menu">SHOW INFO</div>
</div>
</body>
</html>

Answer №1

Use this code to eliminate extra top spacing for the first div:

.wrapper > div {
  vertical-align: top;
}

If you'd like to learn more about comparing inline-block and float styles, and why adding vertical-align: top is important, check out this informative article:

Snippet

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.wrapper {
  background-color: white;
  width: 100%;
  height: 100%;
}

.content {
  color: yellow;
  background-color: black;
  width: 70%;
  height: 100%;
  display: inline-block;
}

.info {
  background-color: white;
  width: 29%;
  height: 100%;
  display: inline-block;
}

.infobox {
  text-align: center;
}

.wrapper > div {
  vertical-align: top;
}
<div class="wrapper">
  <div class="content">
    1
  </div>
  <div class="info">
    <div class="infobox">asdadasdadas
      <br>asdadsa
      <br>asdadsa
      <br>asdadsa
    </div>
  </div>

  <div class="menu" id="menu" name="menu">SHOW INFO</div>
</div>

Answer №2

Make sure to include a float rule in your CSS:

.content, .info {
    float:left;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

top-sticky and logo visibility

Struggling with an issue related to displaying a logo in a sticky header. The menu works, but need the logo to shrink when header is sticky. https://i.sstatic.net/jDNsb.png This is what I need: https://i.sstatic.net/szzRC.png My current code snippet: ...

Turn off hover functionality for mobile and tablet devices

Is there a way to prevent hover effects on mobile and tablet devices for an SVG file used in the img tag? scss file: .menu-link:hover { img { filter: invert(40%) sepia(90%) saturate(2460%) hue-rotate(204deg) brightness(93%) contrast(93%); } .side ...

Vertical and floating alignment

Can you help me with this HTML/CSS challenge? User: Support: Emily Johnson Alex Roberts I am looking to have two input boxes aligned vertically on both the left and right ...

Issue with loading a stylesheet from a GitHub raw URL

How are you feeling today? I appreciate your willingness to assist, although I realize this may seem like a trivial question. I am struggling to comprehend why things are not functioning as expected. Within my local directory, I have the following tree s ...

What is the best way to insert a triangle shape to the bottom of a div with an opacity level set at 0.2

https://i.stack.imgur.com/sqZpM.png I've been trying to create something similar, but my triangle keeps overlapping with the background in the next section. I've already spent 3 hours on it. Any help would be greatly appreciated. Check out my c ...

The li elements in a horizontal menu all have equal spacing between them, filling the width of the ul

I designed a horizontal menu navigation system using HTML elements ul for the main menu container and li for menu list items. The layout is structured with display table for ul and table-cell for li. However, I encountered an issue where there are inconsis ...

Can a CSS <div> element have margins applied to it?

Can a margin be defined for a text area? My WYSIWYG editor wraps my text within <div> tags instead of using line breaks <br /> So I was thinking of adding a margin to the <div> tag? Is this possible in CSS? If so, how can it be done? ...

Initial two slides of the Bootstrap carousel appear clunky in full screen mode

After researching on various platforms, including Stack Overflow, I came across a similar question that I am facing now. Unfortunately, none of the solutions provided have worked for me so far. I apologize if this is repetitive, but I can't seem to fi ...

How come the background and border of the link are shown behind the image, while the link itself is displayed in front?

There seems to be an issue with the "Give Now" and "How You Help" links on the next page. The background color applied to them is showing up behind an image, making the link appear in front of it. Any suggestions on how to resolve this? ...

Combine the content from multiple text areas and submit it to another text area

****UPDATE**** Thanks to @JasonB, I was able to resolve the previous issue mentioned. Now, I have three additional textareas on the same form that should only appear when their respective checkboxes are clicked. How can I integrate this into my current sc ...

Arranging text in CSS for responsive design

One issue I encountered was setting a division on the webpage. When I try to minimize the browser, the division does not adjust properly to fit the screen: width:1300px; margin:0 auto; height:40px; ...

Creating a div that expands to fill up the remaining height within a flex-child

I'm facing a challenge with a flex container that contains flex children. Within each flex child, there are two stacked divs, the first of which has an unknown height. My goal is to make the second div fill the remaining height available. I've be ...

Enhance Your Website with Bootstrap 3.0 Affix

Looking to attach a right hand column to the top of the window as you scroll using Bootstrap 3.0 and 'affix' feature. Here is the HTML for the element: <div class="col-lg-4 right-hand-bar" data-spy="affix" data-offset-top="477"> This is ...

Differences in sub column heights within Bootstrap grid system

I am facing an issue with maintaining consistent heights for all my columns. I typically use Bootstrap to adjust their sizes, but the problem arises when using sub divs. Click here to view a DEMO showcasing the issue The first "table" is borrowed from an ...

Determining the XY position of the wheel data

In my attempt to develop a lucky draw wheel using reactjs, I needed to position all the input data at specific XY coordinates. Below is an example of the expected output XY positions that I require. var renderData = ["1", "2", "3", "4", "5", "6", "7", " ...

Modifying the .textcontent attribute to showcase an image using JavaScript

I am working on a website and I want to change editButton.textContent = 'Edit'; so that it displays an image instead of text. var editButton = document.createElement('button'); editButton.textContent = 'Edit'; After exploring ...

Avoid having two DIVS appear simultaneously in IE for half a second upon page load

I'm encountering an issue with my HTML and jQuery code. Here is what I have: <div id="block1"> some text </div> <div id="block2"> some more text </div> Along with the following piece of jQuery code: jQuery(document).ready(fu ...

flashing issue with bootstrap selectpicker

Can you rearrange the jQuery code and incorporate popper.js into bootstrap 4? $('.selectpicker').selectpicker(); <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs ...

Text input field with uneditable text displayed at the end

Click here to view the input field I am looking to create an input field that always displays a "%" at the end of the input. Here is what my react component looks like currently: <StyledBaseInput type="text" ...

What is the best way to ensure the navigation bar stays at the top of the window once it has reached

I have a sample js fiddle provided here. The navigation bar is positioned right below the "Hello World" section, and the content follows beneath the nav bar. Is there a way to make the navigation bar stick to the top of the window once it reaches that poin ...