Designing a webpage with HTML and CSS

During an interview, I was presented with the diagram below and the interviewer pointed out that I was missing clear:both in my code.

https://i.sstatic.net/CNevk.png

I attempted the following code but did not achieve the desired outcome

.name3 {
  border: 1px solid black;
  height: 50px;
  width: 90px;
}

.name {
  border: 1px solid black;
  height: 10px;
  width: 90px;
}

.name1 {
  border: 1px solid black;
  height: 40px;
  width: 30px;
}

#name2 {
  border: 1px solid black;
  height: 20px;
  width: 30px;
  float: left;
}
<body>
  <div class="name3">
    <div class="name"></div>
    <div class="name1"></div>
    <div id="name2"></div>
    <div id="name2"></div>
    <div id="name2"></div>
    <div id="name2"></div>
  </div>

</body>

Answer №1

Give this a shot

.title3 {
    border: 1px solid black;
    height: 55px;
    width: 100px;
    float: left;
}
.title {
    border: 1px solid black;
    height: 10px;
    width: 99px;
    float: left;
}
.title1 {
    border: 1px solid black;
    height: 42px;
    width: 34px;
    float: left;
}
#title2 {
    border: 1px solid black;
    height: 20px;
    width: 30px;
    float: left;
}
<body>
  <div class="title3">
    <div class="title"></div>
    <div class="title1"></div>
    <div id="title2"></div>
    <div id="title2"></div>
    <div id="title2"></div>
    <div id="title2"></div>
  </div>

</body>

Answer №2

I attempted to replicate this using Flexbox.

If you're interested in learning more, check out: https://www.w3schools.com/css/css3_flexbox.asp

.top,.side,.square {
  padding: 5px;
  box-sizing: border-box;
  border: 1px solid black;
}

.container {
  display: flex;
  flex-direction: column;
  width: 200px;
}

.container .main {
  display: flex;
  flex-direction: row;
  max-width: 200px;
}

.container .main .content {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.container .main .content .square {
  width: 50%;
}
<div class="container">
  <div class="top">.top</div>
  <div class="main">
    <div class="side">.side</div>
    <div class="content">
      <div class="square">.square</div>
      <div class="square">.square</div>
      <div class="square">.square</div>
      <div class="square">.square</div>
    </div>
  </div>
</div>

Answer №3

Hello SIMIN, I have carefully reviewed your inquiry and prepared a solution for you. Simply copy and paste the provided code snippet into your preferred text editor. Please keep in mind that I executed this code in the Opera browser, so there might be slight variations in output if you are using a different browser. Best of luck with your project!

<html>
    <head>
        <style>
            .name3{
                border: 1px solid black;
                height: 53px;
                width: 93px;
                }

            .name{
                  border: 0.5px solid black;
                  height: 10px;
                  width: 92px;
                  float: left;
                }

            .name1{
                  border: 0.5px solid black;
                  height: 41px;
                  width: 30px;
                  float: left;
                  clear: left;
                }

            #name2one{
                height: 20px;
                width: 30px;
                border: 0.5px solid black;
                float: left;
                clear: none;
            }


        </style>
    </head>
    <body>
        <div class="name3">
            <div class="name"></div>
            <div class="name1"></div>
            <div id="name2one"></div>
            <div id="name2one"></div>
            <div id="name2one"></div>
            <div id="name2one"></div>
        </div>
    </body>
</html>

Answer №4

Have you considered using percentages for the width?

<div class="wrapper">
  <div class="header></div>
  <div class="sidebar"></div>
  <div class="article"></div>
  <div class="article"></div>
  <div class="article"></div>
  <div class="article"></div>
</div>


.wrapper, .header, .sidebar, .article{
   border: 1px solid black;
   float: left;
}
.wrapper {
   height: 100px;
   width: 100px;
}
.header{
  width: 100%;  
  height: 20px;
}
.sidebar {
    height: 80px;
    width: 33.33%;
}
.article {
    height: 40px;
    width: 33.33%;
}

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

Apply a red border to any form inputs that contain incorrect information when the submit

How can I add red borders to my form inputs only when they are invalid after submission, without displaying the red borders from the start? Currently, I am using the input:invalid selectors in CSS, but this causes the red borders to appear immediately. I ...

The bottom margin fails to function as expected

I've been trying to position a loading image at the bottom right of the page, but everything seems to be working except for the margin-bottom. <div id="preload"> <div align="right" style="margin-bottom:40px; margin-right:50px;"> ...

Unable to conceal tab content upon clicking the identical tab

I recently implemented a tab system with panels that seems to be working well when switching between tabs. However, I'm facing an issue where clicking on the same tab does not hide the corresponding panel and reset the aria attributes as intended. I&a ...

Several radio buttons and their corresponding labels are shown on a single line inside a nested div container

Upon stumbling across this post, I realized it perfectly aligns with my current goal: Radio Button and Label to display in same line. However, the challenge persists... The layout I currently have (first 3 columns) differs from what I aspire to achieve (l ...

Understanding how much of a video stream has been viewed by a user using PHP

I am currently involved in a project that involves displaying video advertisements to users, and after 60 seconds, users are presented with a link. My supervisor wants to ensure that users watch the entire 60 seconds of the video. I am now wondering if th ...

Emptying the AnyChart (Javascript) container prior to generating new charts

I have been utilizing the anychart JavaScript library to generate a pie-chart from my data, which is dynamically pulled whenever a user modifies a dropdown selection. Below is the code snippet I am employing for this purpose: var stage = anychart.graph ...

Expanding the Width of Bootstrap 4 Dropdown Button

Currently, I am utilizing Bootstrap 4's dropdown feature. Is there a way to modify the code below so that the dropdown menu that appears upon clicking the button matches the same width as the button itself? It's important to note that the button ...

Accessing an object from a webpage using Selenium: A step-by-step guide

Today marks my debut using Selenium IDE, and I must admit that my knowledge of web development is limited. My team is currently working on a website, and as part of my task, I need to write tests for it. The website features several charts showcasing data ...

Is there a way to modify the color of ASCII art letters within HTML's <pre> tags?

For this illustration, I aim to transform the letter "y" into a shade of blue. ,ggggggggggggggg dP""""""88""""""" Yb,_ 88 `"" 88 88 88 gg gg 88 I8 8I gg, 88 ...

Learn the process of activating or deactivating tabs on an AngularJS frontend

My webpage has three tabs that I'm struggling to enable and disable correctly. Whenever I click on a tab, it routes me to the desired page but the tab remains active even though it should deactivate. Strangely, removing the code 'window.location. ...

What is the best API for incorporating interactive maps into my Android application?

I am looking to create an Android app (using Java) with interactive maps similar to ammaps, which can be integrated with HTML5/jQuery Mobile. Check out for reference. The app will display a world map where different areas are highlighted or colored based ...

Error: Papa is not defined. The file was loaded from the CDN in the header section

I have integrated the cdn hosted lib for PapaParse in my HTML header. However, when I execute my JavaScript file and it reaches the function where I call Papa.unparse(data); It throws an error stating that Papa is undefined. This has left me puzzled as I h ...

Multiple Ajax(Jquery method) Submissions with just one click and issue with Image not being sent to the server

Having trouble submitting form data to the server after client-side validation using jQuery. I've been working on this all day and could really use some help. I created a jQuery slider for my login form, where it slides to the next input field after v ...

Activate the WebDAV feature within the .htaccess file

Can WebDAV be activated through an .htaccess file? I'm experiencing issues with Plesk not recognizing my modified config files that have WebDAV enabled. Is it feasible to enable WebDAV without using an .htaccess file? ...

The background-repeat-x property is not being retrieved by the Selenium WebDriver getCssValue() function

My goal is to check if a background image exists and if the `repeat-x` property is set. I can successfully retrieve the background image using the following code: driver.findElement(By.xpath("//body").getCssValue("background-image"); This code returns a ...

Div flexes and compresses smaller than its content dimensions

Here's a link to the fiddle: check it out Take a look at a normal card below: https://i.sstatic.net/7Yqqv.png But when the browser window is resized, it shrinks to this: https://i.sstatic.net/1aexK.png This is the HTML structure: #product-list ...

How come the <script> element is showing up in the <body> tag even though I initially declared it outside the <body>

I'm currently working on web projects through the Odin Project and I want to follow the software engineering process by taking small steps and testing them. Specifically, I'm interested in seeing the output of document.querySelector("body"). I kn ...

Picture featuring a right-angled triangle on the right side

I have been experimenting with creating a complex image effect using CSS only, without any JavaScript. Despite several attempts, I haven't been able to achieve the desired outcome yet. https://i.sstatic.net/sUEaJ.jpg CSS .container{ width: 500p ...

Unfiltered items remain unsorted when the checkbox is left unchecked

My goal is to create a filtering system for an array of four categories using separate checkboxes. Each click on a checkbox should filter the array by a specific category. I have implemented the code below to achieve this, but I am facing some issues. Curr ...

Experiencing difficulties with JSoup on Android for HTML parsing

I recently started working on a fun little project to scrape data (specifically XKCD comics) from the internet and display it on my phone. This is my first time delving into Android development, and since I'm not too familiar with Java, I'm keepi ...